summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cmake.conf4
-rw-r--r--.prev_CMakeLists.txt20
-rw-r--r--.qmake.conf6
-rw-r--r--CMakeLists.txt10
-rw-r--r--LICENSE.GPL3-EXCEPT704
-rw-r--r--LICENSES/BSD-3-Clause.txt9
-rw-r--r--LICENSES/GFDL-1.3-no-invariants-only.txt451
-rw-r--r--LICENSES/GPL-2.0-only.txt (renamed from LICENSE.GPL2)0
-rw-r--r--LICENSES/GPL-3.0-only.txt (renamed from LICENSE.GPL3)0
-rw-r--r--LICENSES/LGPL-3.0-only.txt (renamed from LICENSE.LGPL3)0
-rw-r--r--LICENSES/LicenseRef-Qt-Commercial.txt8
-rw-r--r--LICENSES/Qt-GPL-exception-1.0.txt22
-rw-r--r--README.md2
-rw-r--r--coin/axivion/ci_config_linux.json60
-rw-r--r--coin/module_config.yaml1
-rw-r--r--conanfile.py37
-rw-r--r--dependencies.yaml4
-rw-r--r--dist/changes-5.15.228
-rw-r--r--examples/CMakeLists.txt5
-rw-r--r--examples/websockets/CMakeLists.txt17
-rw-r--r--examples/websockets/doc/echoclient.qdoc73
-rw-r--r--examples/websockets/doc/echoserver.qdoc72
-rw-r--r--examples/websockets/doc/examples.qdoc52
-rw-r--r--examples/websockets/doc/images/echoclient-console-example.webpbin0 -> 40492 bytes
-rw-r--r--examples/websockets/doc/images/qmlwebsocketclient-example.webpbin0 -> 31782 bytes
-rw-r--r--examples/websockets/doc/images/qmlwebsocketserver-example.webpbin0 -> 32102 bytes
-rw-r--r--examples/websockets/doc/images/simplechat-html-example.webpbin0 -> 31714 bytes
-rw-r--r--examples/websockets/doc/images/sslechoclient-console-example.webpbin0 -> 25454 bytes
-rw-r--r--examples/websockets/doc/images/sslechoclient-html-example.webpbin0 -> 27858 bytes
-rw-r--r--examples/websockets/doc/qmlwebsocketclient.qdoc77
-rw-r--r--examples/websockets/doc/qmlwebsocketserver.qdoc64
-rw-r--r--examples/websockets/doc/simplechat.qdoc74
-rw-r--r--examples/websockets/doc/sslechoclient.qdoc73
-rw-r--r--examples/websockets/doc/sslechoserver.qdoc78
-rw-r--r--examples/websockets/echoclient/CMakeLists.txt22
-rw-r--r--examples/websockets/echoclient/echoclient.cpp51
-rw-r--r--examples/websockets/echoclient/echoclient.h51
-rw-r--r--examples/websockets/echoclient/main.cpp79
-rw-r--r--examples/websockets/echoserver/CMakeLists.txt21
-rw-r--r--examples/websockets/echoserver/echoserver.cpp51
-rw-r--r--examples/websockets/echoserver/echoserver.h51
-rw-r--r--examples/websockets/echoserver/main.cpp51
-rw-r--r--examples/websockets/qmlwebsocketclient/CMakeLists.txt25
-rw-r--r--examples/websockets/qmlwebsocketclient/main.cpp51
-rw-r--r--examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml61
-rw-r--r--examples/websockets/qmlwebsocketserver/CMakeLists.txt25
-rw-r--r--examples/websockets/qmlwebsocketserver/main.cpp51
-rw-r--r--examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml65
-rw-r--r--examples/websockets/simplechat/CMakeLists.txt27
-rw-r--r--examples/websockets/simplechat/chatserver.cpp53
-rw-r--r--examples/websockets/simplechat/chatserver.h51
-rw-r--r--examples/websockets/simplechat/main.cpp51
-rw-r--r--examples/websockets/simplechat/simplechat.pro2
-rw-r--r--examples/websockets/sslechoclient/CMakeLists.txt26
-rw-r--r--examples/websockets/sslechoclient/main.cpp82
-rw-r--r--examples/websockets/sslechoclient/sslechoclient.cpp71
-rw-r--r--examples/websockets/sslechoclient/sslechoclient.h51
-rw-r--r--examples/websockets/sslechoclient/sslechoclient.pro5
-rw-r--r--examples/websockets/sslechoserver/CMakeLists.txt22
-rw-r--r--examples/websockets/sslechoserver/main.cpp51
-rw-r--r--examples/websockets/sslechoserver/sslechoserver.cpp51
-rw-r--r--examples/websockets/sslechoserver/sslechoserver.h51
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/imports/.prev_CMakeLists.txt4
-rw-r--r--src/imports/CMakeLists.txt4
-rw-r--r--src/imports/imports.pro4
-rw-r--r--src/imports/qmlwebsockets/.prev_CMakeLists.txt25
-rw-r--r--src/imports/qmlwebsockets/CMakeLists.txt27
-rw-r--r--src/imports/qmlwebsockets/dependencies.json2
-rw-r--r--src/imports/qmlwebsockets/qmldir4
-rw-r--r--src/imports/qmlwebsockets/qmlwebsockets.pro17
-rw-r--r--src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp43
-rw-r--r--src/imports/qmlwebsockets/qmlwebsockets_plugin.h40
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.cpp106
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.h52
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocketserver.cpp81
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocketserver.h49
-rw-r--r--src/imports/qmlwebsockets_compat/plugins.qmltypes97
-rw-r--r--src/imports/qmlwebsockets_compat/qmldir4
-rw-r--r--src/imports/qmlwebsockets_compat/qmlwebsockets_compat.pro7
-rw-r--r--src/src.pro5
-rw-r--r--src/websockets/CMakeLists.txt21
-rw-r--r--src/websockets/doc/qtwebsockets.qdocconf15
-rw-r--r--src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp28
-rw-r--r--src/websockets/doc/src/external-resources.qdoc54
-rw-r--r--src/websockets/doc/src/index.qdoc96
-rw-r--r--src/websockets/doc/src/overview.qdoc28
-rw-r--r--src/websockets/doc/src/qt6-changes.qdoc32
-rw-r--r--src/websockets/doc/src/qtwebsockets-module.qdoc30
-rw-r--r--src/websockets/qdefaultmaskgenerator_p.cpp44
-rw-r--r--src/websockets/qdefaultmaskgenerator_p.h45
-rw-r--r--src/websockets/qmaskgenerator.cpp40
-rw-r--r--src/websockets/qmaskgenerator.h40
-rw-r--r--src/websockets/qsslserver.cpp151
-rw-r--r--src/websockets/qsslserver_p.h98
-rw-r--r--src/websockets/qwebsocket.cpp172
-rw-r--r--src/websockets/qwebsocket.h53
-rw-r--r--src/websockets/qwebsocket_p.cpp633
-rw-r--r--src/websockets/qwebsocket_p.h91
-rw-r--r--src/websockets/qwebsocket_wasm_p.cpp364
-rw-r--r--src/websockets/qwebsocketcorsauthenticator.cpp51
-rw-r--r--src/websockets/qwebsocketcorsauthenticator.h52
-rw-r--r--src/websockets/qwebsocketcorsauthenticator_p.h42
-rw-r--r--src/websockets/qwebsocketdataprocessor.cpp62
-rw-r--r--src/websockets/qwebsocketdataprocessor_p.h40
-rw-r--r--src/websockets/qwebsocketframe.cpp49
-rw-r--r--src/websockets/qwebsocketframe_p.h40
-rw-r--r--src/websockets/qwebsockethandshakeoptions.cpp108
-rw-r--r--src/websockets/qwebsockethandshakeoptions.h49
-rw-r--r--src/websockets/qwebsockethandshakeoptions_p.h35
-rw-r--r--src/websockets/qwebsockethandshakerequest.cpp203
-rw-r--r--src/websockets/qwebsockethandshakerequest_p.h48
-rw-r--r--src/websockets/qwebsockethandshakeresponse.cpp62
-rw-r--r--src/websockets/qwebsockethandshakeresponse_p.h41
-rw-r--r--src/websockets/qwebsocketprotocol.cpp44
-rw-r--r--src/websockets/qwebsocketprotocol.h44
-rw-r--r--src/websockets/qwebsocketprotocol_p.h47
-rw-r--r--src/websockets/qwebsockets_global.h54
-rw-r--r--src/websockets/qwebsocketserver.cpp161
-rw-r--r--src/websockets/qwebsocketserver.h59
-rw-r--r--src/websockets/qwebsocketserver_p.cpp143
-rw-r--r--src/websockets/qwebsocketserver_p.h48
-rw-r--r--src/websockets/websockets.pro52
-rw-r--r--tests/.prev_CMakeLists.txt7
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/auto/.prev_CMakeLists.txt7
-rw-r--r--tests/auto/CMakeLists.txt5
-rw-r--r--tests/auto/auto.pro7
-rw-r--r--tests/auto/cmake/CMakeLists.txt45
-rw-r--r--tests/auto/cmake/cmake.pro7
-rw-r--r--tests/auto/qml/.prev_CMakeLists.txt6
-rw-r--r--tests/auto/qml/CMakeLists.txt4
-rw-r--r--tests/auto/qml/qml.pro3
-rw-r--r--tests/auto/qml/qmlwebsockets/CMakeLists.txt12
-rw-r--r--tests/auto/qml/qmlwebsockets/qmlwebsockets.pro9
-rw-r--r--tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp29
-rw-r--r--tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.qml36
-rw-r--r--tests/auto/qml/qmlwebsockets_compat/qmlwebsockets_compat.pro9
-rw-r--r--tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.cpp30
-rw-r--r--tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.qml47
-rw-r--r--tests/auto/websockets/CMakeLists.txt3
-rw-r--r--tests/auto/websockets/dataprocessor/CMakeLists.txt7
-rw-r--r--tests/auto/websockets/dataprocessor/dataprocessor.pro13
-rw-r--r--tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp329
-rw-r--r--tests/auto/websockets/handshakerequest/BLACKLIST5
-rw-r--r--tests/auto/websockets/handshakerequest/CMakeLists.txt8
-rw-r--r--tests/auto/websockets/handshakerequest/handshakerequest.pro13
-rw-r--r--tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp185
-rw-r--r--tests/auto/websockets/handshakeresponse/CMakeLists.txt8
-rw-r--r--tests/auto/websockets/handshakeresponse/handshakeresponse.pro13
-rw-r--r--tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp41
-rw-r--r--tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt7
-rw-r--r--tests/auto/websockets/qdefaultmaskgenerator/qdefaultmaskgenerator.pro13
-rw-r--r--tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp29
-rw-r--r--tests/auto/websockets/qwebsocket/CMakeLists.txt20
-rw-r--r--tests/auto/websockets/qwebsocket/qwebsocket.pro11
-rw-r--r--tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp698
-rw-r--r--tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt7
-rw-r--r--tests/auto/websockets/qwebsocketcorsauthenticator/qwebsocketcorsauthenticator.pro12
-rw-r--r--tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp29
-rw-r--r--tests/auto/websockets/qwebsocketserver/BLACKLIST5
-rw-r--r--tests/auto/websockets/qwebsocketserver/CMakeLists.txt21
-rw-r--r--tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro15
-rw-r--r--tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp247
-rw-r--r--tests/auto/websockets/shared/qwebsocketshared.qrc6
-rw-r--r--tests/auto/websockets/websocketframe/CMakeLists.txt7
-rw-r--r--tests/auto/websockets/websocketframe/tst_websocketframe.cpp35
-rw-r--r--tests/auto/websockets/websocketframe/websocketframe.pro13
-rw-r--r--tests/auto/websockets/websocketprotocol/CMakeLists.txt7
-rw-r--r--tests/auto/websockets/websocketprotocol/tst_websocketprotocol.cpp29
-rw-r--r--tests/auto/websockets/websocketprotocol/websocketprotocol.pro13
-rw-r--r--tests/auto/websockets/websockets.pro16
-rw-r--r--tests/doc/README.qdocinc (renamed from tests/doc/README)0
-rw-r--r--tests/manual/compliance/tst_compliance.cpp29
-rw-r--r--tests/manual/websockets/tst_websockets.cpp29
-rw-r--r--tests/tests.pro5
176 files changed, 3659 insertions, 5878 deletions
diff --git a/.cmake.conf b/.cmake.conf
index 9305480..2792a7d 100644
--- a/.cmake.conf
+++ b/.cmake.conf
@@ -1 +1,3 @@
-set(QT_REPO_MODULE_VERSION "6.0.0")
+set(QT_REPO_MODULE_VERSION "6.6.0")
+set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1")
+set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1")
diff --git a/.prev_CMakeLists.txt b/.prev_CMakeLists.txt
deleted file mode 100644
index d1a8235..0000000
--- a/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# Generated from qtwebsockets.pro.
-
-cmake_minimum_required(VERSION 3.15.0)
-
-include(.cmake.conf)
-project(QtWebSockets
- VERSION "${QT_REPO_MODULE_VERSION}"
- DESCRIPTION "Qt WebSockets Libraries"
- HOMEPAGE_URL "https://qt.io/"
- LANGUAGES CXX C
-)
-
-find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core SET_ME_TO_SOMETHING_USEFUL)
-find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS SET_ME_TO_SOMETHING_USEFUL)
-
-if(NOT TARGET Qt::Network)
- message(NOTICE "Skipping the build as the condition \"TARGET Qt::Network\" is not met.")
- return()
-endif()
-qt_build_repo()
diff --git a/.qmake.conf b/.qmake.conf
deleted file mode 100644
index 8b97f9b..0000000
--- a/.qmake.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-load(qt_build_config)
-
-CONFIG += warning_clean
-DEFINES += QT_NO_FOREACH
-
-MODULE_VERSION = 6.0.0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e83d3e..a594cea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,9 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qtwebsockets.pro.
-cmake_minimum_required(VERSION 3.15.0)
+cmake_minimum_required(VERSION 3.16)
include(.cmake.conf)
project(QtWebSockets # special case
@@ -10,12 +13,15 @@ project(QtWebSockets # special case
LANGUAGES CXX C
)
+# Make sure we use the fixed BASE argument of qt_add_resource.
+set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE)
+
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core Network) # special case
find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Quick QuickTest) # special case
+qt_internal_project_setup()
if(NOT TARGET Qt::Network)
message(NOTICE "Skipping the build as the condition \"TARGET Qt::Network\" is not met.")
return()
endif()
qt_build_repo()
-
diff --git a/LICENSE.GPL3-EXCEPT b/LICENSE.GPL3-EXCEPT
deleted file mode 100644
index b1cb1be..0000000
--- a/LICENSE.GPL3-EXCEPT
+++ /dev/null
@@ -1,704 +0,0 @@
-This is the GNU General Public License version 3, annotated with The
-Qt Company GPL Exception 1.0:
-
--------------------------------------------------------------------------
-
-The Qt Company GPL Exception 1.0
-
-Exception 1:
-
-As a special exception you may create a larger work which contains the
-output of this application and distribute that work under terms of your
-choice, so long as the work is not otherwise derived from or based on
-this application and so long as the work does not in itself generate
-output that contains the output from this application in its original
-or modified form.
-
-Exception 2:
-
-As a special exception, you have permission to combine this application
-with Plugins licensed under the terms of your choice, to produce an
-executable, and to copy and distribute the resulting executable under
-the terms of your choice. However, the executable must be accompanied
-by a prominent notice offering all users of the executable the entire
-source code to this application, excluding the source code of the
-independent modules, but including any changes you have made to this
-application, under the terms of this license.
-
-
--------------------------------------------------------------------------
-
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- <program> Copyright (C) <year> <name of author>
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt
new file mode 100644
index 0000000..b91bbd8
--- /dev/null
+++ b/LICENSES/BSD-3-Clause.txt
@@ -0,0 +1,9 @@
+Copyright (c) <year> <owner>.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ 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.
+ 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.
+
+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.
diff --git a/LICENSES/GFDL-1.3-no-invariants-only.txt b/LICENSES/GFDL-1.3-no-invariants-only.txt
new file mode 100644
index 0000000..857214d
--- /dev/null
+++ b/LICENSES/GFDL-1.3-no-invariants-only.txt
@@ -0,0 +1,451 @@
+
+ GNU Free Documentation License
+ Version 1.3, 3 November 2008
+
+
+ Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
+ <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+0. PREAMBLE
+
+The purpose of this License is to make a manual, textbook, or other
+functional and useful document "free" in the sense of freedom: to
+assure everyone the effective freedom to copy and redistribute it,
+with or without modifying it, either commercially or noncommercially.
+Secondarily, this License preserves for the author and publisher a way
+to get credit for their work, while not being considered responsible
+for modifications made by others.
+
+This License is a kind of "copyleft", which means that derivative
+works of the document must themselves be free in the same sense. It
+complements the GNU General Public License, which is a copyleft
+license designed for free software.
+
+We have designed this License in order to use it for manuals for free
+software, because free software needs free documentation: a free
+program should come with manuals providing the same freedoms that the
+software does. But this License is not limited to software manuals;
+it can be used for any textual work, regardless of subject matter or
+whether it is published as a printed book. We recommend this License
+principally for works whose purpose is instruction or reference.
+
+
+1. APPLICABILITY AND DEFINITIONS
+
+This License applies to any manual or other work, in any medium, that
+contains a notice placed by the copyright holder saying it can be
+distributed under the terms of this License. Such a notice grants a
+world-wide, royalty-free license, unlimited in duration, to use that
+work under the conditions stated herein. The "Document", below,
+refers to any such manual or work. Any member of the public is a
+licensee, and is addressed as "you". You accept the license if you
+copy, modify or distribute the work in a way requiring permission
+under copyright law.
+
+A "Modified Version" of the Document means any work containing the
+Document or a portion of it, either copied verbatim, or with
+modifications and/or translated into another language.
+
+A "Secondary Section" is a named appendix or a front-matter section of
+the Document that deals exclusively with the relationship of the
+publishers or authors of the Document to the Document's overall
+subject (or to related matters) and contains nothing that could fall
+directly within that overall subject. (Thus, if the Document is in
+part a textbook of mathematics, a Secondary Section may not explain
+any mathematics.) The relationship could be a matter of historical
+connection with the subject or with related matters, or of legal,
+commercial, philosophical, ethical or political position regarding
+them.
+
+The "Invariant Sections" are certain Secondary Sections whose titles
+are designated, as being those of Invariant Sections, in the notice
+that says that the Document is released under this License. If a
+section does not fit the above definition of Secondary then it is not
+allowed to be designated as Invariant. The Document may contain zero
+Invariant Sections. If the Document does not identify any Invariant
+Sections then there are none.
+
+The "Cover Texts" are certain short passages of text that are listed,
+as Front-Cover Texts or Back-Cover Texts, in the notice that says that
+the Document is released under this License. A Front-Cover Text may
+be at most 5 words, and a Back-Cover Text may be at most 25 words.
+
+A "Transparent" copy of the Document means a machine-readable copy,
+represented in a format whose specification is available to the
+general public, that is suitable for revising the document
+straightforwardly with generic text editors or (for images composed of
+pixels) generic paint programs or (for drawings) some widely available
+drawing editor, and that is suitable for input to text formatters or
+for automatic translation to a variety of formats suitable for input
+to text formatters. A copy made in an otherwise Transparent file
+format whose markup, or absence of markup, has been arranged to thwart
+or discourage subsequent modification by readers is not Transparent.
+An image format is not Transparent if used for any substantial amount
+of text. A copy that is not "Transparent" is called "Opaque".
+
+Examples of suitable formats for Transparent copies include plain
+ASCII without markup, Texinfo input format, LaTeX input format, SGML
+or XML using a publicly available DTD, and standard-conforming simple
+HTML, PostScript or PDF designed for human modification. Examples of
+transparent image formats include PNG, XCF and JPG. Opaque formats
+include proprietary formats that can be read and edited only by
+proprietary word processors, SGML or XML for which the DTD and/or
+processing tools are not generally available, and the
+machine-generated HTML, PostScript or PDF produced by some word
+processors for output purposes only.
+
+The "Title Page" means, for a printed book, the title page itself,
+plus such following pages as are needed to hold, legibly, the material
+this License requires to appear in the title page. For works in
+formats which do not have any title page as such, "Title Page" means
+the text near the most prominent appearance of the work's title,
+preceding the beginning of the body of the text.
+
+The "publisher" means any person or entity that distributes copies of
+the Document to the public.
+
+A section "Entitled XYZ" means a named subunit of the Document whose
+title either is precisely XYZ or contains XYZ in parentheses following
+text that translates XYZ in another language. (Here XYZ stands for a
+specific section name mentioned below, such as "Acknowledgements",
+"Dedications", "Endorsements", or "History".) To "Preserve the Title"
+of such a section when you modify the Document means that it remains a
+section "Entitled XYZ" according to this definition.
+
+The Document may include Warranty Disclaimers next to the notice which
+states that this License applies to the Document. These Warranty
+Disclaimers are considered to be included by reference in this
+License, but only as regards disclaiming warranties: any other
+implication that these Warranty Disclaimers may have is void and has
+no effect on the meaning of this License.
+
+2. VERBATIM COPYING
+
+You may copy and distribute the Document in any medium, either
+commercially or noncommercially, provided that this License, the
+copyright notices, and the license notice saying this License applies
+to the Document are reproduced in all copies, and that you add no
+other conditions whatsoever to those of this License. You may not use
+technical measures to obstruct or control the reading or further
+copying of the copies you make or distribute. However, you may accept
+compensation in exchange for copies. If you distribute a large enough
+number of copies you must also follow the conditions in section 3.
+
+You may also lend copies, under the same conditions stated above, and
+you may publicly display copies.
+
+
+3. COPYING IN QUANTITY
+
+If you publish printed copies (or copies in media that commonly have
+printed covers) of the Document, numbering more than 100, and the
+Document's license notice requires Cover Texts, you must enclose the
+copies in covers that carry, clearly and legibly, all these Cover
+Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
+the back cover. Both covers must also clearly and legibly identify
+you as the publisher of these copies. The front cover must present
+the full title with all words of the title equally prominent and
+visible. You may add other material on the covers in addition.
+Copying with changes limited to the covers, as long as they preserve
+the title of the Document and satisfy these conditions, can be treated
+as verbatim copying in other respects.
+
+If the required texts for either cover are too voluminous to fit
+legibly, you should put the first ones listed (as many as fit
+reasonably) on the actual cover, and continue the rest onto adjacent
+pages.
+
+If you publish or distribute Opaque copies of the Document numbering
+more than 100, you must either include a machine-readable Transparent
+copy along with each Opaque copy, or state in or with each Opaque copy
+a computer-network location from which the general network-using
+public has access to download using public-standard network protocols
+a complete Transparent copy of the Document, free of added material.
+If you use the latter option, you must take reasonably prudent steps,
+when you begin distribution of Opaque copies in quantity, to ensure
+that this Transparent copy will remain thus accessible at the stated
+location until at least one year after the last time you distribute an
+Opaque copy (directly or through your agents or retailers) of that
+edition to the public.
+
+It is requested, but not required, that you contact the authors of the
+Document well before redistributing any large number of copies, to
+give them a chance to provide you with an updated version of the
+Document.
+
+
+4. MODIFICATIONS
+
+You may copy and distribute a Modified Version of the Document under
+the conditions of sections 2 and 3 above, provided that you release
+the Modified Version under precisely this License, with the Modified
+Version filling the role of the Document, thus licensing distribution
+and modification of the Modified Version to whoever possesses a copy
+of it. In addition, you must do these things in the Modified Version:
+
+A. Use in the Title Page (and on the covers, if any) a title distinct
+ from that of the Document, and from those of previous versions
+ (which should, if there were any, be listed in the History section
+ of the Document). You may use the same title as a previous version
+ if the original publisher of that version gives permission.
+B. List on the Title Page, as authors, one or more persons or entities
+ responsible for authorship of the modifications in the Modified
+ Version, together with at least five of the principal authors of the
+ Document (all of its principal authors, if it has fewer than five),
+ unless they release you from this requirement.
+C. State on the Title page the name of the publisher of the
+ Modified Version, as the publisher.
+D. Preserve all the copyright notices of the Document.
+E. Add an appropriate copyright notice for your modifications
+ adjacent to the other copyright notices.
+F. Include, immediately after the copyright notices, a license notice
+ giving the public permission to use the Modified Version under the
+ terms of this License, in the form shown in the Addendum below.
+G. Preserve in that license notice the full lists of Invariant Sections
+ and required Cover Texts given in the Document's license notice.
+H. Include an unaltered copy of this License.
+I. Preserve the section Entitled "History", Preserve its Title, and add
+ to it an item stating at least the title, year, new authors, and
+ publisher of the Modified Version as given on the Title Page. If
+ there is no section Entitled "History" in the Document, create one
+ stating the title, year, authors, and publisher of the Document as
+ given on its Title Page, then add an item describing the Modified
+ Version as stated in the previous sentence.
+J. Preserve the network location, if any, given in the Document for
+ public access to a Transparent copy of the Document, and likewise
+ the network locations given in the Document for previous versions
+ it was based on. These may be placed in the "History" section.
+ You may omit a network location for a work that was published at
+ least four years before the Document itself, or if the original
+ publisher of the version it refers to gives permission.
+K. For any section Entitled "Acknowledgements" or "Dedications",
+ Preserve the Title of the section, and preserve in the section all
+ the substance and tone of each of the contributor acknowledgements
+ and/or dedications given therein.
+L. Preserve all the Invariant Sections of the Document,
+ unaltered in their text and in their titles. Section numbers
+ or the equivalent are not considered part of the section titles.
+M. Delete any section Entitled "Endorsements". Such a section
+ may not be included in the Modified Version.
+N. Do not retitle any existing section to be Entitled "Endorsements"
+ or to conflict in title with any Invariant Section.
+O. Preserve any Warranty Disclaimers.
+
+If the Modified Version includes new front-matter sections or
+appendices that qualify as Secondary Sections and contain no material
+copied from the Document, you may at your option designate some or all
+of these sections as invariant. To do this, add their titles to the
+list of Invariant Sections in the Modified Version's license notice.
+These titles must be distinct from any other section titles.
+
+You may add a section Entitled "Endorsements", provided it contains
+nothing but endorsements of your Modified Version by various
+parties--for example, statements of peer review or that the text has
+been approved by an organization as the authoritative definition of a
+standard.
+
+You may add a passage of up to five words as a Front-Cover Text, and a
+passage of up to 25 words as a Back-Cover Text, to the end of the list
+of Cover Texts in the Modified Version. Only one passage of
+Front-Cover Text and one of Back-Cover Text may be added by (or
+through arrangements made by) any one entity. If the Document already
+includes a cover text for the same cover, previously added by you or
+by arrangement made by the same entity you are acting on behalf of,
+you may not add another; but you may replace the old one, on explicit
+permission from the previous publisher that added the old one.
+
+The author(s) and publisher(s) of the Document do not by this License
+give permission to use their names for publicity for or to assert or
+imply endorsement of any Modified Version.
+
+
+5. COMBINING DOCUMENTS
+
+You may combine the Document with other documents released under this
+License, under the terms defined in section 4 above for modified
+versions, provided that you include in the combination all of the
+Invariant Sections of all of the original documents, unmodified, and
+list them all as Invariant Sections of your combined work in its
+license notice, and that you preserve all their Warranty Disclaimers.
+
+The combined work need only contain one copy of this License, and
+multiple identical Invariant Sections may be replaced with a single
+copy. If there are multiple Invariant Sections with the same name but
+different contents, make the title of each such section unique by
+adding at the end of it, in parentheses, the name of the original
+author or publisher of that section if known, or else a unique number.
+Make the same adjustment to the section titles in the list of
+Invariant Sections in the license notice of the combined work.
+
+In the combination, you must combine any sections Entitled "History"
+in the various original documents, forming one section Entitled
+"History"; likewise combine any sections Entitled "Acknowledgements",
+and any sections Entitled "Dedications". You must delete all sections
+Entitled "Endorsements".
+
+
+6. COLLECTIONS OF DOCUMENTS
+
+You may make a collection consisting of the Document and other
+documents released under this License, and replace the individual
+copies of this License in the various documents with a single copy
+that is included in the collection, provided that you follow the rules
+of this License for verbatim copying of each of the documents in all
+other respects.
+
+You may extract a single document from such a collection, and
+distribute it individually under this License, provided you insert a
+copy of this License into the extracted document, and follow this
+License in all other respects regarding verbatim copying of that
+document.
+
+
+7. AGGREGATION WITH INDEPENDENT WORKS
+
+A compilation of the Document or its derivatives with other separate
+and independent documents or works, in or on a volume of a storage or
+distribution medium, is called an "aggregate" if the copyright
+resulting from the compilation is not used to limit the legal rights
+of the compilation's users beyond what the individual works permit.
+When the Document is included in an aggregate, this License does not
+apply to the other works in the aggregate which are not themselves
+derivative works of the Document.
+
+If the Cover Text requirement of section 3 is applicable to these
+copies of the Document, then if the Document is less than one half of
+the entire aggregate, the Document's Cover Texts may be placed on
+covers that bracket the Document within the aggregate, or the
+electronic equivalent of covers if the Document is in electronic form.
+Otherwise they must appear on printed covers that bracket the whole
+aggregate.
+
+
+8. TRANSLATION
+
+Translation is considered a kind of modification, so you may
+distribute translations of the Document under the terms of section 4.
+Replacing Invariant Sections with translations requires special
+permission from their copyright holders, but you may include
+translations of some or all Invariant Sections in addition to the
+original versions of these Invariant Sections. You may include a
+translation of this License, and all the license notices in the
+Document, and any Warranty Disclaimers, provided that you also include
+the original English version of this License and the original versions
+of those notices and disclaimers. In case of a disagreement between
+the translation and the original version of this License or a notice
+or disclaimer, the original version will prevail.
+
+If a section in the Document is Entitled "Acknowledgements",
+"Dedications", or "History", the requirement (section 4) to Preserve
+its Title (section 1) will typically require changing the actual
+title.
+
+
+9. TERMINATION
+
+You may not copy, modify, sublicense, or distribute the Document
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense, or distribute it is void, and
+will automatically terminate your rights under this License.
+
+However, if you cease all violation of this License, then your license
+from a particular copyright holder is reinstated (a) provisionally,
+unless and until the copyright holder explicitly and finally
+terminates your license, and (b) permanently, if the copyright holder
+fails to notify you of the violation by some reasonable means prior to
+60 days after the cessation.
+
+Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, receipt of a copy of some or all of the same material does
+not give you any rights to use it.
+
+
+10. FUTURE REVISIONS OF THIS LICENSE
+
+The Free Software Foundation may publish new, revised versions of the
+GNU Free Documentation License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in
+detail to address new problems or concerns. See
+https://www.gnu.org/licenses/.
+
+Each version of the License is given a distinguishing version number.
+If the Document specifies that a particular numbered version of this
+License "or any later version" applies to it, you have the option of
+following the terms and conditions either of that specified version or
+of any later version that has been published (not as a draft) by the
+Free Software Foundation. If the Document does not specify a version
+number of this License, you may choose any version ever published (not
+as a draft) by the Free Software Foundation. If the Document
+specifies that a proxy can decide which future versions of this
+License can be used, that proxy's public statement of acceptance of a
+version permanently authorizes you to choose that version for the
+Document.
+
+11. RELICENSING
+
+"Massive Multiauthor Collaboration Site" (or "MMC Site") means any
+World Wide Web server that publishes copyrightable works and also
+provides prominent facilities for anybody to edit those works. A
+public wiki that anybody can edit is an example of such a server. A
+"Massive Multiauthor Collaboration" (or "MMC") contained in the site
+means any set of copyrightable works thus published on the MMC site.
+
+"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
+license published by Creative Commons Corporation, a not-for-profit
+corporation with a principal place of business in San Francisco,
+California, as well as future copyleft versions of that license
+published by that same organization.
+
+"Incorporate" means to publish or republish a Document, in whole or in
+part, as part of another Document.
+
+An MMC is "eligible for relicensing" if it is licensed under this
+License, and if all works that were first published under this License
+somewhere other than this MMC, and subsequently incorporated in whole or
+in part into the MMC, (1) had no cover texts or invariant sections, and
+(2) were thus incorporated prior to November 1, 2008.
+
+The operator of an MMC Site may republish an MMC contained in the site
+under CC-BY-SA on the same site at any time before August 1, 2009,
+provided the MMC is eligible for relicensing.
+
+
+ADDENDUM: How to use this License for your documents
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and
+license notices just after the title page:
+
+ Copyright (c) YEAR YOUR NAME.
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.3
+ or any later version published by the Free Software Foundation;
+ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+ A copy of the license is included in the section entitled "GNU
+ Free Documentation License".
+
+If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
+replace the "with...Texts." line with this:
+
+ with the Invariant Sections being LIST THEIR TITLES, with the
+ Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
+
+If you have Invariant Sections without Cover Texts, or some other
+combination of the three, merge those two alternatives to suit the
+situation.
+
+If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License,
+to permit their use in free software.
diff --git a/LICENSE.GPL2 b/LICENSES/GPL-2.0-only.txt
index d159169..d159169 100644
--- a/LICENSE.GPL2
+++ b/LICENSES/GPL-2.0-only.txt
diff --git a/LICENSE.GPL3 b/LICENSES/GPL-3.0-only.txt
index 94a9ed0..94a9ed0 100644
--- a/LICENSE.GPL3
+++ b/LICENSES/GPL-3.0-only.txt
diff --git a/LICENSE.LGPL3 b/LICENSES/LGPL-3.0-only.txt
index 65c5ca8..65c5ca8 100644
--- a/LICENSE.LGPL3
+++ b/LICENSES/LGPL-3.0-only.txt
diff --git a/LICENSES/LicenseRef-Qt-Commercial.txt b/LICENSES/LicenseRef-Qt-Commercial.txt
new file mode 100644
index 0000000..825b1f3
--- /dev/null
+++ b/LICENSES/LicenseRef-Qt-Commercial.txt
@@ -0,0 +1,8 @@
+Licensees holding valid commercial Qt licenses may use this software in
+accordance with the the terms contained in a written agreement between
+you and The Qt Company. Alternatively, the terms and conditions that were
+accepted by the licensee when buying and/or downloading the
+software do apply.
+
+For the latest licensing terms and conditions, see https://www.qt.io/terms-conditions.
+For further information use the contact form at https://www.qt.io/contact-us.
diff --git a/LICENSES/Qt-GPL-exception-1.0.txt b/LICENSES/Qt-GPL-exception-1.0.txt
new file mode 100644
index 0000000..d0322bf
--- /dev/null
+++ b/LICENSES/Qt-GPL-exception-1.0.txt
@@ -0,0 +1,22 @@
+The Qt Company GPL Exception 1.0
+
+Exception 1:
+
+As a special exception you may create a larger work which contains the
+output of this application and distribute that work under terms of your
+choice, so long as the work is not otherwise derived from or based on
+this application and so long as the work does not in itself generate
+output that contains the output from this application in its original
+or modified form.
+
+Exception 2:
+
+As a special exception, you have permission to combine this application
+with Plugins licensed under the terms of your choice, to produce an
+executable, and to copy and distribute the resulting executable under
+the terms of your choice. However, the executable must be accompanied
+by a prominent notice offering all users of the executable the entire
+source code to this application, excluding the source code of the
+independent modules, but including any changes you have made to this
+application, under the terms of this license.
+
diff --git a/README.md b/README.md
index 49f75d1..517cb1d 100644
--- a/README.md
+++ b/README.md
@@ -31,4 +31,4 @@ To use, add `websockets` to the QT variable.
`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).
### Missing Features
-* Extensions and sub-protocols
+* Extensions
diff --git a/coin/axivion/ci_config_linux.json b/coin/axivion/ci_config_linux.json
new file mode 100644
index 0000000..15cbe03
--- /dev/null
+++ b/coin/axivion/ci_config_linux.json
@@ -0,0 +1,60 @@
+{
+ "Project": {
+ "Git": {
+ "_active": true,
+ "sourceserver_gitdir": "/data/axivion/databases/$(env:TESTED_MODULE_COIN).git"
+ },
+ "BuildSystemIntegration": {
+ "child_order": [
+ "GCCSetup",
+ "CMake",
+ "LinkLibraries"
+ ]
+ },
+ "CMake": {
+ "_active": true,
+ "_copy_from": "CMakeIntegration",
+ "build_environment": {},
+ "build_options": "-j4",
+ "generate_options": "--fresh",
+ "generator": "Ninja"
+ },
+ "GCCSetup": {
+ "_active": true,
+ "_copy_from": "Command",
+ "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/"
+ },
+ "LinkLibraries": {
+ "_active": true,
+ "_copy_from": "AxivionLinker",
+ "input_files": [
+ "build/lib/lib*.so*.ir",
+ "build/qml/*/lib*.so*.ir"
+ ],
+ "ir": "build/$(env:TESTED_MODULE_COIN).ir"
+ },
+ "Project-GlobalOptions": {
+ "directory": "../work/qt/$(env:TESTED_MODULE_COIN)",
+ "ir": "build/$(env:TESTED_MODULE_COIN).ir",
+ "name": "qt_$(env:TESTED_MODULE_COIN)_dev_$(env:TARGET_OS_COIN)"
+ }
+ },
+ "Results": {
+ "Dashboard": {
+ "dashboard_url": "https://axivion-srv.ci.qt.io/axivion/"
+ },
+ "Database": {
+ "ci_mode": {
+ "directory": "/data/axivion/databases"
+ }
+ }
+ },
+ "_Format": "1.0",
+ "_Version": "trunk-9e0ef9c5818",
+ "_VersionNum": [
+ 7,
+ 6,
+ 9999,
+ 11489
+ ]
+}
diff --git a/coin/module_config.yaml b/coin/module_config.yaml
index 16d158c..aaf3323 100644
--- a/coin/module_config.yaml
+++ b/coin/module_config.yaml
@@ -10,3 +10,4 @@ instructions:
Test:
- !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml"
+ - !include "{{qt/qtbase}}/coin_module_test_docs.yaml"
diff --git a/conanfile.py b/conanfile.py
new file mode 100644
index 0000000..a2d9a84
--- /dev/null
+++ b/conanfile.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2021 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+from conans import ConanFile
+import re
+from pathlib import Path
+
+
+def _parse_qt_version_by_key(key: str) -> str:
+ with open(Path(__file__).parent.resolve() / ".cmake.conf") as f:
+ m = re.search(fr'{key} .*"(.*)"', f.read())
+ return m.group(1) if m else ""
+
+
+def _get_qt_minor_version() -> str:
+ return ".".join(_parse_qt_version_by_key("QT_REPO_MODULE_VERSION").split(".")[:2])
+
+
+class QtWebSockets(ConanFile):
+ name = "qtwebsockets"
+ license = "LGPL-3.0, GPL-2.0+, Commercial Qt License Agreement"
+ author = "The Qt Company <https://www.qt.io/contact-us>"
+ url = "https://code.qt.io/cgit/qt/qtwebsockets.git"
+ description = (
+ "WebSocket is a web-based protocol designed to enable two-way communication "
+ "between a client application and a remote host. It enables the two entities "
+ "to send data back and forth if the initial handshake succeeds. WebSocket is "
+ "the solution for applications that struggle to get real-time data feeds with "
+ "less network latency and minimum data exchange."
+ )
+ topics = "qt", "qt6", "qtwebsockets", "WebSocket"
+ settings = "os", "compiler", "arch", "build_type"
+ # for referencing the version number and prerelease tag and dependencies info
+ exports = ".cmake.conf", "dependencies.yaml"
+ exports_sources = "*", "!conan*.*"
+ python_requires = f"qt-conan-common/{_get_qt_minor_version()}@qt/everywhere"
+ python_requires_extend = "qt-conan-common.QtLeafModule"
diff --git a/dependencies.yaml b/dependencies.yaml
index 6acb751..a5ec542 100644
--- a/dependencies.yaml
+++ b/dependencies.yaml
@@ -1,7 +1,7 @@
dependencies:
../qtbase:
- ref: 46c1e609893b09a61d70dda3589e6b8d25261468
+ ref: 06830bd78d2cf43b9d544e3792711cbb60d1c27a
required: true
../qtdeclarative:
- ref: 6412bcd2219d2a5c1f8193d8f394ddb1279dee2b
+ ref: 30a95fa0ee4a456cc41d652bf5f6b3c1fce944fb
required: false
diff --git a/dist/changes-5.15.2 b/dist/changes-5.15.2
new file mode 100644
index 0000000..3f584ae
--- /dev/null
+++ b/dist/changes-5.15.2
@@ -0,0 +1,28 @@
+Qt 5.15.2 is a bug-fix release. It maintains both forward and backward
+compatibility (source and binary) with Qt 5.15.1.
+
+For more details, refer to the online documentation included in this
+distribution. The documentation is also available online:
+
+ https://doc.qt.io/qt-5.15/index.html
+
+The Qt version 5.15 series is binary compatible with the 5.14.x series.
+Applications compiled for 5.14 will continue to run with 5.15.
+
+Some of the changes listed in this file include issue tracking numbers
+corresponding to tasks in the Qt Bug Tracker:
+
+ https://bugreports.qt.io/
+
+Each of these identifiers can be entered in the bug tracker to obtain more
+information about a particular change.
+
+****************************************************************************
+* Important Behavior Changes *
+****************************************************************************
+
+****************************************************************************
+* Library *
+****************************************************************************
+
+
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index cc356de..9ddf25d 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,6 +1,7 @@
-# Generated from examples.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-qt_examples_build_begin()
+qt_examples_build_begin(EXTERNAL_BUILD)
add_subdirectory(websockets)
diff --git a/examples/websockets/CMakeLists.txt b/examples/websockets/CMakeLists.txt
index 196d6a1..25901f5 100644
--- a/examples/websockets/CMakeLists.txt
+++ b/examples/websockets/CMakeLists.txt
@@ -1,13 +1,14 @@
-# Generated from websockets.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-add_subdirectory(echoclient)
-add_subdirectory(echoserver)
-add_subdirectory(simplechat)
+qt_internal_add_example(echoclient)
+qt_internal_add_example(echoserver)
+qt_internal_add_example(simplechat)
if(TARGET Qt::Quick)
- add_subdirectory(qmlwebsocketclient)
- add_subdirectory(qmlwebsocketserver)
+ qt_internal_add_example(qmlwebsocketclient)
+ qt_internal_add_example(qmlwebsocketserver)
endif()
if(QT_FEATURE_ssl)
- add_subdirectory(sslechoserver)
- add_subdirectory(sslechoclient)
+ qt_internal_add_example(sslechoserver)
+ qt_internal_add_example(sslechoclient)
endif()
diff --git a/examples/websockets/doc/echoclient.qdoc b/examples/websockets/doc/echoclient.qdoc
index 654a3d6..871a916 100644
--- a/examples/websockets/doc/echoclient.qdoc
+++ b/examples/websockets/doc/echoclient.qdoc
@@ -1,61 +1,26 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example echoclient
- \title Echo Client Example
+ \title WebSocket Echo Client
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Describes how to use the WebSocket API for creating a simple echo client.
+ \brief Show how to write a simple WebSocket client application.
- The Echo Client Example shows how to use the WebSocket API to create a simple
- echo client.
+ The Echo Client shows how to use the \l {Qt WebSockets}{WebSocket}
+ API to send a message to a server and process whatever response the
+ server returns - in this case, simply reporting the response.
- \sa {Echo Server Example}
+ The client by default opens a WebSocket connection to a server listening
+ on local port 1234. When the connection attempt is successful, the client
+ will send a message to the server and print out whatever response the
+ server sends. The client then closes the connection.
+
+ \image echoclient-console-example.webp WebSocket Echo Console Client
+
+ For the sake of illustration, we use the \l {WebSocket Echo Server}, whose
+ reply is simply the message that was sent.
+
+ \sa {WebSocket Echo Server}
*/
diff --git a/examples/websockets/doc/echoserver.qdoc b/examples/websockets/doc/echoserver.qdoc
index 76a37ce..470474f 100644
--- a/examples/websockets/doc/echoserver.qdoc
+++ b/examples/websockets/doc/echoserver.qdoc
@@ -1,69 +1,25 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example echoserver
- \title Echo Server Example
+ \title WebSocket Echo Server
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Shows how to create a simple server application that
- sends back the messages it receives.
+ \brief Show how to write a simple WebSocket server application.
- The Echo Server Example shows how to create a simple server application that
- sends back the messages it receives, using the \l {Qt WebSockets}{WebSocket} API.
+ This Echo Server shows how to create a simple server application that sends
+ back a reply in response to a message it receives, using the
+ \l {Qt WebSockets}{WebSocket} API. For the sake of illustration, the reply
+ is simply a copy of the message.
If your web browser supports \l {Qt WebSockets}{WebSocket}, you can also use it
to open the \c {echoserver/echoclient.html}{echoclient.html} file, and operate
- like the following screenshot.
+ as shown in the following screenshot:
- \image echoclient-html-example.png Screenshot of the HTML version of Echo
- Client example
+ \image echoclient-html-example.png WebSocket Echo HTML Client
- \sa {Echo Client Example}
+ Otherwise use the \l {WebSocket Echo Client} to connect to the server.
+
+ \sa {WebSocket Echo Client}
*/
diff --git a/examples/websockets/doc/examples.qdoc b/examples/websockets/doc/examples.qdoc
index 6ce5bd5..6f23498 100644
--- a/examples/websockets/doc/examples.qdoc
+++ b/examples/websockets/doc/examples.qdoc
@@ -1,57 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\group qtwebsockets-examples
\title Qt WebSockets Examples
+ \examplecategory {Networking}
\brief List of Qt WebSocket examples
The examples below can be used as a guide to using the \l{Qt WebSockets} API.
diff --git a/examples/websockets/doc/images/echoclient-console-example.webp b/examples/websockets/doc/images/echoclient-console-example.webp
new file mode 100644
index 0000000..1b43a44
--- /dev/null
+++ b/examples/websockets/doc/images/echoclient-console-example.webp
Binary files differ
diff --git a/examples/websockets/doc/images/qmlwebsocketclient-example.webp b/examples/websockets/doc/images/qmlwebsocketclient-example.webp
new file mode 100644
index 0000000..24d5044
--- /dev/null
+++ b/examples/websockets/doc/images/qmlwebsocketclient-example.webp
Binary files differ
diff --git a/examples/websockets/doc/images/qmlwebsocketserver-example.webp b/examples/websockets/doc/images/qmlwebsocketserver-example.webp
new file mode 100644
index 0000000..6a13216
--- /dev/null
+++ b/examples/websockets/doc/images/qmlwebsocketserver-example.webp
Binary files differ
diff --git a/examples/websockets/doc/images/simplechat-html-example.webp b/examples/websockets/doc/images/simplechat-html-example.webp
new file mode 100644
index 0000000..e9808bb
--- /dev/null
+++ b/examples/websockets/doc/images/simplechat-html-example.webp
Binary files differ
diff --git a/examples/websockets/doc/images/sslechoclient-console-example.webp b/examples/websockets/doc/images/sslechoclient-console-example.webp
new file mode 100644
index 0000000..561df52
--- /dev/null
+++ b/examples/websockets/doc/images/sslechoclient-console-example.webp
Binary files differ
diff --git a/examples/websockets/doc/images/sslechoclient-html-example.webp b/examples/websockets/doc/images/sslechoclient-html-example.webp
new file mode 100644
index 0000000..b34060a
--- /dev/null
+++ b/examples/websockets/doc/images/sslechoclient-html-example.webp
Binary files differ
diff --git a/examples/websockets/doc/qmlwebsocketclient.qdoc b/examples/websockets/doc/qmlwebsocketclient.qdoc
index d5ac310..b3da626 100644
--- a/examples/websockets/doc/qmlwebsocketclient.qdoc
+++ b/examples/websockets/doc/qmlwebsocketclient.qdoc
@@ -1,56 +1,31 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example qmlwebsocketclient
- \title QML WebSocket Client Example
+ \title QML WebSocket Client
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Explains how to program a QML WebSocket client example.
+ \brief Explains how to write a QML WebSocket client example.
+
+ The QML WebSocket Client example creates a secure and an
+ insecure \l {Qt WebSockets}{WebSocket} connection to an echo
+ server, using the QML API, and alternates between opening
+ connections and closing them. Every time a connection has
+ been opened, it sends a message.
+
+ \image qmlwebsocketclient-example.webp QML WebSocket Client GUI
+
+ This example opens a window with a welcome message. Every time
+ the window is clicked on, it alternates between opening and
+ closing two connections to an external echo server. The echo
+ server used is at ws.ifelse.io, and an Internet connection is
+ necessary for the example to work. Also TLS must be enabled for
+ the secure connection to work. When the connection is opened or
+ closed, the statusChanged signal is handled by the
+ onStatusChanged handler. Every time the socket is opened, a
+ message is sent, and every time the socket is closed, a message
+ is logged in the window. In addition, there is an
+ onTextMessageReceived handler that logs to the window the
+ messages received from the server.
*/
diff --git a/examples/websockets/doc/qmlwebsocketserver.qdoc b/examples/websockets/doc/qmlwebsocketserver.qdoc
index 4f36fd1..099d6d6 100644
--- a/examples/websockets/doc/qmlwebsocketserver.qdoc
+++ b/examples/websockets/doc/qmlwebsocketserver.qdoc
@@ -1,56 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSocket module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example qmlwebsocketserver
- \title QML WebSocket Server Example
+ \title QML WebSocket Server
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
\brief A simple example that shows how to use a QML WebSocketServer.
+
+ \image qmlwebsocketserver-example.webp QML WebSocket Server GUI
+
+ This example opens a window and has a WebSocketServer listening
+ for incoming connections and a WebSocket connecting to the
+ WebSocketServer. Every time the window is clicked, the WebSocket
+ sends a message to the WebSocketServer. The WebSocketServer has a
+ signal handler that logs the incoming message to the window and
+ sends a message back again, and the WebSocket has a signal
+ handler that logs the returned message to the window.
*/
diff --git a/examples/websockets/doc/simplechat.qdoc b/examples/websockets/doc/simplechat.qdoc
index bb3d845..a89ab4b 100644
--- a/examples/websockets/doc/simplechat.qdoc
+++ b/examples/websockets/doc/simplechat.qdoc
@@ -1,61 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example simplechat
- \title Simple Chat Example
+ \title Simple WebSocket Chat
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Shows how to use the QWebSocket and QWebSocketServer classes
- for creating a minimalistic chat application over the WebSocket protocol.
+ \brief A minimal chat application using the WebSocket protocol.
- The Simple Chat Example shows how to use the QWebSocket and QWebSocketServer
- classes to create a minimalistic chat application over the WebSocket protocol.
+ This application shows how to use the QWebSocket and QWebSocketServer
+ classes to create a minimalist chat application over the WebSocket protocol.
+ The example is a server that allows multiple clients to connect to it to send
+ and receive messages.
+
+ By default it listens at localhost port 1234. It keeps track of all clients
+ that are connected to it, and each time one of the clients sends a message to
+ the server, the message is forwarded to all other clients. When a client
+ disconnects, it is removed from the list of clients.
+
+ \image simplechat-html-example.webp Simple WebSocket Chat HTML Client
+
+ There is also an HTML-client that is used to connect to and disconnect from
+ the server, query about the connection, send messages, and view all the
+ messages sent by other clients.
*/
diff --git a/examples/websockets/doc/sslechoclient.qdoc b/examples/websockets/doc/sslechoclient.qdoc
index ea8c8a5..c6766aa 100644
--- a/examples/websockets/doc/sslechoclient.qdoc
+++ b/examples/websockets/doc/sslechoclient.qdoc
@@ -1,62 +1,25 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example sslechoclient
- \title SSL Echo Client Example
+ \title Secure WebSocket Echo Client
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Shows how to use the QWebSocket class to implement an echo
- client over a secure connection (wss).
+ \brief A simple client application using secure WebSockets (wss).
- The SSL Echo Client example shows how to use the QWebSocket class to implement
- an echo client over a secure connection (wss).
+ The Secure WebSocket Echo Client example shows how to use the
+ \l {Qt WebSockets}{WebSocket} class to implement an echo client over
+ a secure connection (wss). It connects to a server and sends a message,
+ and when it receives a message back, it prints it out and exits. SSL
+ support is required for this example to work.
- \sa {Echo Client Example}, {SSL Echo Server Example}
+ This example connects by default to localhost at port 1234 using a secure
+ connection. It trusts the certificates signed by the CA certificates
+ configured in the SSL backend, and in addition trusts the certificate
+ used by \l {Secure WebSocket Echo Server}.
+
+ \image echoclient-console-example.webp Secure WebSocket Echo Console Client
+
+ \sa {WebSocket Echo Client}, {Secure WebSocket Echo Server}
*/
diff --git a/examples/websockets/doc/sslechoserver.qdoc b/examples/websockets/doc/sslechoserver.qdoc
index cce17d8..41ab060 100644
--- a/examples/websockets/doc/sslechoserver.qdoc
+++ b/examples/websockets/doc/sslechoserver.qdoc
@@ -1,62 +1,30 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example sslechoserver
- \title SSL Echo Server Example
+ \title Secure WebSocket Echo Server
+ \examplecategory {Networking}
\ingroup qtwebsockets-examples
- \brief Shows how to use the QWebSocketServer class for implementing a simple
- echo server over secure sockets (wss).
+ \brief A simple server to respond to clients over secure WebSockets (wss).
- The SSL Echo Server example shows how to use the QWebSocketServer class
- to implement a simple echo server over secure sockets (wss).
+ The Secure WebSocket Echo Server example shows how to use the QWebSocketServer
+ class to implement a simple echo server over secure sockets (wss). TLS support
+ is required for this example to work. It authenticates itself to the client
+ and, on success, can accept a message from the client, to which it responds.
+ For the sake of illustration, its response is simply a copy of the message
+ it was sent.
- \sa {SSL Echo Client Example}, {Echo Server Example}
+ This server is configured with a self-signed certificate and key.
+ Unless the clients contacting this server is configured to trust that
+ certificate, which \l {Secure WebSocket Echo Client} does, they will reject
+ this server.
+
+ \image sslechoclient-html-example.webp Secure WebSocket Echo HTML Client
+
+ There is an HTML-based client as part of this example. But it will only
+ work either if the browser used supports the certificate as described above,
+ or if it ignores TLS errors for localhost addresses.
+
+ \sa {Secure WebSocket Echo Client}, {WebSocket Echo Server}
*/
diff --git a/examples/websockets/echoclient/CMakeLists.txt b/examples/websockets/echoclient/CMakeLists.txt
index 0f451cf..3f92c26 100644
--- a/examples/websockets/echoclient/CMakeLists.txt
+++ b/examples/websockets/echoclient/CMakeLists.txt
@@ -1,27 +1,29 @@
-# Generated from echoclient.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(echoclient LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoclient")
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS Core WebSockets)
-add_executable(echoclient
+qt_add_executable(echoclient
echoclient.cpp echoclient.h
main.cpp
)
+
+set_target_properties(echoclient PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(echoclient PUBLIC
Qt::Core
Qt::WebSockets
diff --git a/examples/websockets/echoclient/echoclient.cpp b/examples/websockets/echoclient/echoclient.cpp
index 3d451d2..ef760c3 100644
--- a/examples/websockets/echoclient/echoclient.cpp
+++ b/examples/websockets/echoclient/echoclient.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "echoclient.h"
#include <QtCore/QDebug>
diff --git a/examples/websockets/echoclient/echoclient.h b/examples/websockets/echoclient/echoclient.h
index a7fd234..067956c 100644
--- a/examples/websockets/echoclient/echoclient.h
+++ b/examples/websockets/echoclient/echoclient.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef ECHOCLIENT_H
#define ECHOCLIENT_H
diff --git a/examples/websockets/echoclient/main.cpp b/examples/websockets/echoclient/main.cpp
index f272040..999df79 100644
--- a/examples/websockets/echoclient/main.cpp
+++ b/examples/websockets/echoclient/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QCoreApplication>
#include <QtCore/QCommandLineParser>
#include <QtCore/QCommandLineOption>
@@ -54,19 +7,41 @@
int main(int argc, char *argv[])
{
+ using namespace Qt::Literals::StringLiterals;
QCoreApplication a(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("QtWebSockets example: echoclient");
parser.addHelpOption();
- QCommandLineOption dbgOption(QStringList() << "d" << "debug",
+ QCommandLineOption dbgOption(
+ QStringList{ u"d"_s, u"debug"_s },
QCoreApplication::translate("main", "Debug output [default: off]."));
parser.addOption(dbgOption);
+ QCommandLineOption hostnameOption(
+ QStringList{ u"n"_s, u"hostname"_s },
+ QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname",
+ "localhost");
+ parser.addOption(hostnameOption);
+ QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s },
+ QCoreApplication::translate("main", "Port [default: 1234]."),
+ "port", "1234");
+ parser.addOption(portOption);
+
parser.process(a);
bool debug = parser.isSet(dbgOption);
-
- EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")), debug);
+ bool ok = true;
+ int port = parser.value(portOption).toInt(&ok);
+ if (!ok || port < 1 || port > 65535) {
+ qWarning("Port invalid, must be a number between 1 and 65535\n%s",
+ qPrintable(parser.helpText()));
+ return 1;
+ }
+ QUrl url;
+ url.setScheme(u"ws"_s);
+ url.setHost(parser.value(hostnameOption));
+ url.setPort(port);
+ EchoClient client(url, debug);
QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit);
return a.exec();
diff --git a/examples/websockets/echoserver/CMakeLists.txt b/examples/websockets/echoserver/CMakeLists.txt
index 7877364..6390ee3 100644
--- a/examples/websockets/echoserver/CMakeLists.txt
+++ b/examples/websockets/echoserver/CMakeLists.txt
@@ -1,26 +1,29 @@
-# Generated from echoserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(echoserver LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoserver")
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS WebSockets)
-add_executable(echoserver
+qt_add_executable(echoserver
echoserver.cpp echoserver.h
main.cpp
)
+
+set_target_properties(echoserver PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(echoserver PUBLIC
Qt::WebSockets
)
diff --git a/examples/websockets/echoserver/echoserver.cpp b/examples/websockets/echoserver/echoserver.cpp
index d4e3b65..2411e18 100644
--- a/examples/websockets/echoserver/echoserver.cpp
+++ b/examples/websockets/echoserver/echoserver.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "echoserver.h"
#include "QtWebSockets/qwebsocketserver.h"
#include "QtWebSockets/qwebsocket.h"
diff --git a/examples/websockets/echoserver/echoserver.h b/examples/websockets/echoserver/echoserver.h
index 3681917..eb179af 100644
--- a/examples/websockets/echoserver/echoserver.h
+++ b/examples/websockets/echoserver/echoserver.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef ECHOSERVER_H
#define ECHOSERVER_H
diff --git a/examples/websockets/echoserver/main.cpp b/examples/websockets/echoserver/main.cpp
index f857f0f..5b7d206 100644
--- a/examples/websockets/echoserver/main.cpp
+++ b/examples/websockets/echoserver/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QCoreApplication>
#include <QtCore/QCommandLineParser>
#include <QtCore/QCommandLineOption>
diff --git a/examples/websockets/qmlwebsocketclient/CMakeLists.txt b/examples/websockets/qmlwebsocketclient/CMakeLists.txt
index 73da980..e720ace 100644
--- a/examples/websockets/qmlwebsocketclient/CMakeLists.txt
+++ b/examples/websockets/qmlwebsocketclient/CMakeLists.txt
@@ -1,28 +1,28 @@
-# Generated from qmlwebsocketclient.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(qmlwebsocketclient LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketclient")
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Quick)
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets)
-add_executable(qmlwebsocketclient
+qt_add_executable(qmlwebsocketclient
main.cpp
)
+
+set_target_properties(qmlwebsocketclient PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(qmlwebsocketclient PUBLIC
Qt::Core
Qt::Gui
@@ -30,7 +30,6 @@ target_link_libraries(qmlwebsocketclient PUBLIC
Qt::WebSockets
)
-
# Resources:
set(data_resource_files
"qml/qmlwebsocketclient/main.qml"
diff --git a/examples/websockets/qmlwebsocketclient/main.cpp b/examples/websockets/qmlwebsocketclient/main.cpp
index 8627180..90a04fe 100644
--- a/examples/websockets/qmlwebsocketclient/main.cpp
+++ b/examples/websockets/qmlwebsocketclient/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtGui/QGuiApplication>
#include <QQuickView>
diff --git a/examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml b/examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml
index 4c00411..5a98a83 100644
--- a/examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml
+++ b/examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml
@@ -1,63 +1,16 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick 2.0
import QtWebSockets 1.0
Rectangle {
- width: 360
+ width: 640
height: 360
WebSocket {
id: socket
- url: "ws://echo.websocket.org"
- onTextMessageReceived: {
+ url: "ws://ws.ifelse.io"
+ onTextMessageReceived: function(message) {
messageBox.text = messageBox.text + "\nReceived message: " + message
}
onStatusChanged: if (socket.status == WebSocket.Error) {
@@ -72,8 +25,8 @@ Rectangle {
WebSocket {
id: secureWebSocket
- url: "wss://echo.websocket.org"
- onTextMessageReceived: {
+ url: "wss://ws.ifelse.io"
+ onTextMessageReceived: function(message) {
messageBox.text = messageBox.text + "\nReceived secure message: " + message
}
onStatusChanged: if (secureWebSocket.status == WebSocket.Error) {
diff --git a/examples/websockets/qmlwebsocketserver/CMakeLists.txt b/examples/websockets/qmlwebsocketserver/CMakeLists.txt
index cd6fec7..9a6272f 100644
--- a/examples/websockets/qmlwebsocketserver/CMakeLists.txt
+++ b/examples/websockets/qmlwebsocketserver/CMakeLists.txt
@@ -1,28 +1,28 @@
-# Generated from qmlwebsocketserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(qmlwebsocketserver LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketserver")
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Quick)
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets)
-add_executable(qmlwebsocketserver
+qt_add_executable(qmlwebsocketserver
main.cpp
)
+
+set_target_properties(qmlwebsocketserver PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(qmlwebsocketserver PUBLIC
Qt::Core
Qt::Gui
@@ -30,7 +30,6 @@ target_link_libraries(qmlwebsocketserver PUBLIC
Qt::WebSockets
)
-
# Resources:
set(data_resource_files
"qml/qmlwebsocketserver/main.qml"
diff --git a/examples/websockets/qmlwebsocketserver/main.cpp b/examples/websockets/qmlwebsocketserver/main.cpp
index 2390823..47699b8 100644
--- a/examples/websockets/qmlwebsocketserver/main.cpp
+++ b/examples/websockets/qmlwebsocketserver/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSocket module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtGui/QGuiApplication>
#include <QQuickView>
diff --git a/examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml b/examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml
index 8ada653..644e4d6 100644
--- a/examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml
+++ b/examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSocket module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick 2.0
import QtWebSockets 1.0
@@ -62,7 +15,7 @@ Rectangle {
WebSocketServer {
id: server
listen: true
- onClientConnected: {
+ onClientConnected: function(webSocket) {
webSocket.onTextMessageReceived.connect(function(message) {
appendMessage(qsTr("Server received message: %1").arg(message));
webSocket.sendTextMessage(qsTr("Hello Client!"));
@@ -76,7 +29,9 @@ Rectangle {
WebSocket {
id: socket
url: server.url
- onTextMessageReceived: appendMessage(qsTr("Client received message: %1").arg(message))
+ onTextMessageReceived: function(message) {
+ appendMessage(qsTr("Client received message: %1").arg(message));
+ }
onStatusChanged: {
if (socket.status == WebSocket.Error) {
appendMessage(qsTr("Client error: %1").arg(socket.errorString));
@@ -86,6 +41,14 @@ Rectangle {
}
}
+ Timer {
+ interval: 100
+ running: true
+ onTriggered: {
+ socket.active = true;
+ }
+ }
+
Text {
id: messageBox
text: qsTr("Click to send a message!")
diff --git a/examples/websockets/simplechat/CMakeLists.txt b/examples/websockets/simplechat/CMakeLists.txt
index 82c2fea..f59f1e7 100644
--- a/examples/websockets/simplechat/CMakeLists.txt
+++ b/examples/websockets/simplechat/CMakeLists.txt
@@ -1,31 +1,34 @@
-# Generated from simplechat.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
-project(chatserver LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
+cmake_minimum_required(VERSION 3.16)
+project(simplechatserver LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/simplechat")
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS WebSockets)
-add_executable(chatserver
+qt_add_executable(simplechatserver
chatserver.cpp chatserver.h
main.cpp
)
-target_link_libraries(chatserver PUBLIC
+
+set_target_properties(simplechatserver PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+
+target_link_libraries(simplechatserver PUBLIC
Qt::WebSockets
)
-install(TARGETS chatserver
+install(TARGETS simplechatserver
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/websockets/simplechat/chatserver.cpp b/examples/websockets/simplechat/chatserver.cpp
index 8885fe8..79d7c62 100644
--- a/examples/websockets/simplechat/chatserver.cpp
+++ b/examples/websockets/simplechat/chatserver.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "chatserver.h"
#include <QtWebSockets>
@@ -104,7 +57,7 @@ void ChatServer::onNewConnection()
void ChatServer::processMessage(const QString &message)
{
QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
- for (QWebSocket *pClient : qAsConst(m_clients)) {
+ for (QWebSocket *pClient : std::as_const(m_clients)) {
if (pClient != pSender) //don't echo message back to sender
pClient->sendTextMessage(message);
}
diff --git a/examples/websockets/simplechat/chatserver.h b/examples/websockets/simplechat/chatserver.h
index 5e2a094..d720e13 100644
--- a/examples/websockets/simplechat/chatserver.h
+++ b/examples/websockets/simplechat/chatserver.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef CHATSERVER_H
#define CHATSERVER_H
diff --git a/examples/websockets/simplechat/main.cpp b/examples/websockets/simplechat/main.cpp
index a1ffb49..75209eb 100644
--- a/examples/websockets/simplechat/main.cpp
+++ b/examples/websockets/simplechat/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QCoreApplication>
#include "chatserver.h"
diff --git a/examples/websockets/simplechat/simplechat.pro b/examples/websockets/simplechat/simplechat.pro
index 235ccc0..3c18709 100644
--- a/examples/websockets/simplechat/simplechat.pro
+++ b/examples/websockets/simplechat/simplechat.pro
@@ -1,6 +1,6 @@
QT = websockets
-TARGET = chatserver
+TARGET = simplechatserver
CONFIG += console
CONFIG -= app_bundle
diff --git a/examples/websockets/sslechoclient/CMakeLists.txt b/examples/websockets/sslechoclient/CMakeLists.txt
index b1269f2..b629a9d 100644
--- a/examples/websockets/sslechoclient/CMakeLists.txt
+++ b/examples/websockets/sslechoclient/CMakeLists.txt
@@ -1,26 +1,34 @@
-# Generated from sslechoclient.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(sslechoclient LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoclient")
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS WebSockets)
-add_executable(sslechoclient
+qt_add_executable(sslechoclient
main.cpp
sslechoclient.cpp sslechoclient.h
)
+
+qt_add_resources(sslechoclient "cert"
+ BASE ../sslechoserver
+ FILES ../sslechoserver/localhost.cert
+)
+
+set_target_properties(sslechoclient PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(sslechoclient PUBLIC
Qt::WebSockets
)
diff --git a/examples/websockets/sslechoclient/main.cpp b/examples/websockets/sslechoclient/main.cpp
index b574b70..2d65ed6 100644
--- a/examples/websockets/sslechoclient/main.cpp
+++ b/examples/websockets/sslechoclient/main.cpp
@@ -1,60 +1,42 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QCoreApplication>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QCommandLineOption>
#include "sslechoclient.h"
int main(int argc, char *argv[])
{
+ using namespace Qt::Literals::StringLiterals;
QCoreApplication a(argc, argv);
- SslEchoClient client(QUrl(QStringLiteral("wss://localhost:1234")));
+ QCommandLineParser parser;
+ parser.setApplicationDescription("QtWebSockets example: sslechoclient");
+ parser.addHelpOption();
+
+ QCommandLineOption hostnameOption(
+ QStringList{ u"n"_s, u"hostname"_s },
+ QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname",
+ "localhost");
+ parser.addOption(hostnameOption);
+ QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s },
+ QCoreApplication::translate("main", "Port [default: 1234]."),
+ "port", "1234");
+ parser.addOption(portOption);
+
+ parser.process(a);
+ bool ok = true;
+ int port = parser.value(portOption).toInt(&ok);
+ if (!ok || port < 1 || port > 65535) {
+ qWarning("Port invalid, must be a number between 1 and 65535\n%s",
+ qPrintable(parser.helpText()));
+ return 1;
+ }
+ QUrl url;
+ url.setScheme(u"wss"_s);
+ url.setHost(parser.value(hostnameOption));
+ url.setPort(port);
+ SslEchoClient client(url);
Q_UNUSED(client);
return a.exec();
diff --git a/examples/websockets/sslechoclient/sslechoclient.cpp b/examples/websockets/sslechoclient/sslechoclient.cpp
index 6427f88..e5099e1 100644
--- a/examples/websockets/sslechoclient/sslechoclient.cpp
+++ b/examples/websockets/sslechoclient/sslechoclient.cpp
@@ -1,56 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "sslechoclient.h"
+#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
+#include <QtCore/QFile>
#include <QtWebSockets/QWebSocket>
-#include <QCoreApplication>
QT_USE_NAMESPACE
@@ -61,6 +15,15 @@ SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
this, &SslEchoClient::onSslErrors);
+
+ QSslConfiguration sslConfiguration;
+ QFile certFile(QStringLiteral(":/localhost.cert"));
+ certFile.open(QIODevice::ReadOnly);
+ QSslCertificate certificate(&certFile, QSsl::Pem);
+ certFile.close();
+ sslConfiguration.addCaCertificate(certificate);
+ m_webSocket.setSslConfiguration(sslConfiguration);
+
m_webSocket.open(QUrl(url));
}
//! [constructor]
@@ -84,12 +47,8 @@ void SslEchoClient::onTextMessageReceived(QString message)
void SslEchoClient::onSslErrors(const QList<QSslError> &errors)
{
- Q_UNUSED(errors);
+ qWarning() << "SSL errors:" << errors;
- // WARNING: Never ignore SSL errors in production code.
- // The proper way to handle self-signed certificates is to add a custom root
- // to the CA store.
-
- m_webSocket.ignoreSslErrors();
+ qApp->quit();
}
//! [onTextMessageReceived]
diff --git a/examples/websockets/sslechoclient/sslechoclient.h b/examples/websockets/sslechoclient/sslechoclient.h
index 6634a44..0eb4fcf 100644
--- a/examples/websockets/sslechoclient/sslechoclient.h
+++ b/examples/websockets/sslechoclient/sslechoclient.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef SSLECHOCLIENT_H
#define SSLECHOCLIENT_H
diff --git a/examples/websockets/sslechoclient/sslechoclient.pro b/examples/websockets/sslechoclient/sslechoclient.pro
index 3fa9d9b..29bbe74 100644
--- a/examples/websockets/sslechoclient/sslechoclient.pro
+++ b/examples/websockets/sslechoclient/sslechoclient.pro
@@ -13,5 +13,10 @@ SOURCES += \
HEADERS += \
sslechoclient.h
+resources.files = ../sslechoserver/localhost.cert
+resources.prefix = /
+
+RESOURCES += resources
+
target.path = $$[QT_INSTALL_EXAMPLES]/websockets/sslechoclient
INSTALLS += target
diff --git a/examples/websockets/sslechoserver/CMakeLists.txt b/examples/websockets/sslechoserver/CMakeLists.txt
index 8f71e97..7288373 100644
--- a/examples/websockets/sslechoserver/CMakeLists.txt
+++ b/examples/websockets/sslechoserver/CMakeLists.txt
@@ -1,31 +1,33 @@
-# Generated from sslechoserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(sslechoserver LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoserver")
-find_package(Qt6 COMPONENTS WebSockets)
+find_package(Qt6 REQUIRED COMPONENTS WebSockets)
-add_executable(sslechoserver
+qt_add_executable(sslechoserver
main.cpp
sslechoserver.cpp sslechoserver.h
)
+
+set_target_properties(sslechoserver PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+
target_link_libraries(sslechoserver PUBLIC
Qt::WebSockets
)
-
# Resources:
set(securesocketclient_resource_files
"localhost.cert"
diff --git a/examples/websockets/sslechoserver/main.cpp b/examples/websockets/sslechoserver/main.cpp
index e42f3e1..f67af47 100644
--- a/examples/websockets/sslechoserver/main.cpp
+++ b/examples/websockets/sslechoserver/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QCoreApplication>
#include "sslechoserver.h"
diff --git a/examples/websockets/sslechoserver/sslechoserver.cpp b/examples/websockets/sslechoserver/sslechoserver.cpp
index 5dc41e0..793a701 100644
--- a/examples/websockets/sslechoserver/sslechoserver.cpp
+++ b/examples/websockets/sslechoserver/sslechoserver.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "sslechoserver.h"
#include "QtWebSockets/QWebSocketServer"
#include "QtWebSockets/QWebSocket"
diff --git a/examples/websockets/sslechoserver/sslechoserver.h b/examples/websockets/sslechoserver/sslechoserver.h
index 58d1d67..72b3231 100644
--- a/examples/websockets/sslechoserver/sslechoserver.h
+++ b/examples/websockets/sslechoserver/sslechoserver.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** 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
-** OWNER 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."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef SSLECHOSERVER_H
#define SSLECHOSERVER_H
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0b457c8..21b5bdb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from src.pro.
add_subdirectory(websockets)
diff --git a/src/imports/.prev_CMakeLists.txt b/src/imports/.prev_CMakeLists.txt
deleted file mode 100644
index 5a0e274..0000000
--- a/src/imports/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-# Generated from imports.pro.
-
-add_subdirectory(qmlwebsockets)
-add_subdirectory(qmlwebsockets_compat)
diff --git a/src/imports/CMakeLists.txt b/src/imports/CMakeLists.txt
index e202821..be4dfc1 100644
--- a/src/imports/CMakeLists.txt
+++ b/src/imports/CMakeLists.txt
@@ -1,4 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from imports.pro.
add_subdirectory(qmlwebsockets)
-#add_subdirectory(qmlwebsockets_compat) # special case
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
deleted file mode 100644
index bb0d300..0000000
--- a/src/imports/imports.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += qmlwebsockets \
- qmlwebsockets_compat
diff --git a/src/imports/qmlwebsockets/.prev_CMakeLists.txt b/src/imports/qmlwebsockets/.prev_CMakeLists.txt
deleted file mode 100644
index adb02fe..0000000
--- a/src/imports/qmlwebsockets/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-# Generated from qmlwebsockets.pro.
-
-#####################################################################
-## qmlwebsockets Plugin:
-#####################################################################
-
-qt_add_qml_module(qmlwebsockets
- URI "QtWebSockets"
- VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}"
- CLASSNAME QtWebSocketsDeclarativeModule
- SKIP_TYPE_REGISTRATION
- SOURCES
- qmlwebsockets_plugin.cpp qmlwebsockets_plugin.h
- qqmlwebsocket.cpp qqmlwebsocket.h
- qqmlwebsocketserver.cpp qqmlwebsocketserver.h
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::QmlPrivate
- Qt::WebSockets
-)
-
-#### Keys ignored in scope 1:.:.:qmlwebsockets.pro:<TRUE>:
-# IMPORT_VERSION = "1.$$QT_MINOR_VERSION"
-# OTHER_FILES = "qmldir"
-# TARGETPATH = "QtWebSockets"
diff --git a/src/imports/qmlwebsockets/CMakeLists.txt b/src/imports/qmlwebsockets/CMakeLists.txt
index c182e6c..b937fe1 100644
--- a/src/imports/qmlwebsockets/CMakeLists.txt
+++ b/src/imports/qmlwebsockets/CMakeLists.txt
@@ -1,25 +1,22 @@
-# Generated from qmlwebsockets.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-#####################################################################
-## qmlwebsockets Plugin:
-#####################################################################
-
-qt_add_qml_module(qmlwebsockets
+qt_internal_add_qml_module(qmlwebsockets
URI "QtWebSockets"
- VERSION "1.0" #special case
- CLASSNAME QtWebSocketsDeclarativeModule
- SKIP_TYPE_REGISTRATION
+ VERSION "${PROJECT_VERSION}"
+ PAST_MAJOR_VERSIONS 1
+ CLASS_NAME QtWebSocketsDeclarativeModule
+ PLUGIN_TARGET qmlwebsockets
+ NO_PLUGIN_OPTIONAL
+ NO_GENERATE_PLUGIN_SOURCE
+ NO_GENERATE_QMLTYPES
+ INSTALL_SOURCE_QMLTYPES "plugins.qmltypes"
SOURCES
qmlwebsockets_plugin.cpp qmlwebsockets_plugin.h
qqmlwebsocket.cpp qqmlwebsocket.h
qqmlwebsocketserver.cpp qqmlwebsocketserver.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::QmlPrivate
Qt::WebSockets
)
-
-#### Keys ignored in scope 1:.:.:qmlwebsockets.pro:<TRUE>:
-# IMPORT_VERSION = "1.$$QT_MINOR_VERSION"
-# OTHER_FILES = "qmldir"
-# TARGETPATH = "QtWebSockets"
diff --git a/src/imports/qmlwebsockets/dependencies.json b/src/imports/qmlwebsockets/dependencies.json
deleted file mode 100644
index 0d4f101..0000000
--- a/src/imports/qmlwebsockets/dependencies.json
+++ /dev/null
@@ -1,2 +0,0 @@
-[
-]
diff --git a/src/imports/qmlwebsockets/qmldir b/src/imports/qmlwebsockets/qmldir
deleted file mode 100644
index 130b79f..0000000
--- a/src/imports/qmlwebsockets/qmldir
+++ /dev/null
@@ -1,4 +0,0 @@
-module QtWebSockets
-plugin declarative_qmlwebsockets
-classname QtWebSocketsDeclarativeModule
-typeinfo plugins.qmltypes
diff --git a/src/imports/qmlwebsockets/qmlwebsockets.pro b/src/imports/qmlwebsockets/qmlwebsockets.pro
deleted file mode 100644
index c058918..0000000
--- a/src/imports/qmlwebsockets/qmlwebsockets.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-QT = websockets qml-private core-private
-
-TARGETPATH = QtWebSockets
-
-HEADERS += qmlwebsockets_plugin.h \
- qqmlwebsocket.h \
- qqmlwebsocketserver.h
-
-SOURCES += qmlwebsockets_plugin.cpp \
- qqmlwebsocket.cpp \
- qqmlwebsocketserver.cpp
-
-OTHER_FILES += qmldir
-
-IMPORT_VERSION = 1.$$QT_MINOR_VERSION
-
-load(qml_plugin)
diff --git a/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp b/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
index 467e08c..bbb8236 100644
--- a/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
+++ b/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmlwebsockets_plugin.h"
@@ -48,8 +12,7 @@ QT_BEGIN_NAMESPACE
void QtWebSocketsDeclarativeModule::registerTypes(const char *uri)
{
- // ### Qt 6: Remove support for the "Qt.WebSockets" QML module.
- Q_ASSERT(uri == QLatin1String("QtWebSockets") || uri == QLatin1String("Qt.WebSockets"));
+ Q_ASSERT(uri == QLatin1String("QtWebSockets"));
// @uri QtWebSockets
qmlRegisterType<QQmlWebSocket>(uri, 1 /*major*/, 0 /*minor*/, "WebSocket");
diff --git a/src/imports/qmlwebsockets/qmlwebsockets_plugin.h b/src/imports/qmlwebsockets/qmlwebsockets_plugin.h
index f84a416..68324f0 100644
--- a/src/imports/qmlwebsockets/qmlwebsockets_plugin.h
+++ b/src/imports/qmlwebsockets/qmlwebsockets_plugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMLWEBSOCKET_PLUGIN_H
#define QMLWEBSOCKET_PLUGIN_H
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.cpp b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
index 826ccc6..51a84cf 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.cpp
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\qmltype WebSocket
@@ -55,7 +19,19 @@
\qmlproperty QUrl WebSocket::url
Server url to connect to. The url must have one of 2 schemes: \e ws:// or \e wss://.
When not supplied, then \e ws:// is used.
- */
+*/
+
+/*!
+ \qmlproperty QStringList WebSocket::requestedSubprotocols
+ \since 6.4
+ The list of WebSocket subprotocols to send in the WebSocket handshake.
+*/
+
+/*!
+ \qmlproperty QString WebSocket::negotiatedSubprotocol
+ \since 6.4
+ The WebSocket subprotocol that has been negotiated with the server.
+*/
/*!
\qmlproperty Status WebSocket::status
@@ -69,33 +45,33 @@
\li WebSocket.Closed
\li WebSocket.Error
\endlist
- */
+*/
/*!
\qmlproperty QString WebSocket::errorString
Contains a description of the last error that occurred. When no error occurrred,
this string is empty.
- */
+*/
/*!
\qmlproperty bool WebSocket::active
When set to true, a connection is made to the server with the given url.
When set to false, the connection is closed.
The default value is false.
- */
+*/
/*!
\qmlsignal WebSocket::textMessageReceived(QString message)
This signal is emitted when a text message is received.
\a message contains the bytes received.
- */
+*/
/*!
\qmlsignal WebSocket::binaryMessageReceived(QString message)
\since 5.8
This signal is emitted when a binary message is received.
\a message contains the bytes received.
- */
+*/
/*!
\qmlsignal WebSocket::statusChanged(Status status)
@@ -103,21 +79,22 @@
The \a status argument provides the current status.
\sa {QtWebSockets::}{WebSocket::status}
- */
+*/
/*!
\qmlmethod void WebSocket::sendTextMessage(string message)
Sends \a message to the server.
- */
+*/
/*!
\qmlmethod void WebSocket::sendBinaryMessage(ArrayBuffer message)
\since 5.8
Sends the parameter \a message to the server.
- */
+*/
#include "qqmlwebsocket.h"
#include <QtWebSockets/QWebSocket>
+#include <QtWebSockets/QWebSocketHandshakeOptions>
QT_BEGIN_NAMESPACE
@@ -136,6 +113,7 @@ QQmlWebSocket::QQmlWebSocket(QWebSocket *socket, QObject *parent) :
QObject(parent),
m_status(Closed),
m_url(socket->requestUrl()),
+ m_requestedProtocols(socket->handshakeOptions().subprotocols()),
m_isActive(true),
m_componentCompleted(true),
m_errorString(socket->errorString())
@@ -168,6 +146,20 @@ qint64 QQmlWebSocket::sendBinaryMessage(const QByteArray &message)
return m_webSocket->sendBinaryMessage(message);
}
+QStringList QQmlWebSocket::requestedSubprotocols() const
+{
+ return m_requestedProtocols;
+}
+
+void QQmlWebSocket::setRequestedSubprotocols(const QStringList &requestedSubprotocols)
+{
+ if (m_requestedProtocols == requestedSubprotocols)
+ return;
+
+ m_requestedProtocols = requestedSubprotocols;
+ emit requestedSubprotocolsChanged();
+}
+
QUrl QQmlWebSocket::url() const
{
return m_url;
@@ -186,6 +178,11 @@ void QQmlWebSocket::setUrl(const QUrl &url)
open();
}
+QString QQmlWebSocket::negotiatedSubprotocol() const
+{
+ return m_negotiatedProtocol;
+}
+
QQmlWebSocket::Status QQmlWebSocket::status() const
{
return m_status;
@@ -217,13 +214,12 @@ void QQmlWebSocket::setSocket(QWebSocket *socket)
m_webSocket.reset(socket);
if (m_webSocket) {
// explicit ownership via QScopedPointer
- m_webSocket->setParent(Q_NULLPTR);
+ m_webSocket->setParent(nullptr);
connect(m_webSocket.data(), &QWebSocket::textMessageReceived,
this, &QQmlWebSocket::textMessageReceived);
connect(m_webSocket.data(), &QWebSocket::binaryMessageReceived,
this, &QQmlWebSocket::binaryMessageReceived);
- typedef void (QWebSocket::* ErrorSignal)(QAbstractSocket::SocketError);
- connect(m_webSocket.data(), static_cast<ErrorSignal>(&QWebSocket::error),
+ connect(m_webSocket.data(), &QWebSocket::errorOccurred,
this, &QQmlWebSocket::onError);
connect(m_webSocket.data(), &QWebSocket::stateChanged,
this, &QQmlWebSocket::onStateChanged);
@@ -281,6 +277,12 @@ void QQmlWebSocket::setStatus(QQmlWebSocket::Status status)
setErrorString();
}
Q_EMIT statusChanged(m_status);
+
+ const auto protocol = m_status == Open && m_webSocket ? m_webSocket->subprotocol() : QString();
+ if (m_negotiatedProtocol != protocol) {
+ m_negotiatedProtocol = protocol;
+ Q_EMIT negotiatedSubprotocolChanged();
+ }
}
void QQmlWebSocket::setActive(bool active)
@@ -308,7 +310,9 @@ bool QQmlWebSocket::isActive() const
void QQmlWebSocket::open()
{
if (m_componentCompleted && m_isActive && m_url.isValid() && Q_LIKELY(m_webSocket)) {
- m_webSocket->open(m_url);
+ QWebSocketHandshakeOptions opt;
+ opt.setSubprotocols(m_requestedProtocols);
+ m_webSocket->open(m_url, opt);
}
}
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.h b/src/imports/qmlwebsockets/qqmlwebsocket.h
index 7662607..e8b1224 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.h
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQMLWEBSOCKET_H
#define QQMLWEBSOCKET_H
@@ -55,9 +19,13 @@ class QQmlWebSocket : public QObject, public QQmlParserStatus
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
+ Q_PROPERTY(QStringList requestedSubprotocols READ requestedSubprotocols
+ WRITE setRequestedSubprotocols NOTIFY requestedSubprotocolsChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ Q_PROPERTY(QString negotiatedSubprotocol READ negotiatedSubprotocol
+ NOTIFY negotiatedSubprotocolChanged)
public:
explicit QQmlWebSocket(QObject *parent = 0);
@@ -76,6 +44,10 @@ public:
QUrl url() const;
void setUrl(const QUrl &url);
+ QStringList requestedSubprotocols() const;
+ void setRequestedSubprotocols(const QStringList &subprotocols);
+
+ QString negotiatedSubprotocol() const;
Status status() const;
QString errorString() const;
@@ -92,6 +64,8 @@ Q_SIGNALS:
void activeChanged(bool isActive);
void errorStringChanged(QString errorString);
void urlChanged();
+ void requestedSubprotocolsChanged();
+ void negotiatedSubprotocolChanged();
public:
void classBegin() override;
@@ -103,8 +77,10 @@ private Q_SLOTS:
private:
QScopedPointer<QWebSocket> m_webSocket;
+ QString m_negotiatedProtocol;
Status m_status;
QUrl m_url;
+ QStringList m_requestedProtocols;
bool m_isActive;
bool m_componentCompleted;
QString m_errorString;
diff --git a/src/imports/qmlwebsockets/qqmlwebsocketserver.cpp b/src/imports/qmlwebsockets/qqmlwebsocketserver.cpp
index 416269c..2e8f4df 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocketserver.cpp
+++ b/src/imports/qmlwebsockets/qqmlwebsocketserver.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSocket module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qqmlwebsocketserver.h"
#include "qqmlwebsocket.h"
@@ -56,29 +20,35 @@ QT_USE_NAMESPACE
\qmlproperty QUrl WebSocketServer::url
Server url that client WebSockets can connect to. The url uses the \e ws:// scheme and includes the
port the server listens to and the host address of the server.
- */
+*/
/*!
\qmlproperty QString WebSocketServer::host
The host address of the server. By default, localhost is used.
- */
+*/
/*!
\qmlproperty int WebSocketServer::port
The port this server is listening on. The value must be in the range 0-65535.
By default, a port is chosen automatically.
- */
+*/
/*!
\qmlproperty QString WebSocketServer::name
The name of this server used during the http handshake phase.
- */
+*/
+
+/*!
+ \qmlproperty QStringList WebSocketServer::supportedSubprotocols
+ \since 6.4
+ The list of protocols supported by the server.
+*/
/*!
\qmlproperty QString WebSocketServer::errorString
The stringified error message in case an error occurred.
- */
+*/
/*!
\qmlproperty bool WebSocketServer::listen
@@ -86,18 +56,18 @@ QT_USE_NAMESPACE
When set to true, the server will listen on the specified url defined by host and port
and, when accept is true, accepts incoming client connections. Otherwise the server is closed.
By default, the server is not listening.
- */
+*/
/*!
\qmlproperty bool WebSocketServer::accept
Set to true to accept incoming client connections when the server is listening. When set to false,
incoming connections are rejected. By default, connections are accepted.
- */
+*/
/*!
\qmlsignal WebSocketServer::clientConnected(WebSocket webSocket)
This signal is emitted when a client connects to this server. \a webSocket is the newly created \l [QML]{WebSocket}.
- */
+*/
QQmlWebSocketServer::QQmlWebSocketServer(QObject *parent)
: QObject(parent)
@@ -200,6 +170,19 @@ void QQmlWebSocketServer::setName(const QString &name)
}
}
+void QQmlWebSocketServer::setSupportedSubprotocols(const QStringList &supportedSubprotocols)
+{
+ if (m_supportedSubprotocols == supportedSubprotocols)
+ return;
+
+ m_supportedSubprotocols = supportedSubprotocols;
+
+ if (m_server)
+ m_server->setSupportedSubprotocols(m_supportedSubprotocols);
+
+ emit supportedSubprotocolsChanged(m_supportedSubprotocols);
+}
+
bool QQmlWebSocketServer::listen() const
{
return m_listen;
@@ -252,6 +235,8 @@ void QQmlWebSocketServer::init()
connect(m_server.data(), &QWebSocketServer::closed,
this, &QQmlWebSocketServer::closed);
+ m_server->setSupportedSubprotocols(m_supportedSubprotocols);
+
updateListening();
}
@@ -287,3 +272,7 @@ void QQmlWebSocketServer::closed()
setListen(false);
}
+QStringList QQmlWebSocketServer::supportedSubprotocols() const
+{
+ return m_supportedSubprotocols;
+}
diff --git a/src/imports/qmlwebsockets/qqmlwebsocketserver.h b/src/imports/qmlwebsockets/qqmlwebsocketserver.h
index 98dbfc4..0bc2028 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocketserver.h
+++ b/src/imports/qmlwebsockets/qqmlwebsocketserver.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSocket module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQMLWEBSOCKETSERVER_H
#define QQMLWEBSOCKETSERVER_H
@@ -57,12 +21,14 @@ class QQmlWebSocketServer : public QObject, public QQmlParserStatus
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(QStringList supportedSubprotocols READ supportedSubprotocols
+ WRITE setSupportedSubprotocols NOTIFY supportedSubprotocolsChanged)
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Q_PROPERTY(bool listen READ listen WRITE setListen NOTIFY listenChanged)
Q_PROPERTY(bool accept READ accept WRITE setAccept NOTIFY acceptChanged)
public:
- explicit QQmlWebSocketServer(QObject *parent = Q_NULLPTR);
+ explicit QQmlWebSocketServer(QObject *parent = nullptr);
~QQmlWebSocketServer() override;
void classBegin() override;
@@ -79,6 +45,9 @@ public:
QString name() const;
void setName(const QString &name);
+ QStringList supportedSubprotocols() const;
+ void setSupportedSubprotocols(const QStringList &supportedSubprotocols);
+
QString errorString() const;
bool listen() const;
@@ -94,6 +63,7 @@ Q_SIGNALS:
void urlChanged(const QUrl &url);
void portChanged(int port);
void nameChanged(const QString &name);
+ void supportedSubprotocolsChanged(const QStringList &supportedProtocols);
void hostChanged(const QString &host);
void listenChanged(bool listen);
void acceptChanged(bool accept);
@@ -108,6 +78,7 @@ private:
QScopedPointer<QWebSocketServer> m_server;
QString m_host;
QString m_name;
+ QStringList m_supportedSubprotocols;
int m_port;
bool m_listen;
bool m_accept;
diff --git a/src/imports/qmlwebsockets_compat/plugins.qmltypes b/src/imports/qmlwebsockets_compat/plugins.qmltypes
deleted file mode 100644
index 961ed1c..0000000
--- a/src/imports/qmlwebsockets_compat/plugins.qmltypes
+++ /dev/null
@@ -1,97 +0,0 @@
-import QtQuick.tooling 1.2
-
-// This file describes the plugin-supplied types contained in the library.
-// It is used for QML tooling purposes only.
-//
-// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable Qt.WebSockets 1.0'
-
-Module {
- dependencies: []
- Component {
- name: "QQmlWebSocket"
- prototype: "QObject"
- exports: ["Qt.WebSockets/WebSocket 1.0"]
- exportMetaObjectRevisions: [0]
- Enum {
- name: "Status"
- values: {
- "Connecting": 0,
- "Open": 1,
- "Closing": 2,
- "Closed": 3,
- "Error": 4
- }
- }
- Property { name: "url"; type: "QUrl" }
- Property { name: "status"; type: "Status"; isReadonly: true }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "active"; type: "bool" }
- Signal {
- name: "textMessageReceived"
- Parameter { name: "message"; type: "string" }
- }
- Signal {
- name: "statusChanged"
- Parameter { name: "status"; type: "Status" }
- }
- Signal {
- name: "activeChanged"
- Parameter { name: "isActive"; type: "bool" }
- }
- Signal {
- name: "errorStringChanged"
- Parameter { name: "errorString"; type: "string" }
- }
- Method {
- name: "sendTextMessage"
- type: "qlonglong"
- Parameter { name: "message"; type: "string" }
- }
- }
- Component {
- name: "QQmlWebSocketServer"
- prototype: "QObject"
- exports: ["Qt.WebSockets/WebSocketServer 1.0"]
- exportMetaObjectRevisions: [0]
- Property { name: "url"; type: "QUrl"; isReadonly: true }
- Property { name: "host"; type: "string" }
- Property { name: "port"; type: "int" }
- Property { name: "name"; type: "string" }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "listen"; type: "bool" }
- Property { name: "accept"; type: "bool" }
- Signal {
- name: "clientConnected"
- Parameter { name: "webSocket"; type: "QQmlWebSocket"; isPointer: true }
- }
- Signal {
- name: "errorStringChanged"
- Parameter { name: "errorString"; type: "string" }
- }
- Signal {
- name: "urlChanged"
- Parameter { name: "url"; type: "QUrl" }
- }
- Signal {
- name: "portChanged"
- Parameter { name: "port"; type: "int" }
- }
- Signal {
- name: "nameChanged"
- Parameter { name: "name"; type: "string" }
- }
- Signal {
- name: "hostChanged"
- Parameter { name: "host"; type: "string" }
- }
- Signal {
- name: "listenChanged"
- Parameter { name: "listen"; type: "bool" }
- }
- Signal {
- name: "acceptChanged"
- Parameter { name: "accept"; type: "bool" }
- }
- }
-}
diff --git a/src/imports/qmlwebsockets_compat/qmldir b/src/imports/qmlwebsockets_compat/qmldir
deleted file mode 100644
index a4310d9..0000000
--- a/src/imports/qmlwebsockets_compat/qmldir
+++ /dev/null
@@ -1,4 +0,0 @@
-module Qt.WebSockets
-plugin declarative_qmlwebsockets ../../QtWebSockets/
-classname QtWebSocketsDeclarativeModule
-typeinfo plugins.qmltypes
diff --git a/src/imports/qmlwebsockets_compat/qmlwebsockets_compat.pro b/src/imports/qmlwebsockets_compat/qmlwebsockets_compat.pro
deleted file mode 100644
index fbdf01c..0000000
--- a/src/imports/qmlwebsockets_compat/qmlwebsockets_compat.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-### Qt 6: Remove support for the old "Qt.WebSockets" QML module.
-
-QT = websockets qml
-
-TARGETPATH = Qt/WebSockets
-
-load(qml_module)
diff --git a/src/src.pro b/src/src.pro
deleted file mode 100644
index ad1b0c7..0000000
--- a/src/src.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-TEMPLATE = subdirs
-CONFIG += ordered
-
-SUBDIRS += websockets
-qtHaveModule(quick): SUBDIRS += imports
diff --git a/src/websockets/CMakeLists.txt b/src/websockets/CMakeLists.txt
index 66a9e2d..df6e2e0 100644
--- a/src/websockets/CMakeLists.txt
+++ b/src/websockets/CMakeLists.txt
@@ -1,10 +1,13 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from websockets.pro.
#####################################################################
## WebSockets Module:
#####################################################################
-qt_add_module(WebSockets
+qt_internal_add_module(WebSockets
SOURCES
qdefaultmaskgenerator_p.cpp qdefaultmaskgenerator_p.h
qmaskgenerator.cpp qmaskgenerator.h
@@ -12,6 +15,7 @@ qt_add_module(WebSockets
qwebsocketcorsauthenticator.cpp qwebsocketcorsauthenticator.h qwebsocketcorsauthenticator_p.h
qwebsocketdataprocessor.cpp qwebsocketdataprocessor_p.h
qwebsocketframe.cpp qwebsocketframe_p.h
+ qwebsockethandshakeoptions.cpp qwebsockethandshakeoptions.h qwebsockethandshakeoptions_p.h
qwebsockethandshakerequest.cpp qwebsockethandshakerequest_p.h
qwebsockethandshakeresponse.cpp qwebsockethandshakeresponse_p.h
qwebsocketprotocol.cpp qwebsocketprotocol.h qwebsocketprotocol_p.h
@@ -19,11 +23,13 @@ qt_add_module(WebSockets
qwebsocketserver.cpp qwebsocketserver.h qwebsocketserver_p.cpp qwebsocketserver_p.h
LIBRARIES
Qt::CorePrivate
+ Qt::NetworkPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Network
PRIVATE_MODULE_INTERFACE
Qt::CorePrivate
+ GENERATE_CPP_EXPORTS
)
#### Keys ignored in scope 1:.:.:websockets.pro:<TRUE>:
@@ -32,19 +38,14 @@ qt_add_module(WebSockets
## Scopes:
#####################################################################
-qt_extend_target(WebSockets CONDITION WASM
+qt_internal_extend_target(WebSockets CONDITION WASM
SOURCES
qwebsocket_wasm_p.cpp
+ LIBRARIES
+ websocket.js
)
-qt_extend_target(WebSockets CONDITION QT_FEATURE_ssl
- SOURCES
- qsslserver.cpp
-)
-
-#### Keys ignored in scope 3:.:.:websockets.pro:QT_FEATURE_ssl:
-# PRIVATE_HEADERS = "qsslserver_p.h"
-qt_add_docs(WebSockets
+qt_internal_add_docs(WebSockets
doc/qtwebsockets.qdocconf
)
diff --git a/src/websockets/doc/qtwebsockets.qdocconf b/src/websockets/doc/qtwebsockets.qdocconf
index 56d54a2..d386eeb 100644
--- a/src/websockets/doc/qtwebsockets.qdocconf
+++ b/src/websockets/doc/qtwebsockets.qdocconf
@@ -15,30 +15,26 @@ qhp.QtWebSockets.virtualFolder = qtwebsockets
qhp.QtWebSockets.indexTitle = Qt WebSockets
qhp.QtWebSockets.indexRoot =
-qhp.QtWebSockets.filterAttributes = qtwebsockets $QT_VERSION qtrefdoc
-qhp.QtWebSockets.customFilters.Qt.name = QtWebSockets $QT_VERSION
-qhp.QtWebSockets.customFilters.Qt.filterAttributes = qtwebsockets $QT_VERSION
-
qhp.QtWebSockets.subprojects = classes qml examples
qhp.QtWebSockets.subprojects.classes.title = C++ Classes
qhp.QtWebSockets.subprojects.classes.indexTitle = Qt WebSockets C++ Classes
-qhp.QtWebSockets.subprojects.classes.selectors = class fake:headerfile
+qhp.QtWebSockets.subprojects.classes.selectors = class headerfile
qhp.QtWebSockets.subprojects.classes.sortPages = true
qhp.QtWebSockets.subprojects.qml.title = QML Types
qhp.QtWebSockets.subprojects.qml.indexTitle = Qt WebSockets QML Types
-qhp.QtWebSockets.subprojects.qml.selectors = qmlclass
+qhp.QtWebSockets.subprojects.qml.selectors = qmltype
qhp.QtWebSockets.subprojects.qml.sortPages = true
qhp.QtWebSockets.subprojects.examples.title = Examples
qhp.QtWebSockets.subprojects.examples.indexTitle = Qt WebSockets Examples
-qhp.QtWebSockets.subprojects.examples.selectors = fake:example
+qhp.QtWebSockets.subprojects.examples.selectors = doc:example
qhp.QtWebSockets.subprojects.examples.sortPages = true
tagfile = ../../../doc/qtwebsockets/qtwebsockets.tags
-depends += qtcore qtnetwork qtdoc qmake
+depends += qtcore qtnetwork qtdoc qmake qtcmake
headerdirs += .. \
../../imports
@@ -66,3 +62,6 @@ manifestmeta.thumbnail.names += "QtWebSockets/Echo Client
navigation.landingpage = "Qt WebSockets"
navigation.cppclassespage = "Qt WebSockets C++ Classes"
navigation.qmltypespage = "Qt WebSockets QML Types"
+
+# Enforce zero warnings for documentation build
+warninglimit = 0
diff --git a/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp b/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp
index 78874a3..3940d6a 100644
--- a/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp
+++ b/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [6]
QList<QSslCertificate> cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem"));
QSslError error(QSslError::SelfSignedCertificate, cert.at(0));
diff --git a/src/websockets/doc/src/external-resources.qdoc b/src/websockets/doc/src/external-resources.qdoc
index 1363d24..f9d0c50 100644
--- a/src/websockets/doc/src/external-resources.qdoc
+++ b/src/websockets/doc/src/external-resources.qdoc
@@ -1,82 +1,58 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \externalpage http://w2spconf.com/2011/papers/websocket.pdf
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \externalpage https://www.ieee-security.org/TC/W2SP/2011/papers/websocket.pdf
\title "Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al
*/
/*!
- \externalpage http://tools.ietf.org/html/rfc6454
+ \externalpage https://datatracker.ietf.org/doc/html/rfc6454
\title RFC 6454
*/
/*!
- \externalpage http://tools.ietf.org/html/rfc6455
+ \externalpage https://datatracker.ietf.org/doc/html/rfc6455
\title RFC 6455
*/
/*!
- \externalpage http://tools.ietf.org/html/rfc6455#section-10
+ \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-10
\title WebSocket Security Considerations
*/
/*!
- \externalpage http://tools.ietf.org/html/rfc6455#page-39
+ \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-9
\title WebSocket Extensions
*/
/*!
- \externalpage http://tools.ietf.org/html/rfc6455#page-12
+ \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-1.9
\title WebSocket Subprotocols
*/
/*!
- \externalpage http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
+ \externalpage https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76
\title hixie76
*/
/*!
- \externalpage http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00
+ \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-00
\title hybi-00
*/
/*!
- \externalpage http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-04.txt
+ \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-04
\title hybi-04
*/
/*!
- \externalpage http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-05.txt
+ \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-05
\title hybi-05
*/
/*!
- \externalpage http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07
+ \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-07
\title hybi-07
*/
diff --git a/src/websockets/doc/src/index.qdoc b/src/websockets/doc/src/index.qdoc
index 81a2cb4..e3fce1e 100644
--- a/src/websockets/doc/src/index.qdoc
+++ b/src/websockets/doc/src/index.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtwebsockets-index.html
@@ -31,61 +7,61 @@
\title Qt WebSockets
\brief Provides an implementation of the WebSocket protocol.
- WebSocket is a web-based protocol designed to enable two-way communication
- between a client application and a remote host. It enables the two entities
- to send data back and forth if the initial handshake succeeds. WebSocket is
- the solution for applications that struggle to get real-time data feeds
- with less network latency and minimum data exchange.
+ WebSocket is a web-based protocol designed to enable a two-way interactive
+ communication session between a client application and a remote host. It
+ enables the two entities to send data back and forth if the initial
+ handshake succeeds.
The Qt WebSockets module provides C++ and QML interfaces that enable
Qt applications to act as a server that can process WebSocket requests,
or a client that can consume data received from the server, or both.
- \section1 Getting Started
+ \section1 Using the Module
- To include the definitions of the module's classes, use the following directive:
+ \section2 QML API
- \code
- #include <QtWebSockets/QtWebSockets>
- \endcode
+ \include {module-use.qdocinc} {using the qml api} {QtWebSockets}
- To import the QML types into your application, use the following import statement in your .qml file:
+ \section2 C++ API
- \qml \QtMinorVersion
- import QtWebSockets 1.\1
- \endqml
+ \include {module-use.qdocinc} {using the c++ api}
- To link against the module, add this line to your qmake .pro file:
+ \section3 Building with CMake
- \code
- QT += websockets
- \endcode
+ \include {module-use.qdocinc} {building with cmake} {WebSockets}
- \section1 Licenses
+ \section3 Building with qmake
- Qt WebSockets is available under commercial licenses from \l{The Qt Company}.
- In addition, it is available under free software licenses. Since Qt 5.4,
- these free software licenses are
- \l{GNU Lesser General Public License, version 3}, or
- the \l{GNU General Public License, version 2}.
- See \l{Qt Licensing} for further details.
+ \include {module-use.qdocinc} {building_with_qmake} {websockets}
+
+ \section1 Examples
- \section1 Reference Documentation
\list
- \li \l{Qt WebSockets Overview}{Overview}
- \li \l{Qt WebSockets C++ Classes}{C++ Classes}
- \li \l{Qt WebSockets QML Types}{QML Types}
+ \li \l {Qt WebSockets Examples}
\endlist
- \section1 Examples
+ \section1 Reference
- The module provides the following \l{Qt WebSockets Examples}{Examples} as a guide to using
- the API.
+ \list
+ \li \l {Qt WebSockets Overview} {Overview}
+ \li \l {Qt WebSockets C++ Classes} {C++ Classes}
+ \li \l {Qt WebSockets QML Types} {QML Types}
+ \endlist
\section1 Conformance
+
\list
- \li \l {Testing Qt WebSockets}
+ \li \l {Testing Qt WebSockets}
\endlist
+
+ \section1 Licenses
+
+ Qt WebSockets is available under commercial licenses from \l{The Qt Company}.
+ In addition, it is available under free software licenses. Since Qt 5.4,
+ these free software licenses are
+ \l{GNU Lesser General Public License, version 3}, or
+ the \l{GNU General Public License, version 2}.
+ See \l{Qt Licensing} for further details.
*/
/*!
@@ -98,5 +74,5 @@
\l {Autobahn|Testsuite installation documentation}
to set up the test suite.
- \include README testsuite
+ \include README.qdocinc testsuite
*/
diff --git a/src/websockets/doc/src/overview.qdoc b/src/websockets/doc/src/overview.qdoc
index 48a790f..398dbe1 100644
--- a/src/websockets/doc/src/overview.qdoc
+++ b/src/websockets/doc/src/overview.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page websockets-overview.html
diff --git a/src/websockets/doc/src/qt6-changes.qdoc b/src/websockets/doc/src/qt6-changes.qdoc
new file mode 100644
index 0000000..d514a9b
--- /dev/null
+++ b/src/websockets/doc/src/qt6-changes.qdoc
@@ -0,0 +1,32 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtwebsockets-changes-qt6.html
+ \title Changes to Qt WebSockets
+ \ingroup changes-qt-5-to-6
+ \brief Migrate Qt WebSockets to Qt 6.
+
+ Qt 6 is a result of the conscious effort to make the framework more
+ efficient and easy to use.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+ In this topic we summarize those changes in Qt WebSockets, and provide guidance
+ to handle them.
+
+ \section1 Breaking public API changes
+
+ This section contains information about API changes that break source
+ compatibility.
+
+ \section2 QWebSocketServer::socketDescriptor(), QWebSocketServer::setSocketDescriptor()
+
+ In Qt 6, you should use QWebSocketServer::socketDescriptor() and QWebSocketServer::setSocketDescriptor()
+ to access the underlying socket descriptor of type \c{qintptr}. They mirror QTcpServer::socketDescriptor()
+ and QTcpServer::setSocketDescriptor(), and replace the now deprecated nativeDescriptor() and
+ setNativeDescriptor() methods.
+
+*/
diff --git a/src/websockets/doc/src/qtwebsockets-module.qdoc b/src/websockets/doc/src/qtwebsockets-module.qdoc
index 2761ea5..f1d9ff7 100644
--- a/src/websockets/doc/src/qtwebsockets-module.qdoc
+++ b/src/websockets/doc/src/qtwebsockets-module.qdoc
@@ -1,34 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtWebSockets
\title Qt WebSockets C++ Classes
\ingroup modules
- \qtcmakepackage Websockets
+ \qtcmakepackage WebSockets
\qtvariable websockets
\since 5.3
\brief List of C++ classes that enable WebSocket-based communication.
diff --git a/src/websockets/qdefaultmaskgenerator_p.cpp b/src/websockets/qdefaultmaskgenerator_p.cpp
index 7763868..78bad0d 100644
--- a/src/websockets/qdefaultmaskgenerator_p.cpp
+++ b/src/websockets/qdefaultmaskgenerator_p.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QDefaultMaskGenerator
@@ -84,7 +48,7 @@ QDefaultMaskGenerator::~QDefaultMaskGenerator()
/*!
\internal
*/
-bool QDefaultMaskGenerator::seed() Q_DECL_NOEXCEPT
+bool QDefaultMaskGenerator::seed() noexcept
{
return true;
}
@@ -94,7 +58,7 @@ bool QDefaultMaskGenerator::seed() Q_DECL_NOEXCEPT
\internal
*/
-quint32 QDefaultMaskGenerator::nextMask() Q_DECL_NOEXCEPT
+quint32 QDefaultMaskGenerator::nextMask() noexcept
{
quint32 value = QRandomGenerator::global()->generate();
while (Q_UNLIKELY(value == 0)) {
diff --git a/src/websockets/qdefaultmaskgenerator_p.h b/src/websockets/qdefaultmaskgenerator_p.h
index 3ad4990..0176828 100644
--- a/src/websockets/qdefaultmaskgenerator_p.h
+++ b/src/websockets/qdefaultmaskgenerator_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDEFAULTMASKGENERATOR_P_H
#define QDEFAULTMASKGENERATOR_P_H
@@ -52,6 +16,7 @@
//
#include <QtWebSockets/qmaskgenerator.h>
+#include <QtCore/private/qglobal_p.h>
QT_BEGIN_NAMESPACE
class QObject;
@@ -64,8 +29,8 @@ public:
explicit QDefaultMaskGenerator(QObject *parent = nullptr);
~QDefaultMaskGenerator() override;
- bool seed() Q_DECL_NOEXCEPT override;
- quint32 nextMask() Q_DECL_NOEXCEPT override;
+ bool seed() noexcept override;
+ quint32 nextMask() noexcept override;
};
QT_END_NAMESPACE
diff --git a/src/websockets/qmaskgenerator.cpp b/src/websockets/qmaskgenerator.cpp
index 40f8594..1e927f9 100644
--- a/src/websockets/qmaskgenerator.cpp
+++ b/src/websockets/qmaskgenerator.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QMaskGenerator
diff --git a/src/websockets/qmaskgenerator.h b/src/websockets/qmaskgenerator.h
index 419daca..b2ff48a 100644
--- a/src/websockets/qmaskgenerator.h
+++ b/src/websockets/qmaskgenerator.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMASKGENERATOR_H
#define QMASKGENERATOR_H
diff --git a/src/websockets/qsslserver.cpp b/src/websockets/qsslserver.cpp
deleted file mode 100644
index ed4e4c0..0000000
--- a/src/websockets/qsslserver.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \class QSslServer
-
- \inmodule QtWebSockets
-
- \brief Implements a secure TCP server over SSL.
-
- \internal
-*/
-
-#include "qsslserver_p.h"
-
-#include <QtNetwork/QSslSocket>
-#include <QtNetwork/QSslCipher>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- Constructs a new QSslServer with the given \a parent.
-
- \internal
-*/
-QSslServer::QSslServer(QObject *parent) :
- QTcpServer(parent),
- m_sslConfiguration(QSslConfiguration::defaultConfiguration())
-{
-}
-
-/*!
- Destroys the QSslServer.
-
- All open connections are closed.
-
- \internal
-*/
-QSslServer::~QSslServer()
-{
-}
-
-/*!
- Sets the \a sslConfiguration to use.
-
- \sa QSslSocket::setSslConfiguration()
-
- \internal
-*/
-void QSslServer::setSslConfiguration(const QSslConfiguration &sslConfiguration)
-{
- m_sslConfiguration = sslConfiguration;
-}
-
-/*!
- Returns the current ssl configuration.
-
- \internal
-*/
-QSslConfiguration QSslServer::sslConfiguration() const
-{
- return m_sslConfiguration;
-}
-
-/*!
- Called when a new connection is established.
-
- Converts \a socket to a QSslSocket.
-
- \internal
-*/
-void QSslServer::incomingConnection(qintptr socket)
-{
- QSslSocket *pSslSocket = new QSslSocket(this);
-
- if (Q_LIKELY(pSslSocket)) {
- pSslSocket->setSslConfiguration(m_sslConfiguration);
-
- if (Q_LIKELY(pSslSocket->setSocketDescriptor(socket))) {
- connect(pSslSocket, &QSslSocket::peerVerifyError, this, &QSslServer::peerVerifyError);
-
- connect(pSslSocket, QOverload<const QList<QSslError>&>::of(&QSslSocket::sslErrors),
- this, &QSslServer::sslErrors);
- connect(pSslSocket, &QSslSocket::encrypted,
- this, &QSslServer::socketEncrypted);
- connect(pSslSocket, &QSslSocket::preSharedKeyAuthenticationRequired,
- this, &QSslServer::preSharedKeyAuthenticationRequired);
- connect(pSslSocket, &QSslSocket::alertSent,
- this, &QSslServer::alertSent);
- connect(pSslSocket, &QSslSocket::alertReceived,
- this, &QSslServer::alertReceived);
- connect(pSslSocket, &QSslSocket::handshakeInterruptedOnError,
- this, &QSslServer::handshakeInterruptedOnError);
-
- Q_EMIT startedEncryptionHandshake(pSslSocket);
-
- pSslSocket->startServerEncryption();
- } else {
- delete pSslSocket;
- }
- }
-}
-
-void QSslServer::socketEncrypted()
-{
- QSslSocket *pSslSocket = qobject_cast<QSslSocket *>(sender());
-
- // We do not add the connection until the encryption handshake is complete.
- // In case the handshake is aborted, we would be left with a stale
- // connection in the queue otherwise.
- addPendingConnection(pSslSocket);
- Q_EMIT newEncryptedConnection();
-}
-
-QT_END_NAMESPACE
diff --git a/src/websockets/qsslserver_p.h b/src/websockets/qsslserver_p.h
deleted file mode 100644
index 4f1683a..0000000
--- a/src/websockets/qsslserver_p.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSSLSERVER_P_H
-#define QSSLSERVER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtNetwork/QTcpServer>
-#include <QtNetwork/QSslError>
-#include <QtNetwork/QSslConfiguration>
-#include <QtNetwork/QSslPreSharedKeyAuthenticator>
-#include <QtCore/QList>
-
-QT_BEGIN_NAMESPACE
-
-class QSslSocket;
-
-class QSslServer : public QTcpServer
-{
- Q_OBJECT
- Q_DISABLE_COPY(QSslServer)
-
-public:
- explicit QSslServer(QObject *parent = nullptr);
- ~QSslServer() override;
-
- void setSslConfiguration(const QSslConfiguration &sslConfiguration);
- QSslConfiguration sslConfiguration() const;
-
-Q_SIGNALS:
- void sslErrors(const QList<QSslError> &errors);
- void peerVerifyError(const QSslError &error);
- void newEncryptedConnection();
- void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
- void alertSent(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description);
- void alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description);
- void handshakeInterruptedOnError(const QSslError &error);
- void startedEncryptionHandshake(QSslSocket *socket);
-
-protected:
- void incomingConnection(qintptr socket) override;
-
-private slots:
- void socketEncrypted();
-
-private:
- QSslConfiguration m_sslConfiguration;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSSLSERVER_P_H
diff --git a/src/websockets/qwebsocket.cpp b/src/websockets/qwebsocket.cpp
index 8381047..b495ffd 100644
--- a/src/websockets/qwebsocket.cpp
+++ b/src/websockets/qwebsocket.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QWebSocket
@@ -52,9 +16,7 @@
This class was modeled after QAbstractSocket.
- QWebSocket currently does not support
- \l {WebSocket Extensions} and
- \l {WebSocket Subprotocols}.
+ QWebSocket currently does not support \l {WebSocket Extensions}.
QWebSocket only supports version 13 of the WebSocket protocol, as outlined in
\l {RFC 6455}.
@@ -78,7 +40,7 @@
*/
/*!
- \page echoclient.html example
+ \page echoclient.html
\title QWebSocket client example
\brief A sample WebSocket client that sends a message and displays the message that
it receives back.
@@ -136,6 +98,27 @@ not been filled in with new information when the signal returns.
\sa QAuthenticator, QNetworkProxy
*/
+
+/*!
+ \fn void QWebSocket::authenticationRequired(QAuthenticator *authenticator)
+ \since 6.6
+
+ This signal is emitted when the server requires authentication.
+ The \a authenticator object must then be filled in with the required details
+ to allow authentication and continue the connection.
+
+ If you know that the server may require authentication, you can set the
+ username and password on the initial QUrl, using QUrl::setUserName and
+ QUrl::setPassword. QWebSocket will still try to connect \e{once} without
+ using the provided credentials.
+
+ \note It is not possible to use a QueuedConnection to connect to
+ this signal, as the connection will fail if the authenticator has
+ not been filled in with new information when the signal returns.
+
+ \sa QAuthenticator
+*/
+
/*!
\fn void QWebSocket::stateChanged(QAbstractSocket::SocketState state);
@@ -210,18 +193,6 @@ not been filled in with new information when the signal returns.
\sa textMessageReceived()
*/
/*!
- \fn void QWebSocket::error(QAbstractSocket::SocketError error);
-
- This signal is emitted after an error occurred. The \a error
- parameter describes the type of error that occurred.
-
- QAbstractSocket::SocketError is not a registered metatype, so for queued
- connections, you will have to register it with Q_DECLARE_METATYPE() and
- qRegisterMetaType().
-
- \sa error(), errorString()
-*/
-/*!
\fn void QWebSocket::sslErrors(const QList<QSslError> &errors)
QWebSocket emits this signal after the SSL handshake to indicate that one or more errors have
occurred while establishing the identity of the peer.
@@ -262,7 +233,7 @@ not been filled in with new information when the signal returns.
*/
/*!
\fn void QWebSocket::peerVerifyError(const QSslError &error)
- \since 6.0
+ \since 6.2
QWebSocket can emit this signal several times during the SSL handshake,
before encryption has been established, to indicate that an error has
@@ -280,7 +251,7 @@ not been filled in with new information when the signal returns.
*/
/*!
\fn void QWebSocket::alertSent(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
- \since 6.0
+ \since 6.2
QWebSocket emits this signal if an alert message was sent to a peer. \a level
describes if it was a warning or a fatal error. \a type gives the code
@@ -295,7 +266,7 @@ not been filled in with new information when the signal returns.
*/
/*!
\fn void QWebSocket::alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
- \since 6.0
+ \since 6.2
QWebSocket emits this signal if an alert message was received from a peer.
\a level tells if the alert was fatal or it was a warning. \a type is the
@@ -311,7 +282,7 @@ not been filled in with new information when the signal returns.
*/
/*!
\fn void QWebSocket::handshakeInterruptedOnError(const QSslError &error)
- \since 6.0
+ \since 6.2
QWebSocket emits this signal if a certificate verification error was
found and if early error reporting was enabled in QSslConfiguration.
@@ -332,6 +303,7 @@ not been filled in with new information when the signal returns.
*/
#include "qwebsocket.h"
#include "qwebsocket_p.h"
+#include "qwebsockethandshakeoptions.h"
#include <QtCore/QUrl>
#include <QtNetwork/QTcpSocket>
@@ -484,7 +456,7 @@ void QWebSocket::open(const QUrl &url)
{
Q_D(QWebSocket);
QNetworkRequest request(url);
- d->open(request, true);
+ d->open(request, QWebSocketHandshakeOptions{}, true);
}
/*!
@@ -498,7 +470,41 @@ void QWebSocket::open(const QUrl &url)
void QWebSocket::open(const QNetworkRequest &request)
{
Q_D(QWebSocket);
- d->open(request, true);
+ d->open(request, QWebSocketHandshakeOptions{}, true);
+}
+
+/*!
+ \brief Opens a WebSocket connection using the given \a url and \a options.
+ \since 6.4
+
+ If the url contains newline characters (\\r\\n), then the error signal will be emitted
+ with QAbstractSocket::ConnectionRefusedError as error type.
+
+ Additional options for the WebSocket handshake such as subprotocols can be specified in
+ \a options.
+ */
+void QWebSocket::open(const QUrl &url, const QWebSocketHandshakeOptions &options)
+{
+ Q_D(QWebSocket);
+ QNetworkRequest request(url);
+ d->open(request, options, true);
+}
+
+/*!
+ \brief Opens a WebSocket connection using the given \a request and \a options.
+ \since 6.4
+
+ The \a request url will be used to open the WebSocket connection.
+ Headers present in the request will be sent to the server in the upgrade request,
+ together with the ones needed for the websocket handshake.
+
+ Additional options for the WebSocket handshake such as subprotocols can be specified in
+ \a options.
+ */
+void QWebSocket::open(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options)
+{
+ Q_D(QWebSocket);
+ d->open(request, options, true);
}
/*!
@@ -508,6 +514,9 @@ void QWebSocket::open(const QNetworkRequest &request)
The size of the \a payload cannot be bigger than 125.
If it is larger, the \a payload is clipped to 125 bytes.
+ \note QWebSocket and QWebSocketServer handles ping requests internally,
+ which means they automatically send back a pong response to the peer.
+
\sa pong()
*/
void QWebSocket::ping(const QByteArray &payload)
@@ -544,7 +553,7 @@ void QWebSocket::ignoreSslErrors()
}
/*!
- \since 6.0
+ \since 6.2
If an application wants to conclude a handshake even after receiving
handshakeInterruptedOnError() signal, it must call this function.
@@ -651,6 +660,16 @@ QNetworkRequest QWebSocket::request() const
}
/*!
+ \brief Returns the handshake options that were used to open this socket.
+ \since 6.4
+ */
+QWebSocketHandshakeOptions QWebSocket::handshakeOptions() const
+{
+ Q_D(const QWebSocket);
+ return d->handshakeOptions();
+}
+
+/*!
\brief Returns the current origin.
*/
QString QWebSocket::origin() const
@@ -660,6 +679,16 @@ QString QWebSocket::origin() const
}
/*!
+ \brief Returns the used WebSocket protocol.
+ \since 6.4
+ */
+QString QWebSocket::subprotocol() const
+{
+ Q_D(const QWebSocket);
+ return d->protocol();
+}
+
+/*!
\brief Returns the code indicating why the socket was closed.
\sa QWebSocketProtocol::CloseCode, closeReason()
*/
@@ -976,4 +1005,25 @@ quint64 QWebSocket::maxOutgoingFrameSize()
return QWebSocketPrivate::maxOutgoingFrameSize();
}
+/*!
+ \fn void QWebSocket::errorOccurred(QAbstractSocket::SocketError error);
+
+ \since 6.5
+ \brief This signal is emitted after an error occurred.
+
+ The \a error parameter describes the type of error that occurred.
+
+ QAbstractSocket::SocketError is not a registered metatype, so for queued
+ connections, you will have to register it with Q_DECLARE_METATYPE() and
+ qRegisterMetaType().
+
+ \sa error(), errorString()
+*/
+#if QT_DEPRECATED_SINCE(6, 5)
+/*!
+ \fn void QWebSocket::error(QAbstractSocket::SocketError error);
+ \deprecated [6.5] Use errorOccurred(QAbstractSocket::SocketError error) instead.
+*/
+#endif
+
QT_END_NAMESPACE
diff --git a/src/websockets/qwebsocket.h b/src/websockets/qwebsocket.h
index 18e8019..bf9e393 100644
--- a/src/websockets/qwebsocket.h
+++ b/src/websockets/qwebsocket.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKET_H
#define QWEBSOCKET_H
@@ -58,6 +22,7 @@ QT_BEGIN_NAMESPACE
class QTcpSocket;
class QWebSocketPrivate;
class QMaskGenerator;
+class QWebSocketHandshakeOptions;
class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject
{
@@ -100,7 +65,9 @@ public:
QString resourceName() const;
QUrl requestUrl() const;
QNetworkRequest request() const;
+ QWebSocketHandshakeOptions handshakeOptions() const;
QString origin() const;
+ QString subprotocol() const;
QWebSocketProtocol::CloseCode closeCode() const;
QString closeReason() const;
@@ -131,8 +98,13 @@ public:
public Q_SLOTS:
void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CloseCodeNormal,
const QString &reason = QString());
+
+ // ### Qt7: Merge overloads
void open(const QUrl &url);
void open(const QNetworkRequest &request);
+ void open(const QUrl &url, const QWebSocketHandshakeOptions &options);
+ void open(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options);
+
void ping(const QByteArray &payload = QByteArray());
#ifndef QT_NO_SSL
void ignoreSslErrors();
@@ -146,12 +118,17 @@ Q_SIGNALS:
#ifndef QT_NO_NETWORKPROXY
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
#endif
+ void authenticationRequired(QAuthenticator *authenticator);
void readChannelFinished();
void textFrameReceived(const QString &frame, bool isLastFrame);
void binaryFrameReceived(const QByteArray &frame, bool isLastFrame);
void textMessageReceived(const QString &message);
void binaryMessageReceived(const QByteArray &message);
+#if QT_DEPRECATED_SINCE(6, 5)
+ QT_DEPRECATED_VERSION_X_6_5("Use errorOccurred instead")
void error(QAbstractSocket::SocketError error);
+#endif
+ void errorOccurred(QAbstractSocket::SocketError error);
void pong(quint64 elapsedTime, const QByteArray &payload);
void bytesWritten(qint64 bytes);
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index cad6506..2f1f534 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsocket.h"
#include "qwebsocket_p.h"
@@ -63,14 +27,58 @@
#include <QtNetwork/QSslPreSharedKeyAuthenticator>
#endif
+#include <QtNetwork/private/qhttpheaderparser_p.h>
+#include <QtNetwork/private/qauthenticator_p.h>
+
#include <QtCore/QDebug>
#include <limits>
+#include <memory>
QT_BEGIN_NAMESPACE
-const quint64 MAX_OUTGOING_FRAME_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
-const quint64 DEFAULT_OUTGOING_FRAME_SIZE_IN_BYTES = 512 * 512 * 2; //default size of a frame when sending a message
+using namespace Qt::StringLiterals;
+
+namespace {
+
+constexpr quint64 MAX_OUTGOING_FRAME_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
+constexpr quint64 DEFAULT_OUTGOING_FRAME_SIZE_IN_BYTES = 512 * 512 * 2; // default size of a frame when sending a message
+
+// Based on isSeperator() from qtbase/src/network/access/qhsts.cpp
+// https://datatracker.ietf.org/doc/html/rfc2616#section-2.2:
+//
+// separators = "(" | ")" | "<" | ">" | "@"
+// | "," | ";" | ":" | "\" | <">
+// | "/" | "[" | "]" | "?" | "="
+// | "{" | "}" | SP | HT
+// TODO: Should probably make things like this re-usable as private API of QtNetwork
+bool isSeparator(char c)
+{
+ // separators = "(" | ")" | "<" | ">" | "@"
+ // | "," | ";" | ":" | "\" | <">
+ // | "/" | "[" | "]" | "?" | "="
+ // | "{" | "}" | SP | HT
+ static const char separators[] = "()<>@,;:\\\"/[]?={} \t";
+ static const char *end = separators + sizeof separators - 1;
+ return std::find(separators, end, c) != end;
+}
+
+// https://datatracker.ietf.org/doc/html/rfc6455#section-4.1:
+// 10. The request MAY include a header field with the name
+// |Sec-WebSocket-Protocol|. If present, this value indicates one
+// or more comma-separated subprotocol the client wishes to speak,
+// ordered by preference. The elements that comprise this value
+// MUST be non-empty strings with characters in the range U+0021 to
+// U+007E not including separator characters as defined in
+// [RFC2616] and MUST all be unique strings.
+bool isValidSubProtocolName(const QString &protocol)
+{
+ return std::all_of(protocol.begin(), protocol.end(), [](const QChar &c) {
+ return c.unicode() >= 0x21 && c.unicode() <= 0x7E && !isSeparator(c.toLatin1());
+ });
+}
+
+}
QWebSocketConfiguration::QWebSocketConfiguration() :
#ifndef QT_NO_SSL
@@ -111,7 +119,6 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
m_configuration(),
m_pMaskGenerator(&m_defaultMaskGenerator),
m_defaultMaskGenerator(),
- m_handshakeState(NothingDoneState),
m_outgoingFrameSize(DEFAULT_OUTGOING_FRAME_SIZE_IN_BYTES)
{
m_pingTimer.start();
@@ -143,7 +150,6 @@ QWebSocketPrivate::QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol:
m_configuration(),
m_pMaskGenerator(&m_defaultMaskGenerator),
m_defaultMaskGenerator(),
- m_handshakeState(NothingDoneState),
m_outgoingFrameSize(DEFAULT_OUTGOING_FRAME_SIZE_IN_BYTES)
{
m_pingTimer.start();
@@ -170,6 +176,16 @@ void QWebSocketPrivate::init()
*/
QWebSocketPrivate::~QWebSocketPrivate()
{
+#ifdef Q_OS_WASM
+ if (m_socketContext) {
+ uint16_t m_readyState;
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+ if (m_readyState == 1 || m_readyState == 0) {
+ emscripten_websocket_close(m_socketContext, 1000,"");
+ }
+ emscripten_websocket_delete(m_socketContext);
+ }
+#endif
}
/*!
@@ -271,6 +287,11 @@ QSslConfiguration QWebSocketPrivate::sslConfiguration() const
void QWebSocketPrivate::ignoreSslErrors(const QList<QSslError> &errors)
{
m_configuration.m_ignoredSslErrors = errors;
+ if (Q_LIKELY(m_pSocket)) {
+ QSslSocket *pSslSocket = qobject_cast<QSslSocket *>(m_pSocket);
+ if (Q_LIKELY(pSslSocket))
+ pSslSocket->ignoreSslErrors(errors);
+ }
}
/*!
@@ -309,6 +330,24 @@ void QWebSocketPrivate::_q_updateSslConfiguration()
#endif
+QStringList QWebSocketPrivate::requestedSubProtocols() const
+{
+ auto subprotocolsRequestedInRawHeader = [this]() {
+ QStringList protocols;
+ QByteArray rawProtocols = m_request.rawHeader("Sec-WebSocket-Protocol");
+ QLatin1StringView rawProtocolsView(rawProtocols);
+ const QStringList &optionsProtocols = m_options.subprotocols();
+ for (auto &&entry : rawProtocolsView.tokenize(u',', Qt::SkipEmptyParts)) {
+ if (QLatin1StringView trimmed = entry.trimmed(); !trimmed.isEmpty()) {
+ if (!optionsProtocols.contains(trimmed))
+ protocols << trimmed;
+ }
+ }
+ return protocols;
+ };
+ return m_options.subprotocols() + subprotocolsRequestedInRawHeader();
+}
+
/*!
Called from QWebSocketServer
\internal
@@ -323,14 +362,17 @@ QWebSocket *QWebSocketPrivate::upgradeFrom(QTcpSocket *pTcpSocket,
QNetworkRequest netRequest(request.requestUrl());
const auto headers = request.headers();
for (auto it = headers.begin(), end = headers.end(); it != end; ++it)
- netRequest.setRawHeader(it.key().toLatin1(), it.value().toLatin1());
+ netRequest.setRawHeader(it->first, it->second);
#ifndef QT_NO_SSL
if (QSslSocket *sslSock = qobject_cast<QSslSocket *>(pTcpSocket))
pWebSocket->setSslConfiguration(sslSock->sslConfiguration());
#endif
+ QWebSocketHandshakeOptions options;
+ options.setSubprotocols(request.protocols());
+
pWebSocket->d_func()->setExtension(response.acceptedExtension());
pWebSocket->d_func()->setOrigin(request.origin());
- pWebSocket->d_func()->setRequest(netRequest);
+ pWebSocket->d_func()->setRequest(netRequest, options);
pWebSocket->d_func()->setProtocol(response.acceptedProtocol());
pWebSocket->d_func()->setResourceName(request.requestUrl().toString(QUrl::RemoveUserInfo));
//a server should not send masked frames
@@ -368,7 +410,7 @@ void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString r
QByteArray frame = getFrameHeader(QWebSocketProtocol::OpCodeClose,
quint64(payload.size()), maskingKey, true);
- Q_ASSERT(payload.length() <= 125);
+ Q_ASSERT(payload.size() <= 125);
frame.append(payload);
m_pSocket->write(frame);
m_pSocket->flush();
@@ -383,7 +425,8 @@ void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString r
/*!
\internal
*/
-void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
+void QWebSocketPrivate::open(const QNetworkRequest &request,
+ const QWebSocketHandshakeOptions &options, bool mask)
{
//just delete the old socket for the moment;
//later, we can add more 'intelligent' handling by looking at the URL
@@ -392,7 +435,7 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
QUrl url = request.url();
if (!url.isValid() || url.toString().contains(QStringLiteral("\r\n"))) {
setErrorString(QWebSocket::tr("Invalid URL."));
- Q_EMIT q->error(QAbstractSocket::ConnectionRefusedError);
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
return;
}
if (m_pSocket) {
@@ -406,13 +449,13 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
m_isClosingHandshakeReceived = false;
m_isClosingHandshakeSent = false;
- setRequest(request);
+ setRequest(request, options);
QString resourceName = url.path(QUrl::FullyEncoded);
// Check for encoded \r\n
if (resourceName.contains(QStringLiteral("%0D%0A"))) {
setRequest(QNetworkRequest()); //clear request
setErrorString(QWebSocket::tr("Invalid resource name."));
- Q_EMIT q->error(QAbstractSocket::ConnectionRefusedError);
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
return;
}
if (!url.query().isEmpty()) {
@@ -432,13 +475,15 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
const QString message =
QWebSocket::tr("SSL Sockets are not supported on this platform.");
setErrorString(message);
- Q_EMIT q->error(QAbstractSocket::UnsupportedSocketOperationError);
+ emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
} else {
QSslSocket *sslSocket = new QSslSocket(q);
m_pSocket = sslSocket;
if (Q_LIKELY(m_pSocket)) {
- m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
- m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ QObject::connect(sslSocket, &QSslSocket::connected, [sslSocket](){
+ sslSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
+ sslSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ });
m_pSocket->setReadBufferSize(m_readBufferSize);
m_pSocket->setPauseMode(m_pauseMode);
@@ -458,7 +503,7 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
} else {
const QString message = QWebSocket::tr("Out of memory.");
setErrorString(message);
- Q_EMIT q->error(QAbstractSocket::SocketResourceError);
+ emitErrorOccurred(QAbstractSocket::SocketResourceError);
}
}
} else
@@ -466,8 +511,10 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
if (url.scheme() == QStringLiteral("ws")) {
m_pSocket = new QTcpSocket(q);
if (Q_LIKELY(m_pSocket)) {
- m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
- m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ QObject::connect(m_pSocket, &QTcpSocket::connected, [this](){
+ m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
+ m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ });
m_pSocket->setReadBufferSize(m_readBufferSize);
m_pSocket->setPauseMode(m_pauseMode);
@@ -481,13 +528,13 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
} else {
const QString message = QWebSocket::tr("Out of memory.");
setErrorString(message);
- Q_EMIT q->error(QAbstractSocket::SocketResourceError);
+ emitErrorOccurred(QAbstractSocket::SocketResourceError);
}
} else {
const QString message =
QWebSocket::tr("Unsupported WebSocket scheme: %1").arg(url.scheme());
setErrorString(message);
- Q_EMIT q->error(QAbstractSocket::UnsupportedSocketOperationError);
+ emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
}
}
}
@@ -538,10 +585,13 @@ void QWebSocketPrivate::setResourceName(const QString &resourceName)
/*!
\internal
*/
-void QWebSocketPrivate::setRequest(const QNetworkRequest &request)
+void QWebSocketPrivate::setRequest(const QNetworkRequest &request,
+ const QWebSocketHandshakeOptions &options)
{
if (m_request != request)
m_request = request;
+ if (m_options != options)
+ m_options = options;
}
/*!
@@ -590,8 +640,8 @@ void QWebSocketPrivate::makeConnections(QTcpSocket *pTcpSocket)
if (Q_LIKELY(pTcpSocket)) {
//pass through signals
- QObject::connect(pTcpSocket, &QAbstractSocket::errorOccurred,
- q, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error));
+ QObjectPrivate::connect(pTcpSocket, &QAbstractSocket::errorOccurred, this,
+ &QWebSocketPrivate::emitErrorOccurred);
#ifndef QT_NO_NETWORKPROXY
QObject::connect(pTcpSocket, &QAbstractSocket::proxyAuthenticationRequired, q,
&QWebSocket::proxyAuthenticationRequired);
@@ -606,10 +656,8 @@ void QWebSocketPrivate::makeConnections(QTcpSocket *pTcpSocket)
//catch signals
QObjectPrivate::connect(pTcpSocket, &QAbstractSocket::stateChanged, this,
&QWebSocketPrivate::processStateChanged);
- //!!!important to use a QueuedConnection here;
- //with QTcpSocket there is no problem, but with QSslSocket the processing hangs
QObjectPrivate::connect(pTcpSocket, &QAbstractSocket::readyRead, this,
- &QWebSocketPrivate::processData, Qt::QueuedConnection);
+ &QWebSocketPrivate::processData);
#ifndef QT_NO_SSL
const QSslSocket * const sslSocket = qobject_cast<const QSslSocket *>(pTcpSocket);
if (sslSocket) {
@@ -708,6 +756,14 @@ QString QWebSocketPrivate::origin() const
/*!
\internal
*/
+QWebSocketHandshakeOptions QWebSocketPrivate::handshakeOptions() const
+{
+ return m_options;
+}
+
+/*!
+ \internal
+ */
QString QWebSocketPrivate::protocol() const
{
return m_protocol;
@@ -744,7 +800,6 @@ QByteArray QWebSocketPrivate::getFrameHeader(QWebSocketProtocol::OpCode opCode,
quint64 payloadLength, quint32 maskingKey,
bool lastFrame)
{
- Q_Q(QWebSocket);
QByteArray header;
bool ok = payloadLength <= 0x7FFFFFFFFFFFFFFFULL;
@@ -778,7 +833,7 @@ QByteArray QWebSocketPrivate::getFrameHeader(QWebSocketProtocol::OpCode opCode,
}
} else {
setErrorString(QStringLiteral("WebSocket::getHeader: payload too big!"));
- Q_EMIT q->error(QAbstractSocket::DatagramTooLargeError);
+ emitErrorOccurred(QAbstractSocket::DatagramTooLargeError);
}
return header;
@@ -793,7 +848,6 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
if (Q_UNLIKELY(!m_pSocket) || (state() != QAbstractSocket::ConnectedState))
return payloadWritten;
- Q_Q(QWebSocket);
const QWebSocketProtocol::OpCode firstOpCode = isBinary ?
QWebSocketProtocol::OpCodeBinary : QWebSocketProtocol::OpCodeText;
@@ -839,7 +893,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
m_pSocket->flush();
setErrorString(QWebSocket::tr("Error writing bytes to socket: %1.")
.arg(m_pSocket->errorString()));
- Q_EMIT q->error(QAbstractSocket::NetworkError);
+ emitErrorOccurred(QAbstractSocket::NetworkError);
break;
}
}
@@ -849,7 +903,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
if (Q_UNLIKELY(payloadWritten != data.size())) {
setErrorString(QWebSocket::tr("Bytes written %1 != %2.")
.arg(payloadWritten).arg(data.size()));
- Q_EMIT q->error(QAbstractSocket::NetworkError);
+ emitErrorOccurred(QAbstractSocket::NetworkError);
}
return payloadWritten;
}
@@ -913,205 +967,205 @@ qint64 QWebSocketPrivate::writeFrame(const QByteArray &frame)
return written;
}
+//called on the client for a server handshake response
/*!
\internal
*/
-static QString readLine(QTcpSocket *pSocket)
+void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket)
{
- Q_ASSERT(pSocket);
- QString line;
- char c;
- while (pSocket->getChar(&c)) {
- if (c == char('\r')) {
- pSocket->getChar(&c);
- break;
- } else {
- line.append(QChar::fromLatin1(c));
+ Q_Q(QWebSocket);
+ if (Q_UNLIKELY(!pSocket))
+ return;
+
+ static const QByteArray endOfHeaderMarker = QByteArrayLiteral("\r\n\r\n");
+ const qint64 byteAvailable = pSocket->bytesAvailable();
+ QByteArray available = pSocket->peek(byteAvailable);
+ const int endOfHeaderIndex = available.indexOf(endOfHeaderMarker);
+ if (endOfHeaderIndex < 0) {
+ //then we don't have our header complete yet
+ //check that no one is trying to exhaust our virtual memory
+ const qint64 maxHeaderLength = MAX_HEADERLINE_LENGTH * MAX_HEADERLINES + endOfHeaderMarker.size();
+ if (Q_UNLIKELY(byteAvailable > maxHeaderLength)) {
+ setErrorString(QWebSocket::tr("Header is too large"));
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
}
+ return;
}
- return line;
-}
-
-// this function is a copy of QHttpNetworkReplyPrivate::parseStatus
-static bool parseStatusLine(const QByteArray &status, int *majorVersion, int *minorVersion,
- int *statusCode, QString *reasonPhrase)
-{
- // from RFC 2616:
- // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
- // HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
- // that makes: 'HTTP/n.n xxx Message'
- // byte count: 0123456789012
-
- static const int minLength = 11;
- static const int dotPos = 6;
- static const int spacePos = 8;
- static const char httpMagic[] = "HTTP/";
-
- if (status.length() < minLength
- || !status.startsWith(httpMagic)
- || status.at(dotPos) != '.'
- || status.at(spacePos) != ' ') {
- // I don't know how to parse this status line
- return false;
+ const int headerSize = endOfHeaderIndex + endOfHeaderMarker.size();
+ //don't read past the header
+ QByteArrayView headers = QByteArrayView(available).first(headerSize);
+ //remove our header from the tcpSocket
+ qint64 skippedSize = pSocket->skip(headerSize);
+
+ if (Q_UNLIKELY(skippedSize != headerSize)) {
+ setErrorString(QWebSocket::tr("Read handshake request header failed"));
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
+ return;
}
- // optimize for the valid case: defer checking until the end
- *majorVersion = status.at(dotPos - 1) - '0';
- *minorVersion = status.at(dotPos + 1) - '0';
+ QHttpHeaderParser parser;
+ static const QByteArray endOfStatusMarker = QByteArrayLiteral("\r\n");
+ const int endOfStatusIndex = headers.indexOf(endOfStatusMarker);
+ const QByteArrayView status = headers.first(endOfStatusIndex);
- int i = spacePos;
- int j = status.indexOf(' ', i + 1); // j == -1 || at(j) == ' ' so j+1 == 0 && j+1 <= length()
- const QByteArray code = status.mid(i + 1, j - i - 1);
-
- bool ok;
- *statusCode = code.toInt(&ok);
- *reasonPhrase = QString::fromLatin1(status.constData() + j + 1);
-
- return ok && uint(*majorVersion) <= 9 && uint(* minorVersion) <= 9;
-}
+ if (!parser.parseStatus(status)) {
+ setErrorString(QWebSocket::tr("Read handshake request status failed"));
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
+ return;
+ }
+ if (!parser.parseHeaders(headers.sliced(endOfStatusIndex + endOfStatusMarker.size()))) {
+ setErrorString(QWebSocket::tr("Parsing handshake request header failed"));
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
+ return;
+ }
-//called on the client for a server handshake response
-/*!
- \internal
- */
-void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket)
-{
- Q_Q(QWebSocket);
- if (Q_UNLIKELY(!pSocket))
+ const QString acceptKey = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("sec-websocket-accept")));
+ const QString upgrade = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("upgrade")));
+ const QString connection = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("connection")));
+#if 0 // unused for the moment
+ const QString extensions = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("sec-websocket-extensions"));
+#endif
+ const QString protocol = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("sec-websocket-protocol")));
+ if (!protocol.isEmpty() && !requestedSubProtocols().contains(protocol)) {
+ setErrorString(QWebSocket::tr("WebSocket server has chosen protocol %1 which has not been "
+ "requested")
+ .arg(protocol));
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
return;
- // Reset handshake on a new connection.
- if (m_handshakeState == AllDoneState)
- m_handshakeState = NothingDoneState;
+ }
+ const QString version = QString::fromLatin1(parser.combinedHeaderValue(
+ QByteArrayLiteral("sec-websocket-version")));
+ bool ok = false;
QString errorDescription;
-
- switch (m_handshakeState) {
- case NothingDoneState:
- m_headers.clear();
- m_handshakeState = ReadingStatusState;
- Q_FALLTHROUGH();
- case ReadingStatusState:
- if (!pSocket->canReadLine())
- return;
- m_statusLine = pSocket->readLine().trimmed();
- if (Q_UNLIKELY(!parseStatusLine(m_statusLine, &m_httpMajorVersion, &m_httpMinorVersion, &m_httpStatusCode, &m_httpStatusMessage))) {
- errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(QString::fromLatin1(m_statusLine));
- break;
- }
- m_handshakeState = ReadingHeaderState;
- Q_FALLTHROUGH();
- case ReadingHeaderState: {
- // TODO: this should really use the existing code from QHttpNetworkReplyPrivate::parseHeader
- auto lastHeader = m_headers.end();
- while (pSocket->canReadLine()) {
- QString headerLine = readLine(pSocket);
-
- if (headerLine.isEmpty()) {
- // end of headers
- m_handshakeState = ParsingHeaderState;
- break;
- } else if (headerLine.startsWith(QLatin1Char(' ')) || headerLine.startsWith(QLatin1Char('\t'))) {
- // continuation line -- add this to the last header field
- if (Q_UNLIKELY(lastHeader == m_headers.end())) {
- errorDescription = QWebSocket::tr("Malformed header in response: %1.").arg(headerLine);
- break;
- }
- lastHeader.value().append(QLatin1Char(' '));
- lastHeader.value().append(headerLine.trimmed());
- } else {
- int colonPos = headerLine.indexOf(QLatin1Char(':'));
- if (Q_UNLIKELY(colonPos <= 0)) {
- errorDescription = QWebSocket::tr("Malformed header in response: %1.").arg(headerLine);
- break;
- }
- lastHeader = m_headers.insert(headerLine.left(colonPos).trimmed().toLower(),
- headerLine.mid(colonPos + 1).trimmed());
- }
- }
-
- if (m_handshakeState != ParsingHeaderState) {
- if (pSocket->state() != QAbstractSocket::ConnectedState) {
- errorDescription = QWebSocket::tr("QWebSocketPrivate::processHandshake: Connection closed while reading header.");
- break;
+ switch (parser.getStatusCode()) {
+ case 101: {
+ //HTTP/x.y 101 Switching Protocols
+ //TODO: do not check the httpStatusText right now
+ ok = (acceptKey.size() > 0
+ && parser.getMajorVersion() > 0 && parser.getMinorVersion() > 0
+ && upgrade.compare(u"websocket", Qt::CaseInsensitive) == 0
+ && connection.compare(u"upgrade", Qt::CaseInsensitive) == 0);
+
+ if (ok) {
+ const QString accept = calculateAcceptKey(m_key);
+ if (accept != acceptKey) {
+ ok = false;
+ errorDescription = QWebSocket::tr(
+ "Accept-Key received from server %1 does not match the client key %2.")
+ .arg(acceptKey, accept);
}
- return;
+ } else {
+ const QString upgradeParms = QLatin1String(
+ "Accept-key size: %1, version: %2.%3, upgrade: %4, connection: %5").arg(
+ QString::number(acceptKey.size()), QString::number(parser.getMajorVersion()),
+ QString::number(parser.getMinorVersion()), upgrade, connection);
+ errorDescription = QWebSocket::tr(
+ "Invalid parameter encountered during protocol upgrade: %1").arg(upgradeParms);
}
- Q_FALLTHROUGH();
+ break;
}
- case ParsingHeaderState: {
- const QString acceptKey = m_headers.value(QStringLiteral("sec-websocket-accept"), QString());
- const QString upgrade = m_headers.value(QStringLiteral("upgrade"), QString());
- const QString connection = m_headers.value(QStringLiteral("connection"), QString());
-// unused for the moment
-// const QString extensions = m_headers.value(QStringLiteral("sec-websocket-extensions"),
-// QString());
-// const QString protocol = m_headers.value(QStringLiteral("sec-websocket-protocol"),
-// QString());
- const QString version = m_headers.value(QStringLiteral("sec-websocket-version"), QString());
-
- bool ok = false;
- if (Q_LIKELY(m_httpStatusCode == 101)) {
- //HTTP/x.y 101 Switching Protocols
- //TODO: do not check the httpStatusText right now
- ok = !(acceptKey.isEmpty() ||
- (m_httpMajorVersion < 1 || m_httpMinorVersion < 1) ||
- (upgrade.toLower() != QStringLiteral("websocket")) ||
- (connection.toLower() != QStringLiteral("upgrade")));
- if (ok) {
- const QString accept = calculateAcceptKey(m_key);
- ok = (accept == acceptKey);
- if (!ok)
- errorDescription =
- QWebSocket::tr("Accept-Key received from server %1 does not match the client key %2.")
- .arg(acceptKey, accept);
- } else {
+ case 400: {
+ //HTTP/1.1 400 Bad Request
+ if (!version.isEmpty()) {
+ const QStringList versions = version.split(QStringLiteral(", "), Qt::SkipEmptyParts);
+ if (!versions.contains(QString::number(QWebSocketProtocol::currentVersion()))) {
+ //if needed to switch protocol version, then we are finished here
+ //because we cannot handle other protocols than the RFC one (v13)
errorDescription =
- QWebSocket::tr("QWebSocketPrivate::processHandshake: Invalid statusline in response: %1.")
- .arg(QString::fromLatin1(m_statusLine));
- }
- } else if (m_httpStatusCode == 400) {
- //HTTP/1.1 400 Bad Request
- if (!version.isEmpty()) {
- const QStringList versions = version.split(QStringLiteral(", "), Qt::SkipEmptyParts);
- if (!versions.contains(QString::number(QWebSocketProtocol::currentVersion()))) {
- //if needed to switch protocol version, then we are finished here
- //because we cannot handle other protocols than the RFC one (v13)
- errorDescription =
- QWebSocket::tr("Handshake: Server requests a version that we don't support: %1.")
- .arg(versions.join(QStringLiteral(", ")));
- } else {
- //we tried v13, but something different went wrong
- errorDescription =
- QWebSocket::tr("QWebSocketPrivate::processHandshake: Unknown error condition encountered. Aborting connection.");
- }
+ QWebSocket::tr("Handshake: Server requests a version that we don't support: %1.")
+ .arg(versions.join(QStringLiteral(", ")));
} else {
- errorDescription =
- QWebSocket::tr("QWebSocketPrivate::processHandshake: Unknown error condition encountered. Aborting connection.");
+ //we tried v13, but something different went wrong
+ errorDescription =
+ QWebSocket::tr("QWebSocketPrivate::processHandshake: Unknown error condition encountered. Aborting connection.");
}
} else {
errorDescription =
- QWebSocket::tr("QWebSocketPrivate::processHandshake: Unhandled http status code: %1 (%2).")
- .arg(m_httpStatusCode).arg(m_httpStatusMessage);
+ QWebSocket::tr("QWebSocketPrivate::processHandshake: Unknown error condition encountered. Aborting connection.");
}
- if (ok)
- m_handshakeState = AllDoneState;
break;
}
- case AllDoneState:
- Q_UNREACHABLE();
+ case 401: {
+ // HTTP/1.1 401 UNAUTHORIZED
+ if (m_authenticator.isNull())
+ m_authenticator.detach();
+ auto *priv = QAuthenticatorPrivate::getPrivate(m_authenticator);
+ const QList<QByteArray> challenges = parser.headerFieldValues("WWW-Authenticate");
+ const bool isSupported = std::any_of(challenges.begin(), challenges.end(),
+ QAuthenticatorPrivate::isMethodSupported);
+ if (isSupported)
+ priv->parseHttpResponse(parser.headers(), /*isProxy=*/false, m_request.url().host());
+ if (!isSupported || priv->method == QAuthenticatorPrivate::None) {
+ // Keep the error on a single line so it can easily be searched for:
+ errorDescription = QWebSocket::tr(
+ "QWebSocketPrivate::processHandshake: "
+ "Unsupported WWW-Authenticate challenge(s) encountered!",
+ "'WWW-Authenticate' is the HTTP header.", int(challenges.size()));
+ break;
+ }
+
+ const QUrl url = m_request.url();
+ const bool hasCredentials = !url.userName().isEmpty() || !url.password().isEmpty();
+ if (hasCredentials) {
+ m_authenticator.setUser(url.userName());
+ m_authenticator.setPassword(url.password());
+ // Unset username and password so we don't try it again
+ QUrl copy = url;
+ copy.setUserName({});
+ copy.setPassword({});
+ m_request.setUrl(copy);
+ }
+ if (priv->phase == QAuthenticatorPrivate::Done) { // No user/pass from URL:
+ emit q->authenticationRequired(&m_authenticator);
+ if (priv->phase == QAuthenticatorPrivate::Done) {
+ // user/pass was not updated:
+ errorDescription = QWebSocket::tr(
+ "QWebSocket::processHandshake: Host requires authentication");
+ break;
+ }
+ }
+ m_needsResendWithCredentials = true;
+ if (parser.firstHeaderField("Connection").compare("close", Qt::CaseInsensitive) == 0)
+ m_needsReconnect = true;
+ else
+ m_bytesToSkipBeforeNewResponse = parser.firstHeaderField("Content-Length").toInt();
break;
}
+ default: {
+ errorDescription =
+ QWebSocket::tr("QWebSocketPrivate::processHandshake: Unhandled http status code: %1 (%2).")
+ .arg(parser.getStatusCode()).arg(parser.getReasonPhrase());
+ }
+ }
- if (m_handshakeState == AllDoneState) {
+ if (ok) {
// handshake succeeded
+ setProtocol(protocol);
setSocketState(QAbstractSocket::ConnectedState);
Q_EMIT q->connected();
+ } else if (m_needsResendWithCredentials) {
+ if (m_needsReconnect && m_pSocket->state() != QAbstractSocket::UnconnectedState) {
+ // Disconnect here, then in processStateChanged() we reconnect when
+ // we are unconnected.
+ m_pSocket->disconnectFromHost();
+ } else {
+ // I'm cheating, this is how a handshake starts:
+ processStateChanged(QAbstractSocket::ConnectedState);
+ }
+ return;
} else {
// handshake failed
- m_handshakeState = AllDoneState;
setErrorString(errorDescription);
- Q_EMIT q->error(QAbstractSocket::ConnectionRefusedError);
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
+ if (m_pSocket->state() != QAbstractSocket::UnconnectedState)
+ m_pSocket->disconnectFromHost();
}
}
@@ -1135,9 +1189,35 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
QList<QPair<QString, QString> > headers;
const auto headerList = m_request.rawHeaderList();
- for (const QByteArray &key : headerList)
+ for (const QByteArray &key : headerList) {
+ // protocols handled separately below
+ if (key.compare("Sec-WebSocket-Protocol", Qt::CaseInsensitive) == 0)
+ continue;
headers << qMakePair(QString::fromLatin1(key),
QString::fromLatin1(m_request.rawHeader(key)));
+ }
+ const QStringList subProtocols = requestedSubProtocols();
+
+ // Perform authorization if needed:
+ if (m_needsResendWithCredentials) {
+ m_needsResendWithCredentials = false;
+ // Based on QHttpNetworkRequest::uri:
+ auto uri = [](QUrl url) -> QByteArray {
+ QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo
+ | QUrl::FullyEncoded);
+ if (url.path().isEmpty())
+ url.setPath(QStringLiteral("/"));
+ else
+ format |= QUrl::NormalizePathSegments;
+ return url.toEncoded(format);
+ };
+ auto *priv = QAuthenticatorPrivate::getPrivate(m_authenticator);
+ Q_ASSERT(priv);
+ QByteArray response = priv->calculateResponse("GET", uri(m_request.url()),
+ m_request.url().host());
+ if (!response.isEmpty())
+ headers << qMakePair(u"Authorization"_s, QString::fromLatin1(response));
+ }
const auto format = QUrl::RemoveScheme | QUrl::RemoveUserInfo
| QUrl::RemovePath | QUrl::RemoveQuery
@@ -1147,12 +1227,12 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
host,
origin(),
QString(),
- QString(),
+ subProtocols,
m_key,
headers);
if (handshake.isEmpty()) {
m_pSocket->abort();
- Q_EMIT q->error(QAbstractSocket::ConnectionRefusedError);
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
return;
}
m_pSocket->write(handshake.toLatin1());
@@ -1165,7 +1245,28 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
break;
case QAbstractSocket::UnconnectedState:
- if (webSocketState != QAbstractSocket::UnconnectedState) {
+ if (m_needsReconnect) {
+ // Need to reinvoke the lambda queued because the underlying socket
+ // isn't done cleaning up yet...
+ auto reconnect = [this]() {
+ m_needsReconnect = false;
+ const QUrl url = m_request.url();
+#if QT_CONFIG(ssl)
+ const bool isEncrypted = url.scheme().compare(u"wss", Qt::CaseInsensitive) == 0;
+ if (isEncrypted) {
+ // This has to work because we did it earlier; this is just us
+ // reconnecting!
+ auto *sslSocket = qobject_cast<QSslSocket *>(m_pSocket);
+ Q_ASSERT(sslSocket);
+ sslSocket->connectToHostEncrypted(url.host(), quint16(url.port(443)));
+ } else
+#endif
+ {
+ m_pSocket->connectToHost(url.host(), quint16(url.port(80)));
+ }
+ };
+ QMetaObject::invokeMethod(q, reconnect, Qt::QueuedConnection);
+ } else if (webSocketState != QAbstractSocket::UnconnectedState) {
setSocketState(QAbstractSocket::UnconnectedState);
Q_EMIT q->disconnected();
}
@@ -1195,13 +1296,18 @@ void QWebSocketPrivate::processData()
{
if (!m_pSocket) // disconnected with data still in-bound
return;
- while (m_pSocket->bytesAvailable()) {
- if (state() == QAbstractSocket::ConnectingState) {
- if (!m_pSocket->canReadLine())
- return;
- processHandshake(m_pSocket);
- } else if (!m_dataProcessor->process(m_pSocket)) {
+ if (state() == QAbstractSocket::ConnectingState) {
+ if (m_bytesToSkipBeforeNewResponse > 0)
+ m_bytesToSkipBeforeNewResponse -= m_pSocket->skip(m_bytesToSkipBeforeNewResponse);
+ if (m_bytesToSkipBeforeNewResponse > 0 || !m_pSocket->canReadLine())
return;
+ processHandshake(m_pSocket);
+ // That may have changed state(), recheck in the next 'if' below.
+ }
+ if (state() != QAbstractSocket::ConnectingState) {
+ while (m_pSocket->bytesAvailable()) {
+ if (!m_dataProcessor->process(m_pSocket))
+ return;
}
}
}
@@ -1252,7 +1358,7 @@ QString QWebSocketPrivate::createHandShakeRequest(QString resourceName,
QString host,
QString origin,
QString extensions,
- QString protocols,
+ const QStringList &protocols,
QByteArray key,
const QList<QPair<QString, QString> > &headers)
{
@@ -1277,11 +1383,6 @@ QString QWebSocketPrivate::createHandShakeRequest(QString resourceName,
"Possible attack detected."));
return QString();
}
- if (protocols.contains(QStringLiteral("\r\n"))) {
- setErrorString(QWebSocket::tr("The protocols attribute contains newlines. " \
- "Possible attack detected."));
- return QString();
- }
handshakeRequest << QStringLiteral("GET ") % resourceName % QStringLiteral(" HTTP/1.1") <<
QStringLiteral("Host: ") % host <<
@@ -1292,10 +1393,26 @@ QString QWebSocketPrivate::createHandShakeRequest(QString resourceName,
handshakeRequest << QStringLiteral("Origin: ") % origin;
handshakeRequest << QStringLiteral("Sec-WebSocket-Version: ")
% QString::number(QWebSocketProtocol::currentVersion());
- if (extensions.length() > 0)
+ if (extensions.size() > 0)
handshakeRequest << QStringLiteral("Sec-WebSocket-Extensions: ") % extensions;
- if (protocols.length() > 0)
- handshakeRequest << QStringLiteral("Sec-WebSocket-Protocol: ") % protocols;
+
+ const QStringList validProtocols = [&] {
+ QStringList validProtocols;
+ validProtocols.reserve(protocols.size());
+ for (const auto &p : protocols) {
+ if (isValidSubProtocolName(p))
+ validProtocols.append(p);
+ else
+ qWarning() << "Ignoring invalid WebSocket subprotocol name" << p;
+ }
+
+ return validProtocols;
+ }();
+
+ if (!validProtocols.isEmpty()) {
+ handshakeRequest << QStringLiteral("Sec-WebSocket-Protocol: ")
+ % validProtocols.join(QLatin1String(", "));
+ }
for (const auto &header : headers)
handshakeRequest << header.first % QStringLiteral(": ") % header.second;
@@ -1547,6 +1664,18 @@ void QWebSocketPrivate::setReadBufferSize(qint64 size)
m_pSocket->setReadBufferSize(m_readBufferSize);
}
+void QWebSocketPrivate::emitErrorOccurred(QAbstractSocket::SocketError error)
+{
+ Q_Q(QWebSocket);
+ Q_EMIT q->errorOccurred(error);
+#if QT_DEPRECATED_SINCE(6, 5)
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
+ Q_EMIT q->error(error);
+ QT_WARNING_POP
+#endif
+}
+
#ifndef Q_OS_WASM
/*!
\internal
diff --git a/src/websockets/qwebsocket_p.h b/src/websockets/qwebsocket_p.h
index 9dc62c6..836b38b 100644
--- a/src/websockets/qwebsocket_p.h
+++ b/src/websockets/qwebsocket_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKET_P_H
#define QWEBSOCKET_P_H
@@ -56,6 +20,7 @@
#ifndef QT_NO_NETWORKPROXY
#include <QtNetwork/QNetworkProxy>
#endif
+#include <QtNetwork/QAuthenticator>
#ifndef QT_NO_SSL
#include <QtNetwork/QSslConfiguration>
#include <QtNetwork/QSslError>
@@ -65,12 +30,13 @@
#include <private/qobject_p.h>
#include "qwebsocket.h"
+#include "qwebsockethandshakeoptions.h"
#include "qwebsocketprotocol.h"
#include "qwebsocketdataprocessor_p.h"
#include "qdefaultmaskgenerator_p.h"
#ifdef Q_OS_WASM
-#include <emscripten/val.h>
+# include <emscripten/websocket.h>
#endif
QT_BEGIN_NAMESPACE
@@ -110,6 +76,12 @@ public:
QWebSocketProtocol::Version version);
~QWebSocketPrivate() override;
+ // both constants are taken from the default settings of Apache
+ // see: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize and
+ // http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfields
+ static constexpr int MAX_HEADERLINE_LENGTH = 8 * 1024; // maximum length of a http request header line
+ static constexpr int MAX_HEADERLINES = 100; // maximum number of http request header lines
+
void init();
void abort();
QAbstractSocket::SocketError error() const;
@@ -138,6 +110,7 @@ public:
QString resourceName() const;
QNetworkRequest request() const;
QString origin() const;
+ QWebSocketHandshakeOptions handshakeOptions() const;
QString protocol() const;
QString extension() const;
QWebSocketProtocol::CloseCode closeCode() const;
@@ -157,7 +130,7 @@ public:
void closeGoingAway();
void close(QWebSocketProtocol::CloseCode closeCode, QString reason);
- void open(const QNetworkRequest &request, bool mask);
+ void open(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options, bool mask);
void ping(const QByteArray &payload);
void setSocketState(QAbstractSocket::SocketState state);
@@ -171,18 +144,23 @@ public:
void setOutgoingFrameSize(quint64 outgoingFrameSize);
quint64 outgoingFrameSize() const;
static quint64 maxOutgoingFrameSize();
-
+#ifdef Q_OS_WASM
+ void setSocketClosed(const EmscriptenWebSocketCloseEvent *emCloseEvent);
+ QString closeCodeToString(QWebSocketProtocol::CloseCode code);
+#endif
private:
QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version);
void setVersion(QWebSocketProtocol::Version version);
void setResourceName(const QString &resourceName);
- void setRequest(const QNetworkRequest &request);
+ void setRequest(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options = {});
void setOrigin(const QString &origin);
void setProtocol(const QString &protocol);
void setExtension(const QString &extension);
void enableMasking(bool enable);
void setErrorString(const QString &errorString);
+ QStringList requestedSubProtocols() const;
+
void socketDestroyed(QObject *socket);
void processData();
@@ -204,7 +182,7 @@ private:
QString host,
QString origin,
QString extensions,
- QString protocols,
+ const QStringList &options,
QByteArray key,
const QList<QPair<QString, QString> > &headers);
@@ -218,6 +196,7 @@ private:
QByteArray generateKey() const;
Q_REQUIRED_RESULT qint64 writeFrames(const QList<QByteArray> &frames);
Q_REQUIRED_RESULT qint64 writeFrame(const QByteArray &frame);
+ void emitErrorOccurred(QAbstractSocket::SocketError error);
QTcpSocket *m_pSocket;
QString m_errorString;
@@ -225,6 +204,7 @@ private:
QUrl m_resource;
QString m_resourceName;
QNetworkRequest m_request;
+ QWebSocketHandshakeOptions m_options;
QString m_origin;
QString m_protocol;
QString m_extension;
@@ -232,12 +212,21 @@ private:
QAbstractSocket::PauseModes m_pauseMode;
qint64 m_readBufferSize;
+ // For WWW-Authenticate handling
+ QAuthenticator m_authenticator;
+ qint64 m_bytesToSkipBeforeNewResponse = 0;
+
QByteArray m_key; //identification key used in handshake requests
bool m_mustMask; //a server must not mask the frames it sends
bool m_isClosingHandshakeSent;
bool m_isClosingHandshakeReceived;
+
+ // For WWW-Authenticate handling
+ bool m_needsResendWithCredentials = false;
+ bool m_needsReconnect = false;
+
QWebSocketProtocol::CloseCode m_closeCode;
QString m_closeReason;
@@ -249,24 +238,12 @@ private:
QMaskGenerator *m_pMaskGenerator;
QDefaultMaskGenerator m_defaultMaskGenerator;
- enum HandshakeState {
- NothingDoneState,
- ReadingStatusState,
- ReadingHeaderState,
- ParsingHeaderState,
- AllDoneState
- } m_handshakeState;
- QByteArray m_statusLine;
- int m_httpStatusCode;
- int m_httpMajorVersion, m_httpMinorVersion;
- QString m_httpStatusMessage;
- QMultiMap<QString, QString> m_headers;
-
quint64 m_outgoingFrameSize;
friend class QWebSocketServerPrivate;
#ifdef Q_OS_WASM
- emscripten::val socketContext = emscripten::val::null();
+ EMSCRIPTEN_WEBSOCKET_T m_socketContext = 0;
+ uint16_t m_readyState = 0;
#endif
};
diff --git a/src/websockets/qwebsocket_wasm_p.cpp b/src/websockets/qwebsocket_wasm_p.cpp
index 73c596c..6d3f770 100644
--- a/src/websockets/qwebsocket_wasm_p.cpp
+++ b/src/websockets/qwebsocket_wasm_p.cpp
@@ -1,156 +1,113 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsocket_p.h"
-#include <QtCore/qcoreapplication.h>
+#if QT_CONFIG(thread)
+#include <QtCore/qthread.h>
+#include <emscripten/threading.h>
+#endif
#include <emscripten.h>
-#include <emscripten/bind.h>
+#include <emscripten/websocket.h>
+#include <emscripten/val.h>
-using namespace emscripten;
+#include <QHostAddress>
-static void q_onErrorCallback(val event)
+static EM_BOOL q_onWebSocketErrorCallback(int eventType,
+ const EmscriptenWebSocketErrorEvent *e,
+ void *userData)
{
- val target = event["target"];
+ Q_UNUSED(eventType)
+ Q_UNUSED(e)
- QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate*>(target["data-context"].as<quintptr>());
+ QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate *>(userData);
Q_ASSERT (wsp);
- emit wsp->q_func()->error(wsp->error());
+ emit wsp->q_func()->errorOccurred(wsp->error());
+ return EM_FALSE;
}
-static void q_onCloseCallback(val event)
+static EM_BOOL q_onWebSocketCloseCallback(int eventType,
+ const EmscriptenWebSocketCloseEvent *emCloseEvent,
+ void *userData)
{
- val target = event["target"];
-
- QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate*>(target["data-context"].as<quintptr>());
+ Q_UNUSED(eventType)
+ QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate *>(userData);
Q_ASSERT (wsp);
- wsp->setSocketState(QAbstractSocket::UnconnectedState);
- emit wsp->q_func()->disconnected();
+ wsp->setSocketClosed(emCloseEvent);
+ return EM_FALSE;
}
-static void q_onOpenCallback(val event)
+static EM_BOOL q_onWebSocketOpenCallback(int eventType,
+ const EmscriptenWebSocketOpenEvent *e, void *userData)
{
- val target = event["target"];
+ Q_UNUSED(eventType)
+ Q_UNUSED(e)
- QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate*>(target["data-context"].as<quintptr>());
+ QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate *>(userData);
Q_ASSERT (wsp);
wsp->setSocketState(QAbstractSocket::ConnectedState);
emit wsp->q_func()->connected();
+ return EM_FALSE;
}
-static void q_onIncomingMessageCallback(val event)
+static EM_BOOL q_onWebSocketIncomingMessageCallback(int eventType,
+ const EmscriptenWebSocketMessageEvent *e,
+ void *userData)
{
- val target = event["target"];
-
- if (event["data"].typeOf().as<std::string>() == "string") {
- QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate*>(target["data-context"].as<quintptr>());
- Q_ASSERT (wsp);
-
- const QString message = QString::fromStdString(event["data"].as<std::string>());
- if (!message.isEmpty())
- wsp->q_func()->textMessageReceived(message);
+ Q_UNUSED(eventType)
+ QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate *>(userData);
+ Q_ASSERT(wsp);
+
+ if (!e->isText) {
+ QByteArray buffer(reinterpret_cast<const char *>(e->data), e->numBytes);
+ if (!buffer.isEmpty())
+ emit wsp->q_func()->binaryMessageReceived(buffer);
} else {
- val reader = val::global("FileReader").new_();
- reader.set("onload", val::module_property("QWebSocketPrivate_readBlob"));
- reader.set("data-context", target["data-context"]);
- reader.call<void>("readAsArrayBuffer", event["data"]);
+ QString buffer = QString::fromUtf8(reinterpret_cast<const char *>(e->data), e->numBytes - 1);
+ emit wsp->q_func()->textMessageReceived(buffer);
}
-}
-
-static void q_readBlob(val event)
-{
- val fileReader = event["target"];
-
- QWebSocketPrivate *wsp = reinterpret_cast<QWebSocketPrivate*>(fileReader["data-context"].as<quintptr>());
- Q_ASSERT (wsp);
-
- // Set up source typed array
- val result = fileReader["result"]; // ArrayBuffer
- val Uint8Array = val::global("Uint8Array");
- val sourceTypedArray = Uint8Array.new_(result);
-
- // Allocate and set up destination typed array
- const size_t size = result["byteLength"].as<size_t>();
- QByteArray buffer(size, Qt::Uninitialized);
-
- val destinationTypedArray = Uint8Array.new_(val::module_property("HEAPU8")["buffer"],
- reinterpret_cast<quintptr>(buffer.data()), size);
- destinationTypedArray.call<void>("set", sourceTypedArray);
-
- wsp->q_func()->binaryMessageReceived(buffer);
-}
-
-EMSCRIPTEN_BINDINGS(wasm_module) {
- function("QWebSocketPrivate_onErrorCallback", q_onErrorCallback);
- function("QWebSocketPrivate_onCloseCallback", q_onCloseCallback);
- function("QWebSocketPrivate_onOpenCallback", q_onOpenCallback);
- function("QWebSocketPrivate_onIncomingMessageCallback", q_onIncomingMessageCallback);
- function("QWebSocketPrivate_readBlob", q_readBlob);
+ return 0;
}
qint64 QWebSocketPrivate::sendTextMessage(const QString &message)
{
- socketContext.call<void>("send", message.toStdString());
- return message.length();
+ int result = 0;
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+
+ if (m_readyState == 1) {
+ QByteArray messageArray = message.toUtf8();
+ result = emscripten_websocket_send_utf8_text(m_socketContext, messageArray);
+ if (result < 0)
+ emitErrorOccurred(QAbstractSocket::UnknownSocketError);
+ else
+ return messageArray.length();
+ } else
+ qWarning() << "Could not send message. Websocket is not open";
+
+ return result;
}
qint64 QWebSocketPrivate::sendBinaryMessage(const QByteArray &data)
{
- // Make a copy of the payload data; we don't know how long WebSocket.send() will
- // retain the memory view, while the QByteArray passed to this function may be
- // destroyed as soon as this function returns. In addition, the WebSocket.send()
- // API does not accept data from a view backet by a SharedArrayBuffer, which will
- // be the case for the view produced by typed_memory_view() when threads are enabled.
- val Uint8Array = val::global("Uint8Array");
- val dataCopy = Uint8Array.new_(data.size());
- val dataView = val(typed_memory_view(data.size(),
- reinterpret_cast<const unsigned char *>
- (data.constData())));
- dataCopy.call<void>("set", dataView);
-
- socketContext.call<void>("send", dataCopy);
- return data.length();
+ int result = 0;
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+ if (m_readyState == 1) {
+ result = emscripten_websocket_send_binary(
+ m_socketContext, const_cast<void *>(reinterpret_cast<const void *>(data.constData())),
+ data.size());
+ if (result < 0)
+ emitErrorOccurred(QAbstractSocket::UnknownSocketError);
+ else
+ return data.size();
+ } else
+ qWarning() << "Could not send message. Websocket is not open";
+
+ return result;
}
void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString reason)
@@ -161,43 +118,174 @@ void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString r
Q_EMIT q->aboutToClose();
setSocketState(QAbstractSocket::ClosingState);
- socketContext.call<void>("close", static_cast<quint16>(closeCode),
- reason.toLatin1().toStdString());
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+
+ if (m_readyState == 1 || m_readyState == 0) {
+ emscripten_websocket_close(m_socketContext, (int)closeCode, reason.toUtf8());
+ }
+ setSocketState(QAbstractSocket::UnconnectedState);
+ emit q->disconnected();
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
}
-void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
+void QWebSocketPrivate::open(const QNetworkRequest &request,
+ const QWebSocketHandshakeOptions &options, bool mask)
{
Q_UNUSED(mask);
- Q_Q(QWebSocket);
+ Q_UNUSED(options)
+
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+
+ if ((m_readyState == 1 || m_readyState == 3) && m_socketContext != 0) {
+ emitErrorOccurred(QAbstractSocket::OperationError);
+ return;
+ }
+
const QUrl url = request.url();
- if (!url.isValid() || url.toString().contains(QStringLiteral("\r\n"))) {
- setErrorString(QWebSocket::tr("Invalid URL."));
- Q_EMIT q->error(QAbstractSocket::ConnectionRefusedError);
+
+ emscripten::val navProtocol = emscripten::val::global("self")["location"]["protocol"];
+
+ // An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
+ // and causes emscripten to assert
+ bool isSecureContext = (navProtocol.as<std::string>().find("https") == 0);
+
+ if (!url.isValid()
+ || url.toString().contains(QStringLiteral("\r\n"))) {
+ setErrorString(QWebSocket::tr("Connection refused"));
+
+ emitErrorOccurred(QAbstractSocket::ConnectionRefusedError);
+
return;
}
+ // exception for localhost/127.0.0.1/[::1]
+ // localhost has special privledges
+
+ QHostAddress hostAddress(url.host());
+
+ bool hostAddressIsLocal = (hostAddress == QHostAddress::LocalHost
+ || hostAddress == QHostAddress::LocalHostIPv6);
+
+ if (url.host() != QStringLiteral("localhost") && !hostAddressIsLocal) {
+ if (isSecureContext && url.scheme() == QStringLiteral("ws")) {
+ const QString message =
+ QWebSocket::tr("Unsupported WebSocket scheme: %1").arg(url.scheme());
+ setErrorString(message);
+ emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
+ return;
+ }
+ }
- setSocketState(QAbstractSocket::ConnectingState);
- const std::string urlbytes = url.toString().toStdString();
+ EmscriptenWebSocketCreateAttributes attr;
+
+ emscripten_websocket_init_create_attributes(&attr); // memset
+ QByteArray thisUrl = url.toString(QUrl::FullyEncoded).toUtf8();
+ attr.url = thisUrl.constData();
+#if QT_CONFIG(thread)
+ // see https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/websocket.h
+ // choose a default: create websocket on calling thread
+ attr.createOnMainThread = false;
+#endif
// HTML WebSockets do not support arbitrary request headers, but
// do support the WebSocket protocol header. This header is
// required for some use cases like MQTT.
- const std::string protocolHeaderValue = request.rawHeader("Sec-WebSocket-Protocol").toStdString();
- val webSocket = val::global("WebSocket");
-
- socketContext = !protocolHeaderValue.empty()
- ? webSocket.new_(urlbytes, protocolHeaderValue)
- : webSocket.new_(urlbytes);
-
- socketContext.set("onerror", val::module_property("QWebSocketPrivate_onErrorCallback"));
- socketContext.set("onclose", val::module_property("QWebSocketPrivate_onCloseCallback"));
- socketContext.set("onopen", val::module_property("QWebSocketPrivate_onOpenCallback"));
- socketContext.set("onmessage", val::module_property("QWebSocketPrivate_onIncomingMessageCallback"));
- socketContext.set("data-context", val(quintptr(reinterpret_cast<void *>(this))));
+
+ // add user subprotocol options
+ QStringList protocols = requestedSubProtocols();
+ QByteArray secProto;
+ if (!protocols.isEmpty()) {
+ // comma-separated list of protocol strings, no spaces
+ secProto = protocols.join(QStringLiteral(",")).toLatin1();
+ attr.protocols = secProto.constData();
+ }
+
+ // create and connect
+ setSocketState(QAbstractSocket::ConnectingState);
+ m_socketContext = emscripten_websocket_new(&attr);
+
+ if (m_socketContext <= 0) { // m_readyState might not be changed yet
+ // error
+ emitErrorOccurred(QAbstractSocket::UnknownSocketError);
+ return;
+ }
+
+#if QT_CONFIG(thread)
+ emscripten_websocket_set_onopen_callback_on_thread(m_socketContext, (void *)this,
+ q_onWebSocketOpenCallback,
+ (quintptr)QThread::currentThreadId());
+ emscripten_websocket_set_onmessage_callback_on_thread(m_socketContext, (void *)this,
+ q_onWebSocketIncomingMessageCallback,
+ (quintptr)QThread::currentThreadId());
+ emscripten_websocket_set_onerror_callback_on_thread(m_socketContext, (void *)this,
+ q_onWebSocketErrorCallback,
+ (quintptr)QThread::currentThreadId());
+ emscripten_websocket_set_onclose_callback_on_thread(m_socketContext, (void *)this,
+ q_onWebSocketCloseCallback,
+ (quintptr)QThread::currentThreadId());
+#else
+ emscripten_websocket_set_onopen_callback(m_socketContext, (void *)this,
+ q_onWebSocketOpenCallback);
+ emscripten_websocket_set_onmessage_callback(m_socketContext, (void *)this,
+ q_onWebSocketIncomingMessageCallback);
+ emscripten_websocket_set_onerror_callback(m_socketContext, (void *)this,
+ q_onWebSocketErrorCallback);
+ emscripten_websocket_set_onclose_callback(m_socketContext, (void *)this,
+ q_onWebSocketCloseCallback);
+#endif
}
bool QWebSocketPrivate::isValid() const
{
- return (!socketContext.isUndefined() &&
- (m_socketState == QAbstractSocket::ConnectedState));
+ return (m_socketContext > 0 && m_socketState == QAbstractSocket::ConnectedState);
+}
+
+void QWebSocketPrivate::setSocketClosed(const EmscriptenWebSocketCloseEvent *emCloseEvent)
+{
+ Q_Q(QWebSocket);
+ m_closeCode = (QWebSocketProtocol::CloseCode)emCloseEvent->code;
+
+ m_closeReason = QString::fromUtf8(emCloseEvent->reason);
+
+ if (m_closeReason.isEmpty()) {
+ m_closeReason = closeCodeToString(m_closeCode);
+ }
+
+ if (m_socketState == QAbstractSocket::ConnectedState) {
+ Q_EMIT q->aboutToClose();
+ setSocketState(QAbstractSocket::ClosingState);
+ }
+
+ if (!emCloseEvent->wasClean) {
+ m_errorString = QStringLiteral("The remote host closed the connection");
+ emit q->errorOccurred(error());
+ }
+
+ emscripten_websocket_get_ready_state(m_socketContext, &m_readyState);
+
+ if (m_readyState == 3) { // closed
+ setSocketState(QAbstractSocket::UnconnectedState);
+ emit q->disconnected();
+ emscripten_websocket_delete(emCloseEvent->socket);
+ m_socketContext = 0;
+ }
+}
+
+QString QWebSocketPrivate::closeCodeToString(QWebSocketProtocol::CloseCode code)
+{
+ switch (code) {
+ case QWebSocketProtocol::CloseCodeNormal: return QStringLiteral("Normal closure");
+ case QWebSocketProtocol::CloseCodeGoingAway: return QStringLiteral("Going away");
+ case QWebSocketProtocol::CloseCodeProtocolError: return QStringLiteral("Protocol error");
+ case QWebSocketProtocol::CloseCodeDatatypeNotSupported: return QStringLiteral("Unsupported data");
+ case QWebSocketProtocol::CloseCodeReserved1004: return QStringLiteral("Reserved");
+ case QWebSocketProtocol::CloseCodeMissingStatusCode: return QStringLiteral("No status received");
+ case QWebSocketProtocol::CloseCodeAbnormalDisconnection: return QStringLiteral("Abnormal closure");
+ case QWebSocketProtocol::CloseCodeWrongDatatype: return QStringLiteral("Invalid frame payload data");
+ case QWebSocketProtocol::CloseCodePolicyViolated: return QStringLiteral("Policy violation");
+ case QWebSocketProtocol::CloseCodeTooMuchData: return QStringLiteral("Message too big");
+ case QWebSocketProtocol::CloseCodeMissingExtension: return QStringLiteral("Mandatory extension missing");
+ case QWebSocketProtocol::CloseCodeBadOperation: return QStringLiteral("Internal server error");
+ case QWebSocketProtocol::CloseCodeTlsHandshakeFailed: return QStringLiteral("TLS handshake failed");
+ };
+ return QStringLiteral("");
}
diff --git a/src/websockets/qwebsocketcorsauthenticator.cpp b/src/websockets/qwebsocketcorsauthenticator.cpp
index 5d1cde4..e2529c2 100644
--- a/src/websockets/qwebsocketcorsauthenticator.cpp
+++ b/src/websockets/qwebsocketcorsauthenticator.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QWebSocketCorsAuthenticator
@@ -122,33 +86,30 @@ QWebSocketCorsAuthenticator::operator =(const QWebSocketCorsAuthenticator &other
return *this;
}
-#ifdef Q_COMPILER_RVALUE_REFS
/*!
Move-constructs a QWebSocketCorsAuthenticator, making it point at the same
object \a other was pointing to.
*/
-QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other) :
- d_ptr(other.d_ptr.take())
+QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other) noexcept :
+ d_ptr(other.d_ptr.release())
{}
/*!
Move-assigns \a other to this instance.
*/
QWebSocketCorsAuthenticator &
-QWebSocketCorsAuthenticator::operator =(QWebSocketCorsAuthenticator &&other)
+QWebSocketCorsAuthenticator::operator =(QWebSocketCorsAuthenticator &&other) noexcept
{
qSwap(d_ptr, other.d_ptr);
return *this;
}
-#endif
-
/*!
Swaps \a other with this authenticator.
This operation is very fast and never fails.
*/
-void QWebSocketCorsAuthenticator::swap(QWebSocketCorsAuthenticator &other)
+void QWebSocketCorsAuthenticator::swap(QWebSocketCorsAuthenticator &other) noexcept
{
if (&other != this)
qSwap(d_ptr, other.d_ptr);
diff --git a/src/websockets/qwebsocketcorsauthenticator.h b/src/websockets/qwebsocketcorsauthenticator.h
index b58316a..f2516bd 100644
--- a/src/websockets/qwebsocketcorsauthenticator.h
+++ b/src/websockets/qwebsocketcorsauthenticator.h
@@ -1,46 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETCORSAUTHENTICATOR_H
#define QWEBSOCKETCORSAUTHENTICATOR_H
#include "QtWebSockets/qwebsockets_global.h"
-#include <QtCore/QScopedPointer>
+#include <memory>
QT_BEGIN_NAMESPACE
@@ -55,12 +19,10 @@ public:
~QWebSocketCorsAuthenticator();
explicit QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other);
-#ifdef Q_COMPILER_RVALUE_REFS
- QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other);
- QWebSocketCorsAuthenticator &operator =(QWebSocketCorsAuthenticator &&other);
-#endif
+ QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other) noexcept;
+ QWebSocketCorsAuthenticator &operator =(QWebSocketCorsAuthenticator &&other) noexcept;
- void swap(QWebSocketCorsAuthenticator &other);
+ void swap(QWebSocketCorsAuthenticator &other) noexcept;
QWebSocketCorsAuthenticator &operator =(const QWebSocketCorsAuthenticator &other);
@@ -70,7 +32,7 @@ public:
bool allowed() const;
private:
- QScopedPointer<QWebSocketCorsAuthenticatorPrivate> d_ptr;
+ std::unique_ptr<QWebSocketCorsAuthenticatorPrivate> d_ptr;
};
QT_END_NAMESPACE
diff --git a/src/websockets/qwebsocketcorsauthenticator_p.h b/src/websockets/qwebsocketcorsauthenticator_p.h
index e1dfe55..eb460f3 100644
--- a/src/websockets/qwebsocketcorsauthenticator_p.h
+++ b/src/websockets/qwebsocketcorsauthenticator_p.h
@@ -1,45 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETCORSAUTHENTICATOR_P_H
#define QWEBSOCKETCORSAUTHENTICATOR_P_H
-#include <QtCore/qglobal.h>
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/QString>
//
diff --git a/src/websockets/qwebsocketdataprocessor.cpp b/src/websockets/qwebsocketdataprocessor.cpp
index 3ffc084..27da96b 100644
--- a/src/websockets/qwebsocketdataprocessor.cpp
+++ b/src/websockets/qwebsocketdataprocessor.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QWebSocketDataProcessor
The class QWebSocketDataProcessor is responsible for reading, validating and
@@ -188,9 +152,9 @@ bool QWebSocketDataProcessor::process(QIODevice *pIoDevice)
m_isFragmented = !frame.isFinalFrame();
}
quint64 messageLength = m_opCode == QWebSocketProtocol::OpCodeText
- ? quint64(m_textMessage.length())
- : quint64(m_binaryMessage.length());
- if (Q_UNLIKELY((messageLength + quint64(frame.payload().length())) >
+ ? quint64(m_textMessage.size())
+ : quint64(m_binaryMessage.size());
+ if (Q_UNLIKELY((messageLength + quint64(frame.payload().size())) >
maxAllowedMessageSize())) {
clear();
Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeTooMuchData,
@@ -198,9 +162,9 @@ bool QWebSocketDataProcessor::process(QIODevice *pIoDevice)
return true;
}
+ bool isFinalFrame = frame.isFinalFrame();
if (m_opCode == QWebSocketProtocol::OpCodeText) {
- QString frameTxt = m_decoder(frame.payload().constData(),
- frame.payload().size());
+ QString frameTxt = m_decoder(frame.payload());
if (Q_UNLIKELY(m_decoder.hasError())) {
clear();
Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeWrongDatatype,
@@ -208,14 +172,17 @@ bool QWebSocketDataProcessor::process(QIODevice *pIoDevice)
return true;
} else {
m_textMessage.append(frameTxt);
- Q_EMIT textFrameReceived(frameTxt, frame.isFinalFrame());
+ frame.clear();
+ Q_EMIT textFrameReceived(frameTxt, isFinalFrame);
}
} else {
m_binaryMessage.append(frame.payload());
- Q_EMIT binaryFrameReceived(frame.payload(), frame.isFinalFrame());
+ QByteArray payload = frame.payload();
+ frame.clear();
+ Q_EMIT binaryFrameReceived(payload, isFinalFrame);
}
- if (frame.isFinalFrame()) {
+ if (isFinalFrame) {
isDone = true;
if (m_opCode == QWebSocketProtocol::OpCodeText) {
const QString textMessage(m_textMessage);
@@ -253,6 +220,7 @@ void QWebSocketDataProcessor::clear()
m_textMessage.clear();
m_payloadLength = 0;
m_decoder.resetState();
+ frame.clear();
}
/*!
@@ -290,7 +258,7 @@ bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame)
if (payload.size() > 2) {
auto toUtf16 = QStringDecoder(QStringDecoder::Utf8,
QStringDecoder::Flag::Stateless | QStringDecoder::Flag::ConvertInvalidToNull);
- closeReason = toUtf16(payload.constData() + 2, payload.size() - 2);
+ closeReason = toUtf16(QByteArrayView(payload).sliced(2));
if (Q_UNLIKELY(toUtf16.hasError())) {
closeCode = QWebSocketProtocol::CloseCodeWrongDatatype;
closeReason = tr("Invalid UTF-8 code encountered.");
diff --git a/src/websockets/qwebsocketdataprocessor_p.h b/src/websockets/qwebsocketdataprocessor_p.h
index 5405060..5c07be6 100644
--- a/src/websockets/qwebsocketdataprocessor_p.h
+++ b/src/websockets/qwebsocketdataprocessor_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETDATAPROCESSOR_P_H
#define QWEBSOCKETDATAPROCESSOR_P_H
diff --git a/src/websockets/qwebsocketframe.cpp b/src/websockets/qwebsocketframe.cpp
index 008fe8c..6ce8c13 100644
--- a/src/websockets/qwebsocketframe.cpp
+++ b/src/websockets/qwebsocketframe.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QWebSocketFrame
@@ -248,8 +212,7 @@ void QWebSocketFrame::readFrame(QIODevice *pIoDevice)
return;
default:
- Q_UNREACHABLE();
- return;
+ Q_UNREACHABLE_RETURN();
}
}
}
@@ -300,7 +263,7 @@ QWebSocketFrame::ProcessingState QWebSocketFrame::readFrameHeader(QIODevice *pIo
*/
QWebSocketFrame::ProcessingState QWebSocketFrame::readFramePayloadLength(QIODevice *pIoDevice)
{
- // see http://tools.ietf.org/html/rfc6455#page-28 paragraph 5.2
+ // see https://tools.ietf.org/html/rfc6455#page-28 paragraph 5.2
// in all cases, the minimal number of bytes MUST be used to encode the length,
// for example, the length of a 124-byte-long string can't be encoded as the
// sequence 126, 0, 124"
@@ -333,7 +296,7 @@ QWebSocketFrame::ProcessingState QWebSocketFrame::readFramePayloadLength(QIODevi
return PS_DISPATCH_RESULT;
}
// Most significant bit must be set to 0 as
- // per http://tools.ietf.org/html/rfc6455#section-5.2
+ // per https://tools.ietf.org/html/rfc6455#section-5.2
m_length = qFromBigEndian<quint64>(length);
if (Q_UNLIKELY(m_length & (quint64(1) << 63))) {
setError(QWebSocketProtocol::CloseCodeProtocolError,
@@ -388,7 +351,7 @@ QWebSocketFrame::ProcessingState QWebSocketFrame::readFramePayload(QIODevice *pI
m_payload = pIoDevice->read(int(m_length));
// m_length can be safely cast to an integer,
// because MAX_FRAME_SIZE_IN_BYTES = MAX_INT
- if (Q_UNLIKELY(m_payload.length() != int(m_length))) {
+ if (Q_UNLIKELY(m_payload.size() != int(m_length))) {
// some error occurred; refer to the Qt documentation of QIODevice::read()
setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
tr("Some serious error occurred while reading from the network."));
diff --git a/src/websockets/qwebsocketframe_p.h b/src/websockets/qwebsocketframe_p.h
index 992379a..17681ae 100644
--- a/src/websockets/qwebsocketframe_p.h
+++ b/src/websockets/qwebsocketframe_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETFRAME_P_H
#define QWEBSOCKETFRAME_P_H
diff --git a/src/websockets/qwebsockethandshakeoptions.cpp b/src/websockets/qwebsockethandshakeoptions.cpp
new file mode 100644
index 0000000..8dcc3e0
--- /dev/null
+++ b/src/websockets/qwebsockethandshakeoptions.cpp
@@ -0,0 +1,108 @@
+// Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn <a.rehn@menlosystems.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwebsockethandshakeoptions_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QWebSocketHandshakeOptions
+
+ \inmodule QtWebSockets
+ \since 6.4
+ \brief Collects options for the WebSocket handshake.
+
+ QWebSocketHandshakeOptions collects options that are passed along to the
+ WebSocket handshake, such as WebSocket subprotocols and WebSocket
+ Extensions.
+
+ At the moment, only WebSocket subprotocols are supported.
+
+ \sa QWebSocket::open()
+*/
+
+/*!
+ \brief Constructs an empty QWebSocketHandshakeOptions object.
+*/
+QWebSocketHandshakeOptions::QWebSocketHandshakeOptions()
+ : d(new QWebSocketHandshakeOptionsPrivate)
+{
+}
+
+/*!
+ \brief Constructs a QWebSocketHandshakeOptions that is a copy of \a other.
+*/
+QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other)
+ : d(other.d)
+{
+}
+
+/*!
+ \fn QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept
+ \brief Constructs a QWebSocketHandshakeOptions that is moved from \a other.
+*/
+
+/*!
+ \brief Destroys this object.
+*/
+QWebSocketHandshakeOptions::~QWebSocketHandshakeOptions()
+{
+}
+
+/*!
+ \fn QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=(QWebSocketHandshakeOptions &&other) noexcept
+ \brief Moves \a other to this object.
+*/
+
+/*!
+ \brief Assigns \a other to this object.
+*/
+QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=(
+ const QWebSocketHandshakeOptions &other)
+{
+ d = other.d;
+ return *this;
+}
+
+/*!
+ \fn void swap(QWebSocketHandshakeOptions &other) noexcept
+ \brief Swaps this object with \a other.
+*/
+
+/*!
+ \brief Returns the list of WebSocket subprotocols to send along with the
+ websocket handshake.
+*/
+QStringList QWebSocketHandshakeOptions::subprotocols() const
+{
+ return d->subprotocols;
+}
+
+/*!
+ \brief Sets the list of WebSocket subprotocols \a protocols to send along
+ with the websocket handshake.
+
+ WebSocket subprotocol names may only consist of those US-ASCII characters
+ that are in the unreserved group. Invalid protocol names will not be
+ included in the handshake.
+*/
+void QWebSocketHandshakeOptions::setSubprotocols(const QStringList &protocols)
+{
+ d->subprotocols = protocols;
+}
+
+bool QWebSocketHandshakeOptions::equals(const QWebSocketHandshakeOptions &other) const
+{
+ return *d == *other.d;
+}
+
+/*!
+ //! friend
+ \fn QWebSocketHandshakeOptions::operator==(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs)
+ \fn QWebSocketHandshakeOptions::operator!=(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs)
+ \brief Compares \a lhs for equality with \a rhs.
+*/
+
+QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QWebSocketHandshakeOptionsPrivate)
+
+QT_END_NAMESPACE
diff --git a/src/websockets/qwebsockethandshakeoptions.h b/src/websockets/qwebsockethandshakeoptions.h
new file mode 100644
index 0000000..eac3344
--- /dev/null
+++ b/src/websockets/qwebsockethandshakeoptions.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn <a.rehn@menlosystems.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QWEBSOCKETHANDSHAKEOPTIONS_H
+#define QWEBSOCKETHANDSHAKEOPTIONS_H
+
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QStringList>
+
+#include "QtWebSockets/qwebsockets_global.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWebSocketHandshakeOptionsPrivate;
+
+QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QWebSocketHandshakeOptionsPrivate, Q_WEBSOCKETS_EXPORT)
+
+class Q_WEBSOCKETS_EXPORT QWebSocketHandshakeOptions
+{
+public:
+ QWebSocketHandshakeOptions();
+ QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other);
+ QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept = default;
+ ~QWebSocketHandshakeOptions();
+
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QWebSocketHandshakeOptions)
+ QWebSocketHandshakeOptions &operator=(const QWebSocketHandshakeOptions &other);
+
+ void swap(QWebSocketHandshakeOptions &other) noexcept { d.swap(other.d); }
+
+ QStringList subprotocols() const;
+ void setSubprotocols(const QStringList &protocols);
+
+private:
+ bool equals(const QWebSocketHandshakeOptions &other) const;
+
+ friend bool operator==(const QWebSocketHandshakeOptions &lhs,
+ const QWebSocketHandshakeOptions &rhs) { return lhs.equals(rhs); }
+ friend bool operator!=(const QWebSocketHandshakeOptions &lhs,
+ const QWebSocketHandshakeOptions &rhs) { return !lhs.equals(rhs); }
+
+ QSharedDataPointer<QWebSocketHandshakeOptionsPrivate> d;
+ friend class QWebSocketHandshakeOptionsPrivate;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBSOCKETHANDSHAKEOPTIONS_H
diff --git a/src/websockets/qwebsockethandshakeoptions_p.h b/src/websockets/qwebsockethandshakeoptions_p.h
new file mode 100644
index 0000000..9ff38a3
--- /dev/null
+++ b/src/websockets/qwebsockethandshakeoptions_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn <a.rehn@menlosystems.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWEBSOCKETHANDSHAKEOPTIONS_P_H
+#define QWEBSOCKETHANDSHAKEOPTIONS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QSharedData>
+
+#include "qwebsockethandshakeoptions.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_AUTOTEST_EXPORT QWebSocketHandshakeOptionsPrivate : public QSharedData
+{
+public:
+ inline bool operator==(const QWebSocketHandshakeOptionsPrivate &other) const
+ { return subprotocols == other.subprotocols; }
+
+ QStringList subprotocols;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBSOCKETHANDSHAKEOPTIONS_P_H
diff --git a/src/websockets/qwebsockethandshakerequest.cpp b/src/websockets/qwebsockethandshakerequest.cpp
index 89fbf8e..59f215b 100644
--- a/src/websockets/qwebsockethandshakerequest.cpp
+++ b/src/websockets/qwebsockethandshakerequest.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsockethandshakerequest_p.h"
#include "qwebsocketprotocol.h"
@@ -59,7 +23,7 @@ QWebSocketHandshakeRequest::QWebSocketHandshakeRequest(int port, bool isSecure)
m_port(port),
m_isSecure(isSecure),
m_isValid(false),
- m_headers(),
+ m_parser(),
m_versions(),
m_key(),
m_origin(),
@@ -83,7 +47,7 @@ QWebSocketHandshakeRequest::~QWebSocketHandshakeRequest()
void QWebSocketHandshakeRequest::clear()
{
m_isValid = false;
- m_headers.clear();
+ m_parser.clear();
m_versions.clear();
m_key.clear();
m_origin.clear();
@@ -119,9 +83,17 @@ bool QWebSocketHandshakeRequest::isValid() const
/*!
\internal
*/
-QMultiMap<QString, QString> QWebSocketHandshakeRequest::headers() const
+QList<QPair<QByteArray, QByteArray>> QWebSocketHandshakeRequest::headers() const
{
- return m_headers;
+ return m_parser.headers();
+}
+
+/*!
+ \internal
+ */
+bool QWebSocketHandshakeRequest::hasHeader(const QByteArray &name) const
+{
+ return !m_parser.firstHeaderField(name).isEmpty();
}
/*!
@@ -189,49 +161,50 @@ QUrl QWebSocketHandshakeRequest::requestUrl() const
}
/*!
- Reads a line of text from the given textstream (terminated by CR/LF).
+ Reads a line of text from the given QByteArrayView (terminated by CR/LF),
+ and removes the read bytes from the QByteArrayView.
If an empty line was detected, an empty string is returned.
When an error occurs, a null string is returned.
\internal
*/
-static QString readLine(QTextStream &stream, int maxHeaderLineLength)
+static QByteArrayView readLine(QByteArrayView &header, int maxHeaderLineLength)
{
- QString line;
- char c;
- while (!stream.atEnd()) {
- stream >> c;
- if (stream.status() != QTextStream::Ok)
- return QString();
- if (c == char('\r')) {
- //eat the \n character
- stream >> c;
- line.append(QStringLiteral(""));
- break;
- } else {
- line.append(QChar::fromLatin1(c));
- if (line.length() > maxHeaderLineLength)
- return QString();
- }
+ qsizetype length = qMin(maxHeaderLineLength, header.size());
+ QByteArrayView line = header.first(length);
+ qsizetype end = line.indexOf('\n');
+ if (end != -1) {
+ line = line.first(end);
+ if (line.endsWith('\r'))
+ line.chop(1);
+ header = header.sliced(end + 1);
+ return line;
}
- return line;
+ return QByteArrayView();
}
/*!
\internal
*/
-void QWebSocketHandshakeRequest::readHandshake(QTextStream &textStream, int maxHeaderLineLength,
- int maxHeaders)
+static void appendCommmaSeparatedLineToList(QStringList &list, QByteArrayView line)
+{
+ for (auto &c : QLatin1String(line).tokenize(QLatin1String(","), Qt::SkipEmptyParts))
+ list << c.trimmed().toString();
+}
+
+/*!
+ \internal
+ */
+void QWebSocketHandshakeRequest::readHandshake(QByteArrayView header, int maxHeaderLineLength)
{
clear();
- if (Q_UNLIKELY(textStream.status() != QTextStream::Ok))
- return;
- const QString requestLine = readLine(textStream, maxHeaderLineLength);
+ m_parser.setMaxHeaderFieldSize(maxHeaderLineLength);
+ QString requestLine = QString::fromLatin1(readLine(header, maxHeaderLineLength));
if (requestLine.isNull()) {
clear();
return;
}
const QStringList tokens = requestLine.split(QLatin1Char(' '), Qt::SkipEmptyParts);
- if (Q_UNLIKELY(tokens.length() < 3)) {
+ if (Q_UNLIKELY(tokens.size() < 3)) {
clear();
return;
}
@@ -245,47 +218,17 @@ void QWebSocketHandshakeRequest::readHandshake(QTextStream &textStream, int maxH
clear();
return;
}
- QString headerLine = readLine(textStream, maxHeaderLineLength);
- if (headerLine.isNull()) {
+
+ bool parsed = m_parser.parseHeaders(header);
+ if (!parsed) {
clear();
return;
}
- m_headers.clear();
- // TODO: this should really use the existing code from QHttpNetworkReplyPrivate::parseHeader
- auto lastHeader = m_headers.end();
- while (!headerLine.isEmpty()) {
- if (headerLine.startsWith(QLatin1Char(' ')) || headerLine.startsWith(QLatin1Char('\t'))) {
- // continuation line -- add this to the last header field
- if (Q_UNLIKELY(lastHeader == m_headers.end())) {
- clear();
- return;
- }
- lastHeader.value().append(QLatin1Char(' '));
- lastHeader.value().append(headerLine.trimmed());
- } else {
- int colonPos = headerLine.indexOf(QLatin1Char(':'));
- if (Q_UNLIKELY(colonPos <= 0)) {
- clear();
- return;
- }
- lastHeader = m_headers.insert(headerLine.left(colonPos).trimmed().toLower(),
- headerLine.mid(colonPos + 1).trimmed());
- }
- if (m_headers.size() > maxHeaders) {
- clear();
- return;
- }
- headerLine = readLine(textStream, maxHeaderLineLength);
- if (headerLine.isNull()) {
- clear();
- return;
- }
- }
m_requestUrl = QUrl::fromEncoded(resourceName.toLatin1());
- QString host = m_headers.value(QStringLiteral("host"), QString());
+ QString host = QString::fromLatin1(m_parser.firstHeaderField("host"));
if (m_requestUrl.isRelative()) {
- // see http://tools.ietf.org/html/rfc6455#page-17
+ // see https://tools.ietf.org/html/rfc6455#page-17
// No. 4 item in "The requirements for this handshake"
m_requestUrl.setAuthority(host);
if (!m_requestUrl.userName().isNull()) { // If the username is null, the password must be too.
@@ -299,59 +242,45 @@ void QWebSocketHandshakeRequest::readHandshake(QTextStream &textStream, int maxH
m_requestUrl.setScheme(scheme);
}
- const QStringList versionLines = m_headers.values(QStringLiteral("sec-websocket-version"));
- for (QStringList::const_iterator v = versionLines.begin(); v != versionLines.end(); ++v) {
- const QStringList versions = (*v).split(QStringLiteral(","), Qt::SkipEmptyParts);
- for (QStringList::const_iterator i = versions.begin(); i != versions.end(); ++i) {
+ const QList<QByteArray> versionLines = m_parser.headerFieldValues("sec-websocket-version");
+ for (auto v = versionLines.begin(); v != versionLines.end(); ++v) {
+ for (const auto &version :
+ QString::fromLatin1(*v).tokenize(QStringLiteral(","), Qt::SkipEmptyParts)) {
bool ok = false;
- (void)(*i).toUInt(&ok);
+ (void)version.toUInt(&ok);
if (!ok) {
clear();
return;
}
const QWebSocketProtocol::Version ver =
- QWebSocketProtocol::versionFromString((*i).trimmed());
+ QWebSocketProtocol::versionFromString(version.trimmed());
m_versions << ver;
}
}
//sort in descending order
std::sort(m_versions.begin(), m_versions.end(), std::greater<QWebSocketProtocol::Version>());
- m_key = m_headers.value(QStringLiteral("sec-websocket-key"), QString());
- //must contain "Upgrade", case-insensitive
- const QString upgrade = m_headers.value(QStringLiteral("upgrade"), QString());
- //must be equal to "websocket", case-insensitive
- const QString connection = m_headers.value(QStringLiteral("connection"), QString());
- const QStringList connectionLine = connection.split(QStringLiteral(","), Qt::SkipEmptyParts);
+
+ m_key = QString::fromLatin1(m_parser.firstHeaderField("sec-websocket-key"));
+ const QByteArray upgrade = m_parser.firstHeaderField("upgrade");
QStringList connectionValues;
- for (QStringList::const_iterator c = connectionLine.begin(); c != connectionLine.end(); ++c)
- connectionValues << (*c).trimmed();
+ appendCommmaSeparatedLineToList(connectionValues, m_parser.firstHeaderField("connection"));
//optional headers
- m_origin = m_headers.value(QStringLiteral("origin"), QString());
- const QStringList protocolLines = m_headers.values(QStringLiteral("sec-websocket-protocol"));
- for (const QString& pl : protocolLines) {
- const QStringList protocols = pl.split(QStringLiteral(","), Qt::SkipEmptyParts);
- for (const QString& p : protocols)
- m_protocols << p.trimmed();
- }
+ m_origin = QString::fromLatin1(m_parser.firstHeaderField("origin"));
+ const QList<QByteArray> protocolLines = m_parser.headerFieldValues("sec-websocket-protocol");
+ for (const QByteArray &pl : protocolLines)
+ appendCommmaSeparatedLineToList(m_protocols, pl);
- const QStringList extensionLines = m_headers.values(QStringLiteral("sec-websocket-extensions"));
- for (const QString& el : extensionLines) {
- const QStringList extensions = el.split(QStringLiteral(","), Qt::SkipEmptyParts);
- for (const QString& e : extensions)
- m_extensions << e.trimmed();
- }
+ const QList<QByteArray> extensionLines = m_parser.headerFieldValues("sec-websocket-extensions");
+ for (const QByteArray &el : extensionLines)
+ appendCommmaSeparatedLineToList(m_extensions, el);
//TODO: authentication field
- m_isValid = !(m_requestUrl.host().isEmpty() ||
- resourceName.isEmpty() ||
- m_versions.isEmpty() ||
- m_key.isEmpty() ||
- (verb != QStringLiteral("GET")) ||
- (!conversionOk || (httpVersion < 1.1f)) ||
- (upgrade.toLower() != QStringLiteral("websocket")) ||
- (!connectionValues.contains(QStringLiteral("upgrade"), Qt::CaseInsensitive)));
+ m_isValid = !(m_requestUrl.host().isEmpty() || resourceName.isEmpty() || m_versions.isEmpty()
+ || m_key.isEmpty() || verb != QStringLiteral("GET") || !conversionOk
+ || httpVersion < 1.1f || upgrade.compare("websocket", Qt::CaseInsensitive) != 0
+ || !connectionValues.contains(QStringLiteral("upgrade"), Qt::CaseInsensitive));
if (Q_UNLIKELY(!m_isValid))
clear();
}
diff --git a/src/websockets/qwebsockethandshakerequest_p.h b/src/websockets/qwebsockethandshakerequest_p.h
index c5e9c44..a183d77 100644
--- a/src/websockets/qwebsockethandshakerequest_p.h
+++ b/src/websockets/qwebsockethandshakerequest_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETHANDSHAKEREQUEST_P_H
#define QWEBSOCKETHANDSHAKEREQUEST_P_H
@@ -54,6 +18,7 @@
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QUrl>
+#include <QtNetwork/private/qhttpheaderparser_p.h>
#include "qwebsocketprotocol.h"
@@ -74,7 +39,8 @@ public:
int port() const;
bool isSecure() const;
bool isValid() const;
- QMultiMap<QString, QString> headers() const;
+ QList<QPair<QByteArray, QByteArray>> headers() const;
+ bool hasHeader(const QByteArray &name) const;
QList<QWebSocketProtocol::Version> versions() const;
QString key() const;
QString origin() const;
@@ -84,14 +50,14 @@ public:
QString resourceName() const;
QString host() const;
- void readHandshake(QTextStream &textStream, int maxHeaderLineLength, int maxHeaders);
+ void readHandshake(QByteArrayView header, int maxHeaderLineLength);
private:
int m_port;
bool m_isSecure;
bool m_isValid;
- QMultiMap<QString, QString> m_headers;
+ QHttpHeaderParser m_parser;
QList<QWebSocketProtocol::Version> m_versions;
QString m_key;
QString m_origin;
diff --git a/src/websockets/qwebsockethandshakeresponse.cpp b/src/websockets/qwebsockethandshakeresponse.cpp
index d3ef609..5f2492c 100644
--- a/src/websockets/qwebsockethandshakeresponse.cpp
+++ b/src/websockets/qwebsockethandshakeresponse.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsockethandshakeresponse_p.h"
#include "qwebsockethandshakerequest_p.h"
@@ -161,9 +125,21 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse(
} else {
if (request.isValid()) {
const QString acceptKey = calculateAcceptKey(request.key());
- const QList<QString> matchingProtocols =
- listIntersection(supportedProtocols, request.protocols(),
- std::less<QString>());
+
+ // Find first client protocol that is supported. Order is important!
+ const QString protocol = [&] {
+ const auto clientProtocols = request.protocols();
+
+ const auto isSupportedProtocol = [&](const QString &protocol) {
+ return supportedProtocols.contains(protocol);
+ };
+ const auto it = std::find_if(
+ clientProtocols.constBegin(), clientProtocols.constEnd(),
+ isSupportedProtocol);
+
+ return it == clientProtocols.constEnd() ? QString() : *it;
+ }();
+
//TODO: extensions must be kept in the order in which they arrive
//cannot use set.intersect() to get the supported extensions
const QList<QString> matchingExtensions =
@@ -182,8 +158,8 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse(
QStringLiteral("Upgrade: websocket") <<
QStringLiteral("Connection: Upgrade") <<
QStringLiteral("Sec-WebSocket-Accept: ") % acceptKey;
- if (!matchingProtocols.isEmpty()) {
- m_acceptedProtocol = matchingProtocols.first();
+ if (!protocol.isEmpty()) {
+ m_acceptedProtocol = protocol;
response << QStringLiteral("Sec-WebSocket-Protocol: ") % m_acceptedProtocol;
}
if (!matchingExtensions.isEmpty()) {
diff --git a/src/websockets/qwebsockethandshakeresponse_p.h b/src/websockets/qwebsockethandshakeresponse_p.h
index 9a9b883..27f7480 100644
--- a/src/websockets/qwebsockethandshakeresponse_p.h
+++ b/src/websockets/qwebsockethandshakeresponse_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETHANDSHAKERESPONSE_P_H
#define QWEBSOCKETHANDSHAKERESPONSE_P_H
@@ -53,6 +17,7 @@
#include <QtCore/QObject>
#include <QtCore/QList>
#include "qwebsocketprotocol.h"
+#include "private/qglobal_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/websockets/qwebsocketprotocol.cpp b/src/websockets/qwebsocketprotocol.cpp
index df87a93..3feddf4 100644
--- a/src/websockets/qwebsocketprotocol.cpp
+++ b/src/websockets/qwebsocketprotocol.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsocketprotocol_p.h"
#include <QtCore/QString>
@@ -172,7 +136,7 @@ QT_BEGIN_NAMESPACE
\internal
*/
-QWebSocketProtocol::Version QWebSocketProtocol::versionFromString(const QString &versionString)
+QWebSocketProtocol::Version QWebSocketProtocol::versionFromString(QStringView versionString)
{
bool ok = false;
Version version = VersionUnknown;
@@ -210,7 +174,7 @@ void QWebSocketProtocol::mask(char *payload, quint64 size, quint32 maskingKey)
quint8((maskingKey & 0x0000FF00u) >> 8),
quint8((maskingKey & 0x000000FFu))
};
- int i = 0;
+ quint64 i = 0;
while (size-- > 0)
*payload++ ^= mask[i++ % 4];
}
diff --git a/src/websockets/qwebsocketprotocol.h b/src/websockets/qwebsocketprotocol.h
index f3af517..ea3bf63 100644
--- a/src/websockets/qwebsocketprotocol.h
+++ b/src/websockets/qwebsocketprotocol.h
@@ -1,45 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETPROTOCOL_H
#define QWEBSOCKETPROTOCOL_H
+#if 0
+# pragma qt_class(QWebSocketProtocol)
+#endif
+
#include <QtCore/qglobal.h>
#include "QtWebSockets/qwebsockets_global.h"
diff --git a/src/websockets/qwebsocketprotocol_p.h b/src/websockets/qwebsocketprotocol_p.h
index 4a8d952..c99d7ca 100644
--- a/src/websockets/qwebsocketprotocol_p.h
+++ b/src/websockets/qwebsocketprotocol_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETPROTOCOL_P_H
#define QWEBSOCKETPROTOCOL_P_H
@@ -51,12 +15,13 @@
// We mean it.
//
-#include <QtCore/qglobal.h>
+#include <QtCore/private/qglobal_p.h>
#include "QtWebSockets/qwebsocketprotocol.h"
+#include <QtCore/qstringview.h>
+
QT_BEGIN_NAMESPACE
-class QString;
class QByteArray;
namespace QWebSocketProtocol
@@ -96,7 +61,7 @@ inline bool isCloseCodeValid(int closeCode)
}
inline Version currentVersion() { return VersionLatest; }
-Version Q_AUTOTEST_EXPORT versionFromString(const QString &versionString);
+Version Q_AUTOTEST_EXPORT versionFromString(QStringView versionString);
void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey);
void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey);
diff --git a/src/websockets/qwebsockets_global.h b/src/websockets/qwebsockets_global.h
index d4b7aca..2af3812 100644
--- a/src/websockets/qwebsockets_global.h
+++ b/src/websockets/qwebsockets_global.h
@@ -1,58 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETSGLOBAL_H
#define QWEBSOCKETSGLOBAL_H
#include <QtCore/qglobal.h>
+#include <QtWebSockets/qtwebsocketsexports.h>
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_WEBSOCKETS_LIB)
-# define Q_WEBSOCKETS_EXPORT Q_DECL_EXPORT
-# else
-# define Q_WEBSOCKETS_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_WEBSOCKETS_EXPORT
-#endif
-
-QT_END_NAMESPACE
#endif // QWEBSOCKETSGLOBAL_H
diff --git a/src/websockets/qwebsocketserver.cpp b/src/websockets/qwebsocketserver.cpp
index a7c6157..0c69d22 100644
--- a/src/websockets/qwebsocketserver.cpp
+++ b/src/websockets/qwebsocketserver.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QWebSocketServer
@@ -65,9 +29,7 @@
Calling close() makes QWebSocketServer stop listening for incoming connections.
- QWebSocketServer currently does not support
- \l {WebSocket Extensions} and
- \l {WebSocket Subprotocols}.
+ QWebSocketServer currently does not support \l {WebSocket Extensions}.
\note When working with self-signed certificates, \l{Firefox bug 594502} prevents \l{Firefox} to
connect to a secure WebSocket server. To work around this problem, first browse to the
@@ -84,7 +46,7 @@
*/
/*!
- \page echoserver.html example
+ \page echoserver.html
\title WebSocket server example
\brief A sample WebSocket server echoing back messages sent to it.
@@ -219,6 +181,47 @@
*/
/*!
+ \fn void QWebSocketServer::alertSent(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
+ \since 6.2
+
+ QWebSocketServer emits this signal if an alert message was sent to a peer. \a level
+ describes if it was a warning or a fatal error. \a type gives the code
+ of the alert message. When a textual description of the alert message is
+ available, it is supplied in \a description.
+
+ \note This signal is mostly informational and can be used for debugging
+ purposes, normally it does not require any actions from the application.
+ \note Not all backends support this functionality.
+
+ \sa alertReceived(), QSsl::AlertLevel, QSsl::AlertType
+*/
+/*!
+ \fn void QWebSocketServer::alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
+ \since 6.2
+
+ QWebSocketServer emits this signal if an alert message was received from a peer.
+ \a level tells if the alert was fatal or it was a warning. \a type is the
+ code explaining why the alert was sent. When a textual description of
+ the alert message is available, it is supplied in \a description.
+
+ \note The signal is mostly for informational and debugging purposes and does not
+ require any handling in the application. If the alert was fatal, underlying
+ backend will handle it and close the connection.
+ \note Not all backends support this functionality.
+
+ \sa alertSent(), QSsl::AlertLevel, QSsl::AlertType
+*/
+/*!
+ \fn void QWebSocketServer::handshakeInterruptedOnError(const QSslError &error)
+ \since 6.2
+
+ QWebSocketServer emits this signal if a certificate verification \a error was
+ found and if early error reporting was enabled in QSslConfiguration.
+
+ \sa sslErrors(), QSslConfiguration::setHandshakeMustInterruptOnError()
+*/
+
+/*!
\enum QWebSocketServer::SslMode
Indicates whether the server operates over wss (SecureMode) or ws (NonSecureMode)
@@ -496,6 +499,26 @@ QString QWebSocketServer::serverName() const
}
/*!
+ \brief Sets the list of protocols supported by the server to \a protocols.
+ \since 6.4
+ */
+void QWebSocketServer::setSupportedSubprotocols(const QStringList &protocols)
+{
+ Q_D(QWebSocketServer);
+ d->setSupportedSubprotocols(protocols);
+}
+
+/*!
+ \brief Returns the list of protocols supported by the server.
+ \since 6.4
+ */
+QStringList QWebSocketServer::supportedSubprotocols() const
+{
+ Q_D(const QWebSocketServer);
+ return d->supportedSubprotocols();
+}
+
+/*!
Returns the server's address if the server is listening for connections; otherwise returns
QHostAddress::Null.
@@ -624,7 +647,6 @@ void QWebSocketServer::setHandshakeTimeout(int msec)
d->setHandshakeTimeout(msec);
}
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
/*!
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
@@ -656,71 +678,34 @@ qintptr QWebSocketServer::socketDescriptor() const
return d->socketDescriptor();
}
-#else // ### Qt 6: Remove leftovers
+#if QT_DEPRECATED_SINCE(6, 2)
/*!
- \deprecated
+ \fn bool QWebSocketServer::setNativeDescriptor(qintptr socketDescriptor)
- Sets the socket descriptor this server should use when listening for incoming connections to
- \a socketDescriptor.
-
- Returns true if the socket is set successfully; otherwise returns false.
- The socket is assumed to be in listening state.
-
- \sa socketDescriptor(), setSocketDescriptor(), nativeDescriptor(), isListening()
- \since 5.3
- */
-bool QWebSocketServer::setSocketDescriptor(int socketDescriptor)
-{
- return setNativeDescriptor(socketDescriptor);
-}
-
-/*!
\deprecated
-
- Returns the native socket descriptor the server uses to listen for incoming instructions,
- or -1 if the server is not listening.
- If the server is using QNetworkProxy, the returned descriptor may not be usable with
- native socket functions.
-
- \sa nativeDescriptor(), setNativeDescriptor(), setSocketDescriptor(), isListening()
- \since 5.3
- */
-int QWebSocketServer::socketDescriptor() const
-{
- return int(nativeDescriptor());
-}
-
-/*!
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
Returns true if the socket is set successfully; otherwise returns false.
The socket is assumed to be in listening state.
- \sa nativeDescriptor(), isListening()
+ \sa nativeDescriptor(), setSocketDescriptor(), isListening()
\since 5.12
*/
-bool QWebSocketServer::setNativeDescriptor(qintptr socketDescriptor)
-{
- Q_D(QWebSocketServer);
- return d->setSocketDescriptor(socketDescriptor);
-}
/*!
+ \fn qintptr QWebSocketServer::nativeDescriptor() const
+
+ \deprecated
Returns the native socket descriptor the server uses to listen for incoming instructions,
or -1 if the server is not listening.
If the server is using QNetworkProxy, the returned descriptor may not be usable with
native socket functions.
- \sa setNativeDescriptor(), isListening()
+ \sa setNativeDescriptor(), socketDescriptor(), isListening()
\since 5.12
*/
-qintptr QWebSocketServer::nativeDescriptor() const
-{
- Q_D(const QWebSocketServer);
- return d->socketDescriptor();
-}
-#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+#endif
/*!
Returns a list of WebSocket versions that this server is supporting.
diff --git a/src/websockets/qwebsocketserver.h b/src/websockets/qwebsocketserver.h
index 5c32ffb..4dd04da 100644
--- a/src/websockets/qwebsocketserver.h
+++ b/src/websockets/qwebsocketserver.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETSERVER_H
#define QWEBSOCKETSERVER_H
@@ -52,7 +16,7 @@
#include <QtNetwork/QSslError>
#endif
-#if QT_HAS_INCLUDE(<chrono>)
+#if __has_include(<chrono>)
#include <chrono>
#endif
@@ -90,7 +54,7 @@ public:
void setMaxPendingConnections(int numConnections);
int maxPendingConnections() const;
-#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC)
+#if __has_include(<chrono>) || defined(Q_QDOC)
void setHandshakeTimeout(std::chrono::milliseconds msec)
{
setHandshakeTimeout(int(msec.count()));
@@ -109,18 +73,14 @@ public:
SslMode secureMode() const;
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool setSocketDescriptor(qintptr socketDescriptor);
qintptr socketDescriptor() const;
+#if QT_DEPRECATED_SINCE(6, 2)
+ QT_DEPRECATED_VERSION_X_6_2("Use setSocketDescriptor instead")
bool setNativeDescriptor(qintptr descriptor) { return setSocketDescriptor(descriptor); }
+ QT_DEPRECATED_VERSION_X_6_2("Use socketDescriptor instead")
qintptr nativeDescriptor() const { return socketDescriptor(); }
-#else // ### Qt 6: Remove leftovers
- Q_DECL_DEPRECATED_X("Use setNativeDescriptor") bool setSocketDescriptor(int socketDescriptor);
- Q_DECL_DEPRECATED_X("Use nativeDescriptor") int socketDescriptor() const;
- bool setNativeDescriptor(qintptr descriptor);
- qintptr nativeDescriptor() const;
-#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
-
+#endif
bool hasPendingConnections() const;
virtual QWebSocket *nextPendingConnection();
@@ -134,6 +94,9 @@ public:
void setServerName(const QString &serverName);
QString serverName() const;
+ void setSupportedSubprotocols(const QStringList &protocols);
+ QStringList supportedSubprotocols() const;
+
#ifndef QT_NO_NETWORKPROXY
void setProxy(const QNetworkProxy &networkProxy);
QNetworkProxy proxy() const;
diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp
index f922098..c8a2e87 100644
--- a/src/websockets/qwebsocketserver_p.cpp
+++ b/src/websockets/qwebsocketserver_p.cpp
@@ -1,54 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebsocketserver.h"
#include "qwebsocketserver_p.h"
-#ifndef QT_NO_SSL
-#include "qsslserver_p.h"
-#endif
#include "qwebsocketprotocol.h"
#include "qwebsockethandshakerequest_p.h"
#include "qwebsockethandshakeresponse_p.h"
#include "qwebsocket.h"
#include "qwebsocket_p.h"
#include "qwebsocketcorsauthenticator.h"
+#include <limits>
+#ifndef QT_NO_SSL
+#include "QtNetwork/QSslServer"
+#endif
#include <QtCore/QTimer>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
@@ -56,12 +21,6 @@
QT_BEGIN_NAMESPACE
-//both constants are taken from the default settings of Apache
-//see: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize and
-//http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfields
-const int MAX_HEADERLINE_LENGTH = 8 * 1024; //maximum length of a http request header line
-const int MAX_HEADERLINES = 100; //maximum number of http request header lines
-
/*!
\internal
*/
@@ -87,32 +46,53 @@ void QWebSocketServerPrivate::init()
if (m_secureMode == NonSecureMode) {
m_pTcpServer = new QTcpServer(q);
if (Q_LIKELY(m_pTcpServer))
- QObjectPrivate::connect(m_pTcpServer, &QTcpServer::newConnection,
- this, &QWebSocketServerPrivate::onNewConnection);
+ QObjectPrivate::connect(m_pTcpServer, &QTcpServer::pendingConnectionAvailable, this,
+ &QWebSocketServerPrivate::onNewConnection);
else
qFatal("Could not allocate memory for tcp server.");
} else {
#ifndef QT_NO_SSL
QSslServer *pSslServer = new QSslServer(q);
m_pTcpServer = pSslServer;
+ // Update the QSslServer with the timeout we have:
+ setHandshakeTimeout(m_handshakeTimeout);
if (Q_LIKELY(m_pTcpServer)) {
- QObjectPrivate::connect(pSslServer, &QSslServer::newEncryptedConnection,
- this, &QWebSocketServerPrivate::onNewConnection,
+ QObjectPrivate::connect(pSslServer, &QTcpServer::pendingConnectionAvailable, this,
+ &QWebSocketServerPrivate::onNewConnection,
Qt::QueuedConnection);
- QObjectPrivate::connect(pSslServer, &QSslServer::startedEncryptionHandshake,
- this, &QWebSocketServerPrivate::startHandshakeTimeout);
QObject::connect(pSslServer, &QSslServer::peerVerifyError,
- q, &QWebSocketServer::peerVerifyError);
+ [q](QSslSocket *socket, const QSslError &error) {
+ Q_UNUSED(socket);
+ Q_EMIT q->peerVerifyError(error);
+ });
QObject::connect(pSslServer, &QSslServer::sslErrors,
- q, &QWebSocketServer::sslErrors);
+ [q](QSslSocket *socket, const QList<QSslError> &errors) {
+ Q_UNUSED(socket);
+ Q_EMIT q->sslErrors(errors);
+ });
QObject::connect(pSslServer, &QSslServer::preSharedKeyAuthenticationRequired,
- q, &QWebSocketServer::preSharedKeyAuthenticationRequired);
+ [q](QSslSocket *socket,
+ QSslPreSharedKeyAuthenticator *authenticator) {
+ Q_UNUSED(socket);
+ Q_EMIT q->preSharedKeyAuthenticationRequired(authenticator);
+ });
QObject::connect(pSslServer, &QSslServer::alertSent,
- q, &QWebSocketServer::alertSent);
+ [q](QSslSocket *socket, QSsl::AlertLevel level,
+ QSsl::AlertType type, const QString &description) {
+ Q_UNUSED(socket);
+ Q_EMIT q->alertSent(level, type, description);
+ });
QObject::connect(pSslServer, &QSslServer::alertReceived,
- q, &QWebSocketServer::alertReceived);
+ [q](QSslSocket *socket, QSsl::AlertLevel level,
+ QSsl::AlertType type, const QString &description) {
+ Q_UNUSED(socket);
+ Q_EMIT q->alertReceived(level, type, description);
+ });
QObject::connect(pSslServer, &QSslServer::handshakeInterruptedOnError,
- q, &QWebSocketServer::handshakeInterruptedOnError);
+ [q](QSslSocket *socket, const QSslError &error) {
+ Q_UNUSED(socket);
+ Q_EMIT q->handshakeInterruptedOnError(error);
+ });
}
#else
qFatal("SSL not supported on this platform.");
@@ -294,6 +274,24 @@ void QWebSocketServerPrivate::setMaxPendingConnections(int numConnections)
/*!
\internal
*/
+void QWebSocketServerPrivate::setHandshakeTimeout(int msec)
+{
+#if QT_CONFIG(ssl)
+ if (auto *server = qobject_cast<QSslServer *>(m_pTcpServer)) {
+ int timeout = msec;
+ // Since QSslServer doesn't deal with negative numbers we set a very
+ // large one instead to keep some level of compatibility:
+ if (timeout < 0)
+ timeout = std::numeric_limits<int>::max();
+ server->setHandshakeTimeout(timeout);
+ }
+#endif
+ m_handshakeTimeout = msec;
+}
+
+/*!
+ \internal
+ */
bool QWebSocketServerPrivate::setSocketDescriptor(qintptr socketDescriptor)
{
return m_pTcpServer->setSocketDescriptor(socketDescriptor);
@@ -320,10 +318,17 @@ QList<QWebSocketProtocol::Version> QWebSocketServerPrivate::supportedVersions()
/*!
\internal
*/
-QStringList QWebSocketServerPrivate::supportedProtocols() const
+void QWebSocketServerPrivate::setSupportedSubprotocols(const QStringList &protocols)
+{
+ m_supportedSubprotocols = protocols;
+}
+
+/*!
+ \internal
+ */
+QStringList QWebSocketServerPrivate::supportedSubprotocols() const
{
- QStringList supportedProtocols;
- return supportedProtocols; //no protocols are currently supported
+ return m_supportedSubprotocols;
}
/*!
@@ -393,8 +398,8 @@ void QWebSocketServerPrivate::onNewConnection()
{
while (m_pTcpServer->hasPendingConnections()) {
QTcpSocket *pTcpSocket = m_pTcpServer->nextPendingConnection();
- if (Q_LIKELY(pTcpSocket) && m_secureMode == NonSecureMode)
- startHandshakeTimeout(pTcpSocket);
+ Q_ASSERT(pTcpSocket);
+ startHandshakeTimeout(pTcpSocket);
handleConnection(pTcpSocket);
}
}
@@ -444,7 +449,8 @@ void QWebSocketServerPrivate::handshakeReceived()
if (endOfHeaderIndex < 0) {
//then we don't have our header complete yet
//check that no one is trying to exhaust our virtual memory
- const qint64 maxHeaderLength = MAX_HEADERLINE_LENGTH * MAX_HEADERLINES + endOfHeaderMarker.size();
+ const qint64 maxHeaderLength = QWebSocketPrivate::MAX_HEADERLINE_LENGTH
+ * QWebSocketPrivate::MAX_HEADERLINES + endOfHeaderMarker.size();
if (Q_UNLIKELY(byteAvailable > maxHeaderLength)) {
pTcpSocket->close();
setError(QWebSocketProtocol::CloseCodeTooMuchData,
@@ -459,7 +465,7 @@ void QWebSocketServerPrivate::handshakeReceived()
bool success = false;
bool isSecure = (m_secureMode == SecureMode);
- if (Q_UNLIKELY(m_pendingConnections.length() >= maxPendingConnections())) {
+ if (Q_UNLIKELY(m_pendingConnections.size() >= maxPendingConnections())) {
pTcpSocket->close();
setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
QWebSocketServer::tr("Too many pending connections."));
@@ -479,8 +485,7 @@ void QWebSocketServerPrivate::handshakeReceived()
}
QWebSocketHandshakeRequest request(pTcpSocket->peerPort(), isSecure);
- QTextStream textStream(header, QIODevice::ReadOnly);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERLINES);
+ request.readHandshake(header, QWebSocketPrivate::MAX_HEADERLINE_LENGTH);
if (request.isValid()) {
QWebSocketCorsAuthenticator corsAuthenticator(request.origin());
@@ -490,7 +495,7 @@ void QWebSocketServerPrivate::handshakeReceived()
m_serverName,
corsAuthenticator.allowed(),
supportedVersions(),
- supportedProtocols(),
+ supportedSubprotocols(),
supportedExtensions());
if (Q_LIKELY(response.isValid())) {
diff --git a/src/websockets/qwebsocketserver_p.h b/src/websockets/qwebsocketserver_p.h
index 1f1cbd9..9941341 100644
--- a/src/websockets/qwebsocketserver_p.h
+++ b/src/websockets/qwebsocketserver_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWEBSOCKETSERVER_P_H
#define QWEBSOCKETSERVER_P_H
@@ -104,14 +68,13 @@ public:
QWebSocketProtocol::CloseCode serverError() const;
quint16 serverPort() const;
void setMaxPendingConnections(int numConnections);
- void setHandshakeTimeout(int msec) {
- m_handshakeTimeout = msec;
- }
+ void setHandshakeTimeout(int msec);
bool setSocketDescriptor(qintptr socketDescriptor);
qintptr socketDescriptor() const;
QList<QWebSocketProtocol::Version> supportedVersions() const;
- QStringList supportedProtocols() const;
+ void setSupportedSubprotocols(const QStringList &protocols);
+ QStringList supportedSubprotocols() const;
QStringList supportedExtensions() const;
void setServerName(const QString &serverName);
@@ -135,6 +98,7 @@ private:
QTcpServer *m_pTcpServer;
QString m_serverName;
SslMode m_secureMode;
+ QStringList m_supportedSubprotocols;
QQueue<QWebSocket *> m_pendingConnections;
QWebSocketProtocol::CloseCode m_error;
QString m_errorString;
diff --git a/src/websockets/websockets.pro b/src/websockets/websockets.pro
deleted file mode 100644
index 87eecc5..0000000
--- a/src/websockets/websockets.pro
+++ /dev/null
@@ -1,52 +0,0 @@
-TARGET = QtWebSockets
-
-QT = core-private network
-
-QMAKE_DOCS = $$PWD/doc/qtwebsockets.qdocconf
-OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator
-OTHER_FILES += doc/snippets/*.cpp
-OTHER_FILES += doc/qtwebsockets.qdocconf
-
-PUBLIC_HEADERS += \
- $$PWD/qwebsockets_global.h \
- $$PWD/qwebsocket.h \
- $$PWD/qwebsocketserver.h \
- $$PWD/qwebsocketprotocol.h \
- $$PWD/qwebsocketcorsauthenticator.h \
- $$PWD/qmaskgenerator.h
-
-PRIVATE_HEADERS += \
- $$PWD/qwebsocket_p.h \
- $$PWD/qwebsocketserver_p.h \
- $$PWD/qwebsocketprotocol_p.h \
- $$PWD/qwebsockethandshakerequest_p.h \
- $$PWD/qwebsockethandshakeresponse_p.h \
- $$PWD/qwebsocketdataprocessor_p.h \
- $$PWD/qwebsocketcorsauthenticator_p.h \
- $$PWD/qwebsocketframe_p.h \
- $$PWD/qdefaultmaskgenerator_p.h
-
-SOURCES += \
- $$PWD/qwebsocket.cpp \
- $$PWD/qwebsocket_p.cpp \
- $$PWD/qwebsocketserver.cpp \
- $$PWD/qwebsocketserver_p.cpp \
- $$PWD/qwebsocketprotocol.cpp \
- $$PWD/qwebsockethandshakerequest.cpp \
- $$PWD/qwebsockethandshakeresponse.cpp \
- $$PWD/qwebsocketdataprocessor.cpp \
- $$PWD/qwebsocketcorsauthenticator.cpp \
- $$PWD/qwebsocketframe.cpp \
- $$PWD/qmaskgenerator.cpp \
- $$PWD/qdefaultmaskgenerator_p.cpp
-
-wasm: SOURCES += $$PWD/qwebsocket_wasm_p.cpp
-
-qtConfig(ssl) {
- SOURCES += $$PWD/qsslserver.cpp
- PRIVATE_HEADERS += $$PWD/qsslserver_p.h
-}
-
-HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
-
-load(qt_module)
diff --git a/tests/.prev_CMakeLists.txt b/tests/.prev_CMakeLists.txt
deleted file mode 100644
index 2214137..0000000
--- a/tests/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-# Generated from tests.pro.
-
-if(QT_BUILD_STANDALONE_TESTS)
- # Add qt_find_package calls for extra dependencies that need to be found when building
- # the standalone tests here.
-endif()
-qt_build_tests()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8825444..5fb41c0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from tests.pro.
if(QT_BUILD_STANDALONE_TESTS)
diff --git a/tests/auto/.prev_CMakeLists.txt b/tests/auto/.prev_CMakeLists.txt
deleted file mode 100644
index 39b8e8d..0000000
--- a/tests/auto/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-# Generated from auto.pro.
-
-add_subdirectory(cmake)
-add_subdirectory(websockets)
-if(TARGET Qt::Quick)
- add_subdirectory(qml)
-endif()
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt
index b9730a2..ce0b7ab 100644
--- a/tests/auto/CMakeLists.txt
+++ b/tests/auto/CMakeLists.txt
@@ -1,6 +1,7 @@
-# Generated from auto.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-# add_subdirectory(cmake) # special case remove
+add_subdirectory(cmake)
add_subdirectory(websockets)
if(TARGET Qt::Quick)
add_subdirectory(qml)
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
deleted file mode 100644
index d96c4a5..0000000
--- a/tests/auto/auto.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += cmake websockets
-
-qtHaveModule(quick) {
- SUBDIRS += qml
-}
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index b80f5d9..d818f45 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -1,14 +1,47 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 2.8)
-
-project(qmake_cmake_files)
+# This is an automatic test for the CMake configuration files.
+# To run it manually,
+# 1) mkdir build # Create a build directory
+# 2) cd build
+# 3) # Run cmake on this directory
+# `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..`
+# 4) ctest # Run ctest
+cmake_minimum_required(VERSION 3.16)
+project(websockets_cmake_tests)
enable_testing()
-find_package(Qt5Core REQUIRED)
+set(required_packages Core WebSockets)
+
+# Setup the test when called as a completely standalone project.
+if(TARGET Qt6::Core)
+ # Tests are built as part of the repository's build tree.
+ # Setup paths so that the Qt packages are found.
+ qt_internal_set_up_build_dir_package_paths()
+endif()
+
+find_package(Qt6 REQUIRED COMPONENTS ${required_packages})
+
+# Setup common test variables which were previously set by ctest_testcase_common.prf.
+set(CMAKE_MODULES_UNDER_TEST "${required_packages}")
-include("${_Qt5CTestMacros}")
+foreach(qt_package ${CMAKE_MODULES_UNDER_TEST})
+ set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}")
+ if(${package_name}_FOUND)
+ set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}")
+ set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}")
+ set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}")
+ endif()
+endforeach()
-test_module_includes(
+include("${_Qt6CTestMacros}")
+
+set(module_includes
WebSockets QWebSocket
)
+
+_qt_internal_test_module_includes(
+ ${module_includes}
+)
diff --git a/tests/auto/cmake/cmake.pro b/tests/auto/cmake/cmake.pro
deleted file mode 100644
index 76e5c3b..0000000
--- a/tests/auto/cmake/cmake.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-
-# Cause make to do nothing.
-TEMPLATE = subdirs
-
-CMAKE_QT_MODULES_UNDER_TEST = websockets
-
-CONFIG += ctest_testcase
diff --git a/tests/auto/qml/.prev_CMakeLists.txt b/tests/auto/qml/.prev_CMakeLists.txt
deleted file mode 100644
index 96eef3f..0000000
--- a/tests/auto/qml/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-# Generated from qml.pro.
-
-if(NOT UIKIT)
- add_subdirectory(qmlwebsockets)
- add_subdirectory(qmlwebsockets_compat)
-endif()
diff --git a/tests/auto/qml/CMakeLists.txt b/tests/auto/qml/CMakeLists.txt
index 8788707..d7bb337 100644
--- a/tests/auto/qml/CMakeLists.txt
+++ b/tests/auto/qml/CMakeLists.txt
@@ -1,6 +1,8 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qml.pro.
if(NOT UIKIT)
add_subdirectory(qmlwebsockets)
- # add_subdirectory(qmlwebsockets_compat) # special case remove
endif()
diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro
deleted file mode 100644
index 8951c55..0000000
--- a/tests/auto/qml/qml.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-
-!uikit: SUBDIRS += qmlwebsockets qmlwebsockets_compat
diff --git a/tests/auto/qml/qmlwebsockets/CMakeLists.txt b/tests/auto/qml/qmlwebsockets/CMakeLists.txt
index ca1557c..b85fc49 100644
--- a/tests/auto/qml/qmlwebsockets/CMakeLists.txt
+++ b/tests/auto/qml/qmlwebsockets/CMakeLists.txt
@@ -1,15 +1,23 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qmlwebsockets.pro.
#####################################################################
## tst_qmlwebsockets Test:
#####################################################################
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ *.qml)
+list(APPEND test_data ${test_data_glob})
-qt_add_test(tst_qmlwebsockets
+qt_internal_add_test(tst_qmlwebsockets
QMLTEST
SOURCES
tst_qmlwebsockets.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
+ TESTDATA ${test_data}
)
#### Keys ignored in scope 1:.:.:qmlwebsockets.pro:<TRUE>:
diff --git a/tests/auto/qml/qmlwebsockets/qmlwebsockets.pro b/tests/auto/qml/qmlwebsockets/qmlwebsockets.pro
deleted file mode 100644
index 9405f37..0000000
--- a/tests/auto/qml/qmlwebsockets/qmlwebsockets.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_qmlwebsockets
-CONFIG += qmltestcase
-CONFIG += console
-SOURCES += tst_qmlwebsockets.cpp
-
-importFiles.path = .
-DEPLOYMENT += importFiles
-
diff --git a/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp b/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp
index 956dda1..6cd24fe 100644
--- a/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp
+++ b/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtQuickTest/quicktest.h>
QUICK_TEST_MAIN(qmlwebsockets)
diff --git a/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.qml b/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.qml
index 66c1ed0..78ecd86 100644
--- a/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.qml
+++ b/tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.qml
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQuick 2.5
import QtWebSockets 1.1
@@ -38,6 +13,8 @@ Rectangle {
id: server
port: 1337
+ supportedSubprotocols: [ "chat", "superchat" ]
+
onClientConnected: {
currentSocket = webSocket;
}
@@ -48,6 +25,7 @@ Rectangle {
WebSocket {
id: socket
url: server.url
+ requestedSubprotocols: [ "superchat", "chat" ]
}
TestCase {
@@ -56,6 +34,10 @@ Rectangle {
socket.active = true;
tryCompare(socket, 'status', WebSocket.Open);
verify(server.currentSocket);
+
+ // Handshake should select client's first preference.
+ compare(socket.negotiatedSubprotocol, "superchat")
+ compare(server.currentSocket.negotiatedSubprotocol, "superchat")
}
function ensureDisconnected() {
diff --git a/tests/auto/qml/qmlwebsockets_compat/qmlwebsockets_compat.pro b/tests/auto/qml/qmlwebsockets_compat/qmlwebsockets_compat.pro
deleted file mode 100644
index 104e6de..0000000
--- a/tests/auto/qml/qmlwebsockets_compat/qmlwebsockets_compat.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_qmlwebsockets_compat
-CONFIG += qmltestcase
-CONFIG += console
-SOURCES += tst_qmlwebsockets_compat.cpp
-
-importFiles.path = .
-DEPLOYMENT += importFiles
-
diff --git a/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.cpp b/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.cpp
deleted file mode 100644
index c0e09cf..0000000
--- a/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtQuickTest/quicktest.h>
-QUICK_TEST_MAIN(qmlwebsockets_compat)
diff --git a/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.qml b/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.qml
deleted file mode 100644
index d9ba35d..0000000
--- a/tests/auto/qml/qmlwebsockets_compat/tst_qmlwebsockets_compat.qml
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 2.5
-import Qt.WebSockets 1.0
-
-Rectangle {
- width: 360
- height: 360
-
- function appendMessage(message) {
- messageBox.text += "\n" + message
- }
-
- WebSocketServer {
- id: server
- }
-
- WebSocket {
- id: socket
- }
-}
diff --git a/tests/auto/websockets/CMakeLists.txt b/tests/auto/websockets/CMakeLists.txt
index 70b99db..28ce40a 100644
--- a/tests/auto/websockets/CMakeLists.txt
+++ b/tests/auto/websockets/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from websockets.pro.
add_subdirectory(qwebsocketcorsauthenticator)
diff --git a/tests/auto/websockets/dataprocessor/CMakeLists.txt b/tests/auto/websockets/dataprocessor/CMakeLists.txt
index 6ea9ed4..bb2bdb7 100644
--- a/tests/auto/websockets/dataprocessor/CMakeLists.txt
+++ b/tests/auto/websockets/dataprocessor/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from dataprocessor.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,10 @@ endif()
## tst_dataprocessor Test:
#####################################################################
-qt_add_test(tst_dataprocessor
+qt_internal_add_test(tst_dataprocessor
SOURCES
tst_dataprocessor.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/dataprocessor/dataprocessor.pro b/tests/auto/websockets/dataprocessor/dataprocessor.pro
deleted file mode 100644
index 907bfeb..0000000
--- a/tests/auto/websockets/dataprocessor/dataprocessor.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_dataprocessor
-
-QT = testlib websockets-private
-
-SOURCES += tst_dataprocessor.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp
index 0e861de..d814cce 100644
--- a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp
+++ b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtTest/QSignalSpy>
@@ -247,20 +222,20 @@ void tst_DataProcessor::goodBinaryFrame()
data.append(char(FIN | QWebSocketProtocol::OpCodeBinary));
- if (payload.length() < 126)
+ if (payload.size() < 126)
{
- data.append(char(payload.length()));
+ data.append(char(payload.size()));
}
- else if (payload.length() < 65536)
+ else if (payload.size() < 65536)
{
- quint16 swapped = qToBigEndian<quint16>(payload.length());
+ quint16 swapped = qToBigEndian<quint16>(payload.size());
const char *wireRepresentation
= static_cast<const char *>(static_cast<const void *>(&swapped));
data.append(char(126)).append(wireRepresentation, 2);
}
else
{
- quint64 swapped = qToBigEndian<quint64>(payload.length());
+ quint64 swapped = qToBigEndian<quint64>(payload.size());
const char *wireRepresentation
= static_cast<const char *>(static_cast<const void *>(&swapped));
data.append(char(127)).append(wireRepresentation, 8);
@@ -281,18 +256,18 @@ void tst_DataProcessor::goodBinaryFrame()
QSignalSpy textFrameReceivedSpy(&dataProcessor, SIGNAL(textFrameReceived(QString,bool)));
QSignalSpy textMessageReceivedSpy(&dataProcessor, SIGNAL(textMessageReceived(QString)));
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), 0);
- QCOMPARE(pongReceivedSpy.count(), 0);
- QCOMPARE(closeReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 1);
- QCOMPARE(binaryMessageReceivedSpy.count(), 1);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), 0);
+ QCOMPARE(pongReceivedSpy.size(), 0);
+ QCOMPARE(closeReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 1);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 1);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
QList<QVariant> arguments = binaryFrameReceivedSpy.takeFirst();
- QCOMPARE(arguments.at(0).toByteArray().length(), payload.length());
+ QCOMPARE(arguments.at(0).toByteArray().size(), payload.size());
arguments = binaryMessageReceivedSpy.takeFirst();
- QCOMPARE(arguments.at(0).toByteArray().length(), payload.length());
+ QCOMPARE(arguments.at(0).toByteArray().size(), payload.size());
buffer.close();
}
@@ -341,20 +316,20 @@ void tst_DataProcessor::goodTextFrame()
data.append(char(FIN | QWebSocketProtocol::OpCodeText));
- if (payload.length() < 126)
+ if (payload.size() < 126)
{
- data.append(char(payload.length()));
+ data.append(char(payload.size()));
}
- else if (payload.length() < 65536)
+ else if (payload.size() < 65536)
{
- quint16 swapped = qToBigEndian<quint16>(payload.length());
+ quint16 swapped = qToBigEndian<quint16>(payload.size());
const char *wireRepresentation
= static_cast<const char *>(static_cast<const void *>(&swapped));
data.append(char(126)).append(wireRepresentation, 2);
}
else
{
- quint64 swapped = qToBigEndian<quint64>(payload.length());
+ quint64 swapped = qToBigEndian<quint64>(payload.size());
const char *wireRepresentation
= static_cast<const char *>(static_cast<const void *>(&swapped));
data.append(char(127)).append(wireRepresentation, 8);
@@ -377,18 +352,18 @@ void tst_DataProcessor::goodTextFrame()
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), 0);
- QCOMPARE(pongReceivedSpy.count(), 0);
- QCOMPARE(closeReceivedSpy.count(), 0);
- QCOMPARE(textFrameReceivedSpy.count(), 1);
- QCOMPARE(textMessageReceivedSpy.count(), 1);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), 0);
+ QCOMPARE(pongReceivedSpy.size(), 0);
+ QCOMPARE(closeReceivedSpy.size(), 0);
+ QCOMPARE(textFrameReceivedSpy.size(), 1);
+ QCOMPARE(textMessageReceivedSpy.size(), 1);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
QList<QVariant> arguments = textFrameReceivedSpy.takeFirst();
- QCOMPARE(arguments.at(0).toString().length(), size);
+ QCOMPARE(arguments.at(0).toString().size(), size);
arguments = textMessageReceivedSpy.takeFirst();
- QCOMPARE(arguments.at(0).toString().length(), size);
+ QCOMPARE(arguments.at(0).toString().size(), size);
buffer.close();
}
@@ -414,14 +389,14 @@ void tst_DataProcessor::goodControlFrame()
buffer.setData(data);
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
- QCOMPARE(closeFrameReceivedSpy.count(), 0);
- QCOMPARE(pongReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), 1);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
+ QCOMPARE(closeFrameReceivedSpy.size(), 0);
+ QCOMPARE(pongReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), 1);
buffer.close();
data.clear();
@@ -432,14 +407,14 @@ void tst_DataProcessor::goodControlFrame()
buffer.setData(data);
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
- QCOMPARE(closeFrameReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), 0);
- QCOMPARE(pongReceivedSpy.count(), 1);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
+ QCOMPARE(closeFrameReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), 0);
+ QCOMPARE(pongReceivedSpy.size(), 1);
buffer.close();
}
@@ -564,14 +539,14 @@ void tst_DataProcessor::goodOpcodes()
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodePing ? 1 : 0);
- QCOMPARE(pongReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodePong ? 1 : 0);
- QCOMPARE(closeReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodeClose ? 1 : 0);
- QCOMPARE(textFrameReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodeText ? 1 : 0);
- QCOMPARE(textMessageReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodeText ? 1 : 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodeBinary ? 1 : 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), opCode == QWebSocketProtocol::OpCodeBinary ? 1 : 0);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodePing ? 1 : 0);
+ QCOMPARE(pongReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodePong ? 1 : 0);
+ QCOMPARE(closeReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodeClose ? 1 : 0);
+ QCOMPARE(textFrameReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodeText ? 1 : 0);
+ QCOMPARE(textMessageReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodeText ? 1 : 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodeBinary ? 1 : 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), opCode == QWebSocketProtocol::OpCodeBinary ? 1 : 0);
buffer.close();
}
@@ -589,7 +564,7 @@ void tst_DataProcessor::goodCloseFrame()
data.append(char(FIN | QWebSocketProtocol::OpCodeClose));
if (swapped != 0)
{
- data.append(char(payload.length() + 2)).append(wireRepresentation, 2).append(payload.toUtf8());
+ data.append(char(payload.size() + 2)).append(wireRepresentation, 2).append(payload.toUtf8());
}
else
{
@@ -613,17 +588,17 @@ void tst_DataProcessor::goodCloseFrame()
dataProcessor.process(&buffer);
- QCOMPARE(errorReceivedSpy.count(), 0);
- QCOMPARE(pingReceivedSpy.count(), 0);
- QCOMPARE(pongReceivedSpy.count(), 0);
- QCOMPARE(closeFrameReceivedSpy.count(), 1);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
+ QCOMPARE(errorReceivedSpy.size(), 0);
+ QCOMPARE(pingReceivedSpy.size(), 0);
+ QCOMPARE(pongReceivedSpy.size(), 0);
+ QCOMPARE(closeFrameReceivedSpy.size(), 1);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
QList<QVariant> arguments = closeFrameReceivedSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(), closeCode);
- QCOMPARE(arguments.at(1).toString().length(), payload.length());
+ QCOMPARE(arguments.at(1).toString().size(), payload.size());
buffer.close();
}
@@ -699,14 +674,14 @@ void tst_DataProcessor::nonCharacterCodes()
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QCOMPARE(errorSpy.count(), 0);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingFrameSpy.count(), 0);
- QCOMPARE(pongFrameSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 1);
- QCOMPARE(textMessageSpy.count(), 1);
- QCOMPARE(binaryFrameSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
+ QCOMPARE(errorSpy.size(), 0);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingFrameSpy.size(), 0);
+ QCOMPARE(pongFrameSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 1);
+ QCOMPARE(textMessageSpy.size(), 1);
+ QCOMPARE(binaryFrameSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
QVariantList arguments = textFrameSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QString>().toUtf8(), payload);
@@ -744,15 +719,15 @@ void tst_DataProcessor::frameTooSmall()
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
QList<QVariant> arguments = errorSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(),
@@ -777,15 +752,15 @@ void tst_DataProcessor::frameTooSmall()
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
arguments = errorSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(),
@@ -810,15 +785,15 @@ void tst_DataProcessor::frameTooSmall()
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 1);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 1);
+ QCOMPARE(binaryFrameSpy.size(), 0);
errorSpy.clear();
closeSpy.clear();
@@ -838,15 +813,15 @@ void tst_DataProcessor::frameTooSmall()
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
QList<QVariant> arguments = errorSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(),
@@ -868,15 +843,15 @@ void tst_DataProcessor::frameTooSmall()
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 1);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 1);
+ QCOMPARE(binaryFrameSpy.size(), 0);
buffer.close();
data.clear();
@@ -897,15 +872,15 @@ void tst_DataProcessor::frameTooSmall()
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(closeSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), 7000);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(closeSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
arguments = errorSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(),
QWebSocketProtocol::CloseCodeGoingAway);
@@ -1380,14 +1355,14 @@ void tst_DataProcessor::invalidPayloadInCloseFrame()
buffer.setData(data);
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QCOMPARE(closeSpy.count(), 1);
- QCOMPARE(errorSpy.count(), 0);
- QCOMPARE(pingMessageSpy.count(), 0);
- QCOMPARE(pongMessageSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QCOMPARE(closeSpy.size(), 1);
+ QCOMPARE(errorSpy.size(), 0);
+ QCOMPARE(pingMessageSpy.size(), 0);
+ QCOMPARE(pongMessageSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
QVariantList arguments = closeSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(), expectedCloseCode);
buffer.close();
@@ -1486,12 +1461,12 @@ void tst_DataProcessor::doTest(int timeout)
buffer.setData(data);
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), timeout);
- QCOMPARE(errorSpy.count(), 1);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), isContinuationFrame ? 1 : 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.size(), timeout);
+ QCOMPARE(errorSpy.size(), 1);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), isContinuationFrame ? 1 : 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
QVariantList arguments = errorSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(), expectedCloseCode);
buffer.close();
@@ -1526,12 +1501,12 @@ void tst_DataProcessor::doCloseFrameTest()
buffer.setData(data);
buffer.open(QIODevice::ReadOnly);
dataProcessor.process(&buffer);
- QCOMPARE(closeSpy.count(), 1);
- QCOMPARE(errorSpy.count(), 0);
- QCOMPARE(textMessageSpy.count(), 0);
- QCOMPARE(binaryMessageSpy.count(), 0);
- QCOMPARE(textFrameSpy.count(), 0);
- QCOMPARE(binaryFrameSpy.count(), 0);
+ QCOMPARE(closeSpy.size(), 1);
+ QCOMPARE(errorSpy.size(), 0);
+ QCOMPARE(textMessageSpy.size(), 0);
+ QCOMPARE(binaryMessageSpy.size(), 0);
+ QCOMPARE(textFrameSpy.size(), 0);
+ QCOMPARE(binaryFrameSpy.size(), 0);
QVariantList arguments = closeSpy.takeFirst();
QCOMPARE(arguments.at(0).value<QWebSocketProtocol::CloseCode>(), expectedCloseCode);
buffer.close();
@@ -1703,7 +1678,7 @@ void tst_DataProcessor::invalidUTF8(const char *dataTag, const char *utf8Sequenc
QTest::newRow(QStringLiteral("Close frame with invalid UTF8-sequence: %1")
.arg(dataTag).toLatin1().constData())
<< quint8(FIN | QWebSocketProtocol::OpCodeClose)
- << quint8(payload.length() + 2)
+ << quint8(payload.size() + 2)
<< QByteArray(wireRepresentation, 2).append(payload)
<< false
<< QWebSocketProtocol::CloseCodeWrongDatatype;
@@ -1713,7 +1688,7 @@ void tst_DataProcessor::invalidUTF8(const char *dataTag, const char *utf8Sequenc
QTest::newRow(QStringLiteral("Text frame with invalid UTF8-sequence: %1")
.arg(dataTag).toLatin1().constData())
<< quint8(FIN | QWebSocketProtocol::OpCodeText)
- << quint8(payload.length())
+ << quint8(payload.size())
<< payload
<< false
<< QWebSocketProtocol::CloseCodeWrongDatatype;
@@ -1721,7 +1696,7 @@ void tst_DataProcessor::invalidUTF8(const char *dataTag, const char *utf8Sequenc
QTest::newRow(QStringLiteral("Continuation text frame with invalid UTF8-sequence: %1")
.arg(dataTag).toLatin1().constData())
<< quint8(FIN | QWebSocketProtocol::OpCodeContinue)
- << quint8(payload.length())
+ << quint8(payload.size())
<< payload
<< true
<< QWebSocketProtocol::CloseCodeWrongDatatype;
@@ -1861,7 +1836,7 @@ void tst_DataProcessor::clearDataBuffers()
const QByteArray binaryData("Hello!");
QByteArray data;
data.append(char(FIN | QWebSocketProtocol::OpCodeBinary));
- data.append(char(binaryData.length()));
+ data.append(char(binaryData.size()));
data.append(binaryData);
QWebSocketDataProcessor dataProcessor;
diff --git a/tests/auto/websockets/handshakerequest/BLACKLIST b/tests/auto/websockets/handshakerequest/BLACKLIST
deleted file mode 100644
index 191f4e8..0000000
--- a/tests/auto/websockets/handshakerequest/BLACKLIST
+++ /dev/null
@@ -1,5 +0,0 @@
-# QTBUG-84315
-[tst_qtbug_57357:invalid-2]
-*
-[tst_qtbug_57357:invalid-4]
-*
diff --git a/tests/auto/websockets/handshakerequest/CMakeLists.txt b/tests/auto/websockets/handshakerequest/CMakeLists.txt
index 2dd3d64..493e0cc 100644
--- a/tests/auto/websockets/handshakerequest/CMakeLists.txt
+++ b/tests/auto/websockets/handshakerequest/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from handshakerequest.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,11 @@ endif()
## tst_handshakerequest Test:
#####################################################################
-qt_add_test(tst_handshakerequest
+qt_internal_add_test(tst_handshakerequest
SOURCES
tst_handshakerequest.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
+ Qt::NetworkPrivate
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/handshakerequest/handshakerequest.pro b/tests/auto/websockets/handshakerequest/handshakerequest.pro
deleted file mode 100644
index b641445..0000000
--- a/tests/auto/websockets/handshakerequest/handshakerequest.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_handshakerequest
-
-QT = testlib websockets-private
-
-SOURCES += tst_handshakerequest.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp b/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
index 230b052..1c0da5c 100644
--- a/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
+++ b/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtCore/QDebug>
@@ -100,30 +75,30 @@ void tst_HandshakeRequest::tst_initialization()
QCOMPARE(request.port(), 0);
QVERIFY(!request.isSecure());
QVERIFY(!request.isValid());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 0);
- QCOMPARE(request.key().length(), 0);
- QCOMPARE(request.origin().length(), 0);
- QCOMPARE(request.host().length(), 0);
+ QCOMPARE(request.key().size(), 0);
+ QCOMPARE(request.origin().size(), 0);
+ QCOMPARE(request.host().size(), 0);
QVERIFY(request.requestUrl().isEmpty());
- QCOMPARE(request.resourceName().length(), 0);
- QCOMPARE(request.versions().length(), 0);
+ QCOMPARE(request.resourceName().size(), 0);
+ QCOMPARE(request.versions().size(), 0);
}
{
QWebSocketHandshakeRequest request(80, true);
QCOMPARE(request.port(), 80);
QVERIFY(request.isSecure());
QVERIFY(!request.isValid());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 0);
- QCOMPARE(request.key().length(), 0);
- QCOMPARE(request.origin().length(), 0);
- QCOMPARE(request.host().length(), 0);
+ QCOMPARE(request.key().size(), 0);
+ QCOMPARE(request.origin().size(), 0);
+ QCOMPARE(request.host().size(), 0);
QVERIFY(request.requestUrl().isEmpty());
- QCOMPARE(request.resourceName().length(), 0);
- QCOMPARE(request.versions().length(), 0);
+ QCOMPARE(request.resourceName().size(), 0);
+ QCOMPARE(request.versions().size(), 0);
}
{
QWebSocketHandshakeRequest request(80, true);
@@ -131,15 +106,15 @@ void tst_HandshakeRequest::tst_initialization()
QCOMPARE(request.port(), 80);
QVERIFY(request.isSecure());
QVERIFY(!request.isValid());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 0);
- QCOMPARE(request.key().length(), 0);
- QCOMPARE(request.origin().length(), 0);
- QCOMPARE(request.host().length(), 0);
+ QCOMPARE(request.key().size(), 0);
+ QCOMPARE(request.origin().size(), 0);
+ QCOMPARE(request.host().size(), 0);
QVERIFY(request.requestUrl().isEmpty());
- QCOMPARE(request.resourceName().length(), 0);
- QCOMPARE(request.versions().length(), 0);
+ QCOMPARE(request.resourceName().size(), 0);
+ QCOMPARE(request.versions().size(), 0);
}
}
@@ -213,25 +188,22 @@ void tst_HandshakeRequest::tst_invalidStream()
QFETCH(QString, dataStream);
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << dataStream;
QWebSocketHandshakeRequest request(80, true);
-
- textStream << dataStream;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QVERIFY(!request.isValid());
QCOMPARE(request.port(), 80);
QVERIFY(request.isSecure());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 0);
- QCOMPARE(request.key().length(), 0);
- QCOMPARE(request.origin().length(), 0);
- QCOMPARE(request.host().length(), 0);
+ QCOMPARE(request.key().size(), 0);
+ QCOMPARE(request.origin().size(), 0);
+ QCOMPARE(request.host().size(), 0);
QVERIFY(request.requestUrl().isEmpty());
- QCOMPARE(request.resourceName().length(), 0);
- QCOMPARE(request.versions().length(), 0);
+ QCOMPARE(request.resourceName().size(), 0);
+ QCOMPARE(request.versions().size(), 0);
}
/*
@@ -249,25 +221,22 @@ void tst_HandshakeRequest::tst_multipleValuesInConnectionHeader()
QStringLiteral("Upgrade: websocket\r\n") +
QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n");
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(80, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QVERIFY(request.isValid());
QCOMPARE(request.port(), 80);
QVERIFY(!request.isSecure());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 5);
- QCOMPARE(request.key().length(), 9);
- QCOMPARE(request.origin().length(), 0);
+ QCOMPARE(request.key().size(), 9);
+ QCOMPARE(request.origin().size(), 0);
QCOMPARE(request.requestUrl(), QUrl("ws://foo.com/test"));
QCOMPARE(request.host(), QStringLiteral("foo.com"));
- QCOMPARE(request.resourceName().length(), 5);
- QCOMPARE(request.versions().length(), 1);
+ QCOMPARE(request.resourceName().size(), 5);
+ QCOMPARE(request.versions().size(), 1);
QCOMPARE(request.versions().at(0), QWebSocketProtocol::Version13);
}
@@ -286,16 +255,13 @@ void tst_HandshakeRequest::tst_parsingWhitespaceInHeaders()
QStringLiteral("Upgrade:websocket \r\n") +
QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n");
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(80, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QVERIFY(request.isValid());
QCOMPARE(request.key(), QStringLiteral("AVD FBDDFF"));
- QCOMPARE(request.versions().length(), 1);
+ QCOMPARE(request.versions().size(), 1);
QCOMPARE(request.versions().at(0), QWebSocketProtocol::Version13);
}
@@ -307,30 +273,27 @@ void tst_HandshakeRequest::tst_multipleVersions()
QStringLiteral("Upgrade: websocket\r\n") +
QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n");
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(80, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QVERIFY(request.isValid());
QCOMPARE(request.port(), 80);
QVERIFY(!request.isSecure());
- QCOMPARE(request.extensions().length(), 0);
- QCOMPARE(request.protocols().length(), 0);
+ QCOMPARE(request.extensions().size(), 0);
+ QCOMPARE(request.protocols().size(), 0);
QCOMPARE(request.headers().size(), 5);
- QVERIFY(request.headers().contains(QStringLiteral("host")));
- QVERIFY(request.headers().contains(QStringLiteral("sec-websocket-version")));
- QVERIFY(request.headers().contains(QStringLiteral("sec-websocket-key")));
- QVERIFY(request.headers().contains(QStringLiteral("upgrade")));
- QVERIFY(request.headers().contains(QStringLiteral("connection")));
+ QVERIFY(request.hasHeader("host"));
+ QVERIFY(request.hasHeader("sec-websocket-version"));
+ QVERIFY(request.hasHeader("sec-websocket-key"));
+ QVERIFY(request.hasHeader("upgrade"));
+ QVERIFY(request.hasHeader("connection"));
QCOMPARE(request.key(), QStringLiteral("AVDFBDDFF"));
- QCOMPARE(request.origin().length(), 0);
+ QCOMPARE(request.origin().size(), 0);
QCOMPARE(request.requestUrl(), QUrl("ws://foo.com/test"));
QCOMPARE(request.host(), QStringLiteral("foo.com"));
- QCOMPARE(request.resourceName().length(), 5);
- QCOMPARE(request.versions().length(), 6);
+ QCOMPARE(request.resourceName().size(), 5);
+ QCOMPARE(request.versions().size(), 6);
//should be 13 since the list is ordered in decreasing order
QCOMPARE(request.versions().at(0), QWebSocketProtocol::Version13);
}
@@ -343,12 +306,9 @@ void tst_HandshakeRequest::tst_qtbug_39355()
QStringLiteral("Upgrade: websocket\r\n") +
QStringLiteral("Connection: Upgrade\r\n\r\n");
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(8080, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QVERIFY(request.isValid());
QCOMPARE(request.port(), 1234);
@@ -366,17 +326,26 @@ void tst_HandshakeRequest::tst_qtbug_48123_data()
QStringLiteral("Connection: Upgrade\r\n");
const int numHeaderLines = header.count(QStringLiteral("\r\n")) - 1; //-1: exclude requestline
- //a headerline should not be larger than MAX_HEADERLINE_LENGTH characters (excluding CRLF)
+ // a headerline must contain colon
QString illegalHeader = header;
- illegalHeader.append(QString(MAX_HEADERLINE_LENGTH + 1, QLatin1Char('c')));
+ illegalHeader.append(QString(MAX_HEADERLINE_LENGTH, QLatin1Char('c')));
illegalHeader.append(QStringLiteral("\r\n\r\n"));
- QTest::newRow("headerline too long") << illegalHeader << false;
+ QTest::newRow("headerline missing colon") << illegalHeader << false;
+
+ // a headerline should not be larger than MAX_HEADERLINE_LENGTH characters (excluding CRLF)
+ QString tooLongHeader = header;
+ QString fieldName = "Too-long: ";
+ tooLongHeader.append(fieldName);
+ tooLongHeader.append(QString(MAX_HEADERLINE_LENGTH + 1 - fieldName.size(), QLatin1Char('c')));
+ tooLongHeader.append(QStringLiteral("\r\n\r\n"));
+
+ QTest::newRow("headerline too long") << tooLongHeader << false;
QString legalHeader = header;
const QString headerKey = QStringLiteral("X-CUSTOM-KEY: ");
legalHeader.append(headerKey);
- legalHeader.append(QString(MAX_HEADERLINE_LENGTH - headerKey.length(), QLatin1Char('c')));
+ legalHeader.append(QString(MAX_HEADERLINE_LENGTH - headerKey.size(), QLatin1Char('c')));
legalHeader.append(QStringLiteral("\r\n\r\n"));
QTest::newRow("headerline with maximum length") << legalHeader << true;
@@ -408,12 +377,9 @@ void tst_HandshakeRequest::tst_qtbug_48123()
QFETCH(bool, shouldBeValid);
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(8080, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QCOMPARE(request.isValid(), shouldBeValid);
}
@@ -504,12 +470,9 @@ void tst_HandshakeRequest::tst_qtbug_57357()
QFETCH(int, port);
QByteArray data;
- QTextStream textStream(&data);
+ QTextStream(&data) << header;
QWebSocketHandshakeRequest request(8080, false);
-
- textStream << header;
- textStream.seek(0);
- request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+ request.readHandshake(data, MAX_HEADERLINE_LENGTH);
QCOMPARE(request.isValid(), valid);
if (valid) {
diff --git a/tests/auto/websockets/handshakeresponse/CMakeLists.txt b/tests/auto/websockets/handshakeresponse/CMakeLists.txt
index 82b84e0..280d1d6 100644
--- a/tests/auto/websockets/handshakeresponse/CMakeLists.txt
+++ b/tests/auto/websockets/handshakeresponse/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from handshakeresponse.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,11 @@ endif()
## tst_handshakeresponse Test:
#####################################################################
-qt_add_test(tst_handshakeresponse
+qt_internal_add_test(tst_handshakeresponse
SOURCES
tst_handshakeresponse.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
+ Qt::NetworkPrivate
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/handshakeresponse/handshakeresponse.pro b/tests/auto/websockets/handshakeresponse/handshakeresponse.pro
deleted file mode 100644
index 61ff2f7..0000000
--- a/tests/auto/websockets/handshakeresponse/handshakeresponse.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_handshakeresponse
-
-QT = testlib websockets-private
-
-SOURCES += tst_handshakeresponse.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp b/tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp
index 9a7c590..797a195 100644
--- a/tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp
+++ b/tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtCore/QDebug>
@@ -81,13 +56,11 @@ void tst_HandshakeResponse::cleanup()
void tst_HandshakeResponse::tst_date_response()
{
QWebSocketHandshakeRequest request(80, false);
- QString buffer;
- QTextStream input(&buffer);
- input << QStringLiteral("GET / HTTP/1.1\r\nHost: example.com\r\nSec-WebSocket-Version: 13\r\n") +
- QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") +
- QStringLiteral("Upgrade: websocket\r\n") +
- QStringLiteral("Connection: Upgrade\r\n\r\n");
- request.readHandshake(input, 8 * 1024, 100);
+ QByteArray bytes = "GET / HTTP/1.1\r\nHost: example.com\r\nSec-WebSocket-Version: 13\r\n"
+ "Sec-WebSocket-Key: AVDFBDDFF\r\n"
+ "Upgrade: websocket\r\n"
+ "Connection: Upgrade\r\n\r\n";
+ request.readHandshake(bytes, 8 * 1024);
QWebSocketHandshakeResponse response(request, "example.com", true,
QList<QWebSocketProtocol::Version>() << QWebSocketProtocol::Version13,
diff --git a/tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt b/tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt
index 9d12b6a..ddadeb9 100644
--- a/tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt
+++ b/tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qdefaultmaskgenerator.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,10 @@ endif()
## tst_defaultmaskgenerator Test:
#####################################################################
-qt_add_test(tst_defaultmaskgenerator
+qt_internal_add_test(tst_defaultmaskgenerator
SOURCES
tst_defaultmaskgenerator.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/qdefaultmaskgenerator/qdefaultmaskgenerator.pro b/tests/auto/websockets/qdefaultmaskgenerator/qdefaultmaskgenerator.pro
deleted file mode 100644
index 07ea14d..0000000
--- a/tests/auto/websockets/qdefaultmaskgenerator/qdefaultmaskgenerator.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_defaultmaskgenerator
-
-QT = testlib websockets-private
-
-SOURCES += tst_defaultmaskgenerator.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp b/tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp
index a09bc95..82ebf2a 100644
--- a/tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp
+++ b/tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtTest/QSignalSpy>
diff --git a/tests/auto/websockets/qwebsocket/CMakeLists.txt b/tests/auto/websockets/qwebsocket/CMakeLists.txt
index ef9a63b..a70d61b 100644
--- a/tests/auto/websockets/qwebsocket/CMakeLists.txt
+++ b/tests/auto/websockets/qwebsocket/CMakeLists.txt
@@ -1,15 +1,31 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qwebsocket.pro.
#####################################################################
## tst_qwebsocket Test:
#####################################################################
-qt_add_test(tst_qwebsocket
+qt_internal_add_test(tst_qwebsocket
SOURCES
tst_qwebsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSockets
)
+set(qwebsocketshared_resource_files
+ "../shared/localhost.cert"
+ "../shared/localhost.key"
+)
+qt_internal_add_resource(tst_qwebsocket "qwebsocketshared"
+ PREFIX
+ "/"
+ BASE
+ "../shared"
+ FILES
+ ${qwebsocketshared_resource_files}
+)
+
#### Keys ignored in scope 1:.:.:qwebsocket.pro:<TRUE>:
# TEMPLATE = "app"
diff --git a/tests/auto/websockets/qwebsocket/qwebsocket.pro b/tests/auto/websockets/qwebsocket/qwebsocket.pro
deleted file mode 100644
index df143d5..0000000
--- a/tests/auto/websockets/qwebsocket/qwebsocket.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-QT = testlib websockets
-
-TARGET = tst_qwebsocket
-
-TEMPLATE = app
-
-SOURCES += tst_qwebsocket.cpp
diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
index 329419c..6881afb 100644
--- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
@@ -1,40 +1,32 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+#include <QRegularExpression>
#include <QString>
#include <QtTest>
#include <QtWebSockets/QWebSocket>
+#include <QtWebSockets/QWebSocketHandshakeOptions>
+#include <QtWebSockets/QWebSocketCorsAuthenticator>
#include <QtWebSockets/QWebSocketServer>
#include <QtWebSockets/qwebsocketprotocol.h>
+#include <QtNetwork/qtcpserver.h>
+#include <QtNetwork/qauthenticator.h>
+#include <QtNetwork/qtcpsocket.h>
+
+#if QT_CONFIG(ssl)
+#include <QtNetwork/qsslserver.h>
+#include <QtNetwork/qsslcertificate.h>
+#include <QtNetwork/qsslkey.h>
+#endif
+
+#include <utility>
+
QT_USE_NAMESPACE
Q_DECLARE_METATYPE(QWebSocketProtocol::Version)
+using namespace Qt::StringLiterals;
+
class EchoServer : public QObject
{
Q_OBJECT
@@ -50,6 +42,7 @@ public:
Q_SIGNALS:
void newConnection(QUrl requestUrl);
void newConnection(QNetworkRequest request);
+ void originAuthenticationRequired(QWebSocketCorsAuthenticator* pAuthenticator);
private Q_SLOTS:
void onNewConnection();
@@ -72,9 +65,13 @@ EchoServer::EchoServer(QObject *parent, quint64 maxAllowedIncomingMessageSize, q
m_maxAllowedIncomingFrameSize(maxAllowedIncomingFrameSize),
m_clients()
{
+ m_pWebSocketServer->setSupportedSubprotocols({ QStringLiteral("protocol1"),
+ QStringLiteral("protocol2") });
if (m_pWebSocketServer->listen(QHostAddress(QStringLiteral("127.0.0.1")))) {
connect(m_pWebSocketServer, SIGNAL(newConnection()),
this, SLOT(onNewConnection()));
+ connect(m_pWebSocketServer, &QWebSocketServer::originAuthenticationRequired,
+ this, &EchoServer::originAuthenticationRequired);
}
}
@@ -146,16 +143,23 @@ private Q_SLOTS:
void tst_sendTextMessage();
void tst_sendBinaryMessage();
void tst_errorString();
+ void tst_openRequest_data();
void tst_openRequest();
+ void tst_protocolAccessor();
+ void protocolsHeaderGeneration_data();
+ void protocolsHeaderGeneration();
void tst_moveToThread();
void tst_moveToThreadNoWarning();
#ifndef QT_NO_NETWORKPROXY
void tst_setProxy();
#endif
+ void authenticationRequired_data();
+ void authenticationRequired();
void overlongCloseReason();
void incomingMessageTooLong();
void incomingFrameTooLong();
void testingFrameAndMessageSizeApi();
+ void customHeader();
};
tst_QWebSocket::tst_QWebSocket()
@@ -324,17 +328,17 @@ void tst_QWebSocket::tst_invalidOpen()
QCOMPARE(socket.sendTextMessage(QStringLiteral("A text message")), 0);
QCOMPARE(socket.sendBinaryMessage(QByteArrayLiteral("A text message")), 0);
- if (errorSpy.count() == 0)
+ if (errorSpy.size() == 0)
QVERIFY(errorSpy.wait());
- QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorSpy.size(), 1);
QList<QVariant> arguments = errorSpy.takeFirst();
QAbstractSocket::SocketError socketError =
qvariant_cast<QAbstractSocket::SocketError>(arguments.at(0));
QCOMPARE(socketError, QAbstractSocket::ConnectionRefusedError);
- QCOMPARE(aboutToCloseSpy.count(), 0);
- QCOMPARE(connectedSpy.count(), 0);
- QCOMPARE(disconnectedSpy.count(), disconnectedCount);
- QCOMPARE(stateChangedSpy.count(), stateChangedCount);
+ QCOMPARE(aboutToCloseSpy.size(), 0);
+ QCOMPARE(connectedSpy.size(), 0);
+ QCOMPARE(disconnectedSpy.size(), disconnectedCount);
+ QCOMPARE(stateChangedSpy.size(), stateChangedCount);
if (stateChangedCount == 2) {
arguments = stateChangedSpy.takeFirst();
QAbstractSocket::SocketState socketState =
@@ -343,13 +347,13 @@ void tst_QWebSocket::tst_invalidOpen()
socketState = qvariant_cast<QAbstractSocket::SocketState>(arguments.at(0));
QCOMPARE(socketState, QAbstractSocket::UnconnectedState);
}
- QCOMPARE(readChannelFinishedSpy.count(), 0);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
- QCOMPARE(pongSpy.count(), 0);
- QCOMPARE(bytesWrittenSpy.count(), 0);
+ QCOMPARE(readChannelFinishedSpy.size(), 0);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
+ QCOMPARE(pongSpy.size(), 0);
+ QCOMPARE(bytesWrittenSpy.size(), 0);
}
void tst_QWebSocket::tst_invalidOrigin()
@@ -390,28 +394,28 @@ void tst_QWebSocket::tst_invalidOrigin()
QVERIFY(errorSpy.wait());
- QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorSpy.size(), 1);
QList<QVariant> arguments = errorSpy.takeFirst();
QAbstractSocket::SocketError socketError =
qvariant_cast<QAbstractSocket::SocketError>(arguments.at(0));
QCOMPARE(socketError, QAbstractSocket::ConnectionRefusedError);
- QCOMPARE(aboutToCloseSpy.count(), 0);
- QCOMPARE(connectedSpy.count(), 0);
- QCOMPARE(disconnectedSpy.count(), 1);
- QCOMPARE(stateChangedSpy.count(), 2); //connectingstate, unconnectedstate
+ QCOMPARE(aboutToCloseSpy.size(), 0);
+ QCOMPARE(connectedSpy.size(), 0);
+ QCOMPARE(disconnectedSpy.size(), 1);
+ QCOMPARE(stateChangedSpy.size(), 2); //connectingstate, unconnectedstate
arguments = stateChangedSpy.takeFirst();
QAbstractSocket::SocketState socketState =
qvariant_cast<QAbstractSocket::SocketState>(arguments.at(0));
arguments = stateChangedSpy.takeFirst();
socketState = qvariant_cast<QAbstractSocket::SocketState>(arguments.at(0));
QCOMPARE(socketState, QAbstractSocket::UnconnectedState);
- QCOMPARE(readChannelFinishedSpy.count(), 0);
- QCOMPARE(textFrameReceivedSpy.count(), 0);
- QCOMPARE(binaryFrameReceivedSpy.count(), 0);
- QCOMPARE(textMessageReceivedSpy.count(), 0);
- QCOMPARE(binaryMessageReceivedSpy.count(), 0);
- QCOMPARE(pongSpy.count(), 0);
- QCOMPARE(bytesWrittenSpy.count(), 0);
+ QCOMPARE(readChannelFinishedSpy.size(), 0);
+ QCOMPARE(textFrameReceivedSpy.size(), 0);
+ QCOMPARE(binaryFrameReceivedSpy.size(), 0);
+ QCOMPARE(textMessageReceivedSpy.size(), 0);
+ QCOMPARE(binaryMessageReceivedSpy.size(), 0);
+ QCOMPARE(pongSpy.size(), 0);
+ QCOMPARE(bytesWrittenSpy.size(), 0);
}
void tst_QWebSocket::tst_sendTextMessage()
@@ -440,8 +444,8 @@ void tst_QWebSocket::tst_sendTextMessage()
socket.open(url);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QCOMPARE(socketError.count(), 0);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QCOMPARE(socketError.size(), 0);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
QList<QVariant> arguments = serverConnectedSpy.takeFirst();
QUrl urlConnected = arguments.at(0).toUrl();
@@ -454,14 +458,14 @@ void tst_QWebSocket::tst_sendTextMessage()
QVERIFY(textMessageReceived.wait(500));
QCOMPARE(socket.bytesToWrite(), 0);
- QCOMPARE(textMessageReceived.count(), 1);
- QCOMPARE(binaryMessageReceived.count(), 0);
- QCOMPARE(binaryFrameReceived.count(), 0);
+ QCOMPARE(textMessageReceived.size(), 1);
+ QCOMPARE(binaryMessageReceived.size(), 0);
+ QCOMPARE(binaryFrameReceived.size(), 0);
arguments = textMessageReceived.takeFirst();
QString messageReceived = arguments.at(0).toString();
QCOMPARE(messageReceived, QStringLiteral("Hello world!"));
- QCOMPARE(textFrameReceived.count(), 1);
+ QCOMPARE(textFrameReceived.size(), 1);
arguments = textFrameReceived.takeFirst();
QString frameReceived = arguments.at(0).toString();
bool isLastFrame = arguments.at(1).toBool();
@@ -476,8 +480,8 @@ void tst_QWebSocket::tst_sendTextMessage()
// QTBUG-74464 QWebsocket doesn't receive text (binary) message with size > 32 kb
socket.open(url);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QCOMPARE(socketError.count(), 0);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QCOMPARE(socketError.size(), 0);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
arguments = serverConnectedSpy.takeFirst();
urlConnected = arguments.at(0).toUrl();
@@ -487,16 +491,16 @@ void tst_QWebSocket::tst_sendTextMessage()
// transmit a long text message with 1 MB
QString longString(0x100000, 'a');
socket.sendTextMessage(longString);
- QVERIFY(socket.bytesToWrite() > longString.length());
+ QVERIFY(socket.bytesToWrite() > longString.size());
QVERIFY(textMessageReceived.wait());
QCOMPARE(socket.bytesToWrite(), 0);
- QCOMPARE(textMessageReceived.count(), 1);
- QCOMPARE(binaryMessageReceived.count(), 0);
- QCOMPARE(binaryFrameReceived.count(), 0);
+ QCOMPARE(textMessageReceived.size(), 1);
+ QCOMPARE(binaryMessageReceived.size(), 0);
+ QCOMPARE(binaryFrameReceived.size(), 0);
arguments = textMessageReceived.takeFirst();
messageReceived = arguments.at(0).toString();
- QCOMPARE(messageReceived.length(), longString.length());
+ QCOMPARE(messageReceived.size(), longString.size());
QCOMPARE(messageReceived, longString);
arguments = textFrameReceived.takeLast();
@@ -512,20 +516,20 @@ void tst_QWebSocket::tst_sendTextMessage()
socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port())));
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
socket.sendTextMessage(QStringLiteral("Hello world!"));
QVERIFY(textMessageReceived.wait(500));
- QCOMPARE(textMessageReceived.count(), 1);
- QCOMPARE(binaryMessageReceived.count(), 0);
- QCOMPARE(binaryFrameReceived.count(), 0);
+ QCOMPARE(textMessageReceived.size(), 1);
+ QCOMPARE(binaryMessageReceived.size(), 0);
+ QCOMPARE(binaryFrameReceived.size(), 0);
arguments = textMessageReceived.takeFirst();
messageReceived = arguments.at(0).toString();
QCOMPARE(messageReceived, QStringLiteral("Hello world!"));
- QCOMPARE(textFrameReceived.count(), 1);
+ QCOMPARE(textFrameReceived.size(), 1);
arguments = textFrameReceived.takeFirst();
frameReceived = arguments.at(0).toString();
isLastFrame = arguments.at(1).toBool();
@@ -556,7 +560,7 @@ void tst_QWebSocket::tst_sendBinaryMessage()
socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port())));
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
QCOMPARE(socket.bytesToWrite(), 0);
@@ -566,14 +570,14 @@ void tst_QWebSocket::tst_sendBinaryMessage()
QVERIFY(binaryMessageReceived.wait(500));
QCOMPARE(socket.bytesToWrite(), 0);
- QCOMPARE(textMessageReceived.count(), 0);
- QCOMPARE(textFrameReceived.count(), 0);
- QCOMPARE(binaryMessageReceived.count(), 1);
+ QCOMPARE(textMessageReceived.size(), 0);
+ QCOMPARE(textFrameReceived.size(), 0);
+ QCOMPARE(binaryMessageReceived.size(), 1);
QList<QVariant> arguments = binaryMessageReceived.takeFirst();
QByteArray messageReceived = arguments.at(0).toByteArray();
QCOMPARE(messageReceived, QByteArrayLiteral("Hello world!"));
- QCOMPARE(binaryFrameReceived.count(), 1);
+ QCOMPARE(binaryFrameReceived.size(), 1);
arguments = binaryFrameReceived.takeFirst();
QByteArray frameReceived = arguments.at(0).toByteArray();
bool isLastFrame = arguments.at(1).toBool();
@@ -590,20 +594,20 @@ void tst_QWebSocket::tst_sendBinaryMessage()
socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port())));
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
socket.sendBinaryMessage(QByteArrayLiteral("Hello world!"));
QVERIFY(binaryMessageReceived.wait(500));
- QCOMPARE(textMessageReceived.count(), 0);
- QCOMPARE(textFrameReceived.count(), 0);
- QCOMPARE(binaryMessageReceived.count(), 1);
+ QCOMPARE(textMessageReceived.size(), 0);
+ QCOMPARE(textFrameReceived.size(), 0);
+ QCOMPARE(binaryMessageReceived.size(), 1);
arguments = binaryMessageReceived.takeFirst();
messageReceived = arguments.at(0).toByteArray();
QCOMPARE(messageReceived, QByteArrayLiteral("Hello world!"));
- QCOMPARE(binaryFrameReceived.count(), 1);
+ QCOMPARE(binaryFrameReceived.size(), 1);
arguments = binaryFrameReceived.takeFirst();
frameReceived = arguments.at(0).toByteArray();
isLastFrame = arguments.at(1).toBool();
@@ -623,16 +627,63 @@ void tst_QWebSocket::tst_errorString()
socket.open(QUrl(QStringLiteral("ws://someserver.on.mars:9999")));
- QTRY_COMPARE_WITH_TIMEOUT(errorSpy.count(), 1, 10000);
+ QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 10000);
QList<QVariant> arguments = errorSpy.takeFirst();
QAbstractSocket::SocketError socketError =
qvariant_cast<QAbstractSocket::SocketError>(arguments.at(0));
QCOMPARE(socketError, QAbstractSocket::HostNotFoundError);
QCOMPARE(socket.errorString(), QStringLiteral("Host not found"));
+
+ // Check that handshake status code is parsed. The error is triggered by
+ // refusing the origin authentication
+ EchoServer echoServer;
+ errorSpy.clear();
+ QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected()));
+ QSignalSpy serverConnectedSpy(&echoServer, SIGNAL(newConnection(QUrl)));
+ connect(&echoServer, &EchoServer::originAuthenticationRequired,
+ &socket, [](QWebSocketCorsAuthenticator* pAuthenticator){
+ pAuthenticator->setAllowed(false);
+ });
+
+ socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
+ QStringLiteral(":") + QString::number(echoServer.port())));
+ QTRY_VERIFY(errorSpy.size() > 0);
+ QCOMPARE(serverConnectedSpy.size(), 0);
+ QCOMPARE(socketConnectedSpy.size(), 0);
+ QCOMPARE(socket.errorString(),
+ QStringLiteral("QWebSocketPrivate::processHandshake: Unhandled http status code: 403"
+ " (Access Forbidden)."));
+}
+
+void tst_QWebSocket::tst_openRequest_data()
+{
+ QTest::addColumn<QStringList>("subprotocols");
+ QTest::addColumn<QString>("subprotocolHeader");
+ QTest::addColumn<QRegularExpression>("warningExpression");
+
+ QTest::addRow("no subprotocols") << QStringList{} << QString{} << QRegularExpression{};
+ QTest::addRow("single subprotocol") << QStringList{"foobar"} << QStringLiteral("foobar")
+ << QRegularExpression{};
+ QTest::addRow("multiple subprotocols") << QStringList{"foo", "bar"}
+ << QStringLiteral("foo, bar")
+ << QRegularExpression{};
+ QTest::addRow("subprotocol with whitespace")
+ << QStringList{"chat", "foo\r\nbar with space"}
+ << QStringLiteral("chat")
+ << QRegularExpression{".*invalid.*bar with space"};
+
+ QTest::addRow("subprotocol with invalid chars")
+ << QStringList{"chat", "foo{}"}
+ << QStringLiteral("chat")
+ << QRegularExpression{".*invalid.*foo"};
}
void tst_QWebSocket::tst_openRequest()
{
+ QFETCH(QStringList, subprotocols);
+ QFETCH(QString, subprotocolHeader);
+ QFETCH(QRegularExpression, warningExpression);
+
EchoServer echoServer;
QWebSocket socket;
@@ -647,18 +698,119 @@ void tst_QWebSocket::tst_openRequest()
url.setQuery(query);
QNetworkRequest req(url);
req.setRawHeader("X-Custom-Header", "A custom header");
- socket.open(req);
+ QWebSocketHandshakeOptions options;
+ options.setSubprotocols(subprotocols);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QTRY_COMPARE(serverRequestSpy.count(), 1);
+ if (!warningExpression.pattern().isEmpty())
+ QTest::ignoreMessage(QtWarningMsg, warningExpression);
+
+ socket.open(req, options);
+
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QTRY_COMPARE(serverRequestSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
QList<QVariant> arguments = serverRequestSpy.takeFirst();
QNetworkRequest requestConnected = arguments.at(0).value<QNetworkRequest>();
QCOMPARE(requestConnected.url(), req.url());
QCOMPARE(requestConnected.rawHeader("X-Custom-Header"), req.rawHeader("X-Custom-Header"));
+
+ if (subprotocols.isEmpty())
+ QVERIFY(!requestConnected.hasRawHeader("Sec-WebSocket-Protocol"));
+ else
+ QCOMPARE(requestConnected.rawHeader("Sec-WebSocket-Protocol"), subprotocolHeader);
+
+
+ socket.close();
+}
+
+void tst_QWebSocket::tst_protocolAccessor()
+{
+ EchoServer echoServer;
+
+ QWebSocket socket;
+
+ QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
+ QLatin1Char(':') + QString::number(echoServer.port()));
+
+ QWebSocketHandshakeOptions options;
+ options.setSubprotocols({ "foo", "protocol2" });
+
+ socket.open(url, options);
+
+ QTRY_COMPARE(socket.state(), QAbstractSocket::ConnectedState);
+
+ QCOMPARE(socket.subprotocol(), "protocol2");
+
socket.close();
}
+void tst_QWebSocket::protocolsHeaderGeneration_data()
+{
+ QTest::addColumn<QStringList>("subprotocols");
+ QTest::addColumn<int>("numInvalidEntries");
+
+ using QSL = QStringList;
+ QTest::addRow("all-invalid") << QSL{ "hello?", "------,,,,------" } << 2;
+ QTest::addRow("one-valid") << QSL{ "hello?", "ImValid" } << 1;
+ QTest::addRow("all-valid") << QSL{ "hello", "ImValid" } << 0;
+}
+
+// We test that the Sec-WebSocket-Protocol header is generated normally in presence
+// of one or more invalid entries. That is, it should not be included at all
+// if there are no valid entries, and there should be no separators with only
+// one valid entry.
+void tst_QWebSocket::protocolsHeaderGeneration()
+{
+ QFETCH(const QStringList, subprotocols);
+ QFETCH(const int, numInvalidEntries);
+ const bool containsValidEntry = numInvalidEntries != subprotocols.size();
+
+ QTcpServer tcpServer;
+ QVERIFY(tcpServer.listen());
+
+ QWebSocket socket;
+
+ QUrl url = QUrl("ws://127.0.0.1:%1"_L1.arg(QString::number(tcpServer.serverPort())));
+
+ QWebSocketHandshakeOptions options;
+ options.setSubprotocols(subprotocols);
+
+ QCOMPARE(options.subprotocols().size(), subprotocols.size());
+ for (int i = 0; i < numInvalidEntries; ++i) {
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg,
+ QRegularExpression("Ignoring invalid WebSocket subprotocol name \".*\""));
+ }
+ socket.open(url, options);
+
+ QTRY_VERIFY(tcpServer.hasPendingConnections());
+ QTcpSocket *serverSocket = tcpServer.nextPendingConnection();
+ QVERIFY(serverSocket);
+
+ bool hasSeenHeader = false;
+ while (serverSocket->state() == QAbstractSocket::ConnectedState) {
+ if (!serverSocket->canReadLine()) {
+ QTRY_VERIFY2(serverSocket->canReadLine(),
+ "Reached end-of-data without seeing end-of-header!");
+ }
+ const QByteArray fullLine = serverSocket->readLine();
+ QByteArrayView line = fullLine;
+ if (line == "\r\n") // End-of-Header
+ break;
+ QByteArrayView headerPrefix = "Sec-WebSocket-Protocol:";
+ if (line.size() < headerPrefix.size())
+ continue;
+ if (line.first(headerPrefix.size()).compare(headerPrefix, Qt::CaseInsensitive) != 0)
+ continue;
+ hasSeenHeader = true;
+ QByteArrayView protocols = line.sliced(headerPrefix.size()).trimmed();
+ QVERIFY(!protocols.empty());
+ QCOMPARE(protocols.count(','), subprotocols.size() - numInvalidEntries - 1);
+ // Keep going in case we encounter the header again
+ }
+ QCOMPARE(hasSeenHeader, containsValidEntry);
+ serverSocket->disconnectFromHost();
+}
+
class WebSocket : public QWebSocket
{
Q_OBJECT
@@ -730,7 +882,7 @@ void tst_QWebSocket::tst_moveToThread()
url.setQuery(query);
socket->asyncOpen(url);
- if (socketConnectedSpy.count() == 0)
+ if (socketConnectedSpy.size() == 0)
QVERIFY(socketConnectedSpy.wait(500));
socket->asyncSendTextMessage(textMessage);
@@ -779,6 +931,309 @@ void tst_QWebSocket::tst_setProxy()
socket.setProxy(proxy);
QCOMPARE(socket.proxy(), proxy);
}
+#endif // QT_NO_NETWORKPROXY
+
+class AuthServer : public QTcpServer
+{
+ Q_OBJECT
+public:
+ AuthServer()
+ {
+ connect(this, &QTcpServer::pendingConnectionAvailable, this, &AuthServer::handleConnection);
+ }
+
+ void incomingConnection(qintptr sockfd) override
+ {
+ if (withEncryption) {
+#if QT_CONFIG(ssl)
+ auto *sslSocket = new QSslSocket(this);
+ connect(sslSocket, &QSslSocket::encrypted, this,
+ [this, sslSocket]() {
+ addPendingConnection(sslSocket);
+ });
+ sslSocket->setSslConfiguration(configuration);
+ sslSocket->setSocketDescriptor(sockfd);
+ sslSocket->startServerEncryption();
+#else
+ QFAIL("withEncryption should not be 'true' if we don't have TLS");
+#endif
+ } else {
+ QTcpSocket *socket = new QTcpSocket(this);
+ socket->setSocketDescriptor(sockfd);
+ addPendingConnection(socket);
+ }
+ }
+
+ void handleConnection()
+ {
+ QTcpSocket *serverSocket = nextPendingConnection();
+ connect(serverSocket, &QTcpSocket::readyRead, this, &AuthServer::handleReadyRead);
+ }
+
+ void handleReadyRead()
+ {
+ auto *serverSocket = qobject_cast<QTcpSocket *>(sender());
+ incomingData.append(serverSocket->readAll());
+ if (finished) {
+ qWarning() << "Unexpected trailing data..." << incomingData;
+ return;
+ }
+ if (!incomingData.contains("\r\n\r\n")) {
+ qDebug("Not all of the data arrived at once, waiting for more...");
+ return;
+ }
+ // Move incomingData into local variable and reset it since we received it all:
+ const QByteArray fullHeader = std::exchange(incomingData, {});
+
+ QLatin1StringView authView = getHeaderValue("Authorization"_L1, fullHeader);
+ if (authView.isEmpty())
+ return writeAuthRequired(serverSocket);
+ qsizetype sep = authView.indexOf(' ');
+ if (sep == -1)
+ return writeAuthRequired(serverSocket);
+ QLatin1StringView authenticateMethod = authView.first(sep);
+ QLatin1StringView authenticateAttempt = authView.sliced(sep + 1);
+ if (authenticateMethod != "Basic" || authenticateAttempt != expectedBasicPayload())
+ return writeAuthRequired(serverSocket);
+
+ QLatin1StringView keyView = getHeaderValue("Sec-WebSocket-Key"_L1, fullHeader);
+ QVERIFY(!keyView.isEmpty());
+
+ const QByteArray accept =
+ QByteArrayView(keyView) % QByteArrayLiteral("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
+ auto generatedKey = QCryptographicHash::hash(accept, QCryptographicHash::Sha1).toBase64();
+ serverSocket->write("HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: websocket\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: " % generatedKey % "\r\n"
+ "\r\n");
+ finished = true;
+ }
+
+ void writeAuthRequired(QTcpSocket *socket) const
+ {
+ QByteArray payload = "HTTP/1.1 401 UNAUTHORIZED\r\n"
+ "WWW-Authenticate: Basic realm=shadow\r\n";
+ if (withConnectionClose)
+ payload.append("Connection: Close\r\n");
+ else if (withContentLength)
+ payload.append("Content-Length: " % QByteArray::number(body.size()) % "\r\n");
+ payload.append("\r\n");
+
+ if (withBody)
+ payload.append(body);
+
+ socket->write(payload);
+ if (withConnectionClose)
+ socket->disconnectFromHost();
+ }
+
+ static QLatin1StringView getHeaderValue(const QLatin1StringView keyHeader,
+ const QByteArrayView fullHeader)
+ {
+ const auto fullHeaderView = QLatin1StringView(fullHeader);
+ const qsizetype headerStart = fullHeaderView.indexOf(keyHeader, 0, Qt::CaseInsensitive);
+ if (headerStart == -1)
+ return {};
+ qsizetype valueStart = headerStart + keyHeader.size();
+ Q_ASSERT(fullHeaderView.size() > valueStart);
+ Q_ASSERT(fullHeaderView[valueStart] == ':');
+ ++valueStart;
+ const qsizetype valueEnd = fullHeaderView.indexOf(QLatin1StringView("\r\n"), valueStart);
+ if (valueEnd == -1)
+ return {};
+ return fullHeaderView.sliced(valueStart, valueEnd - valueStart).trimmed();
+ }
+
+ static QByteArray expectedBasicPayload()
+ {
+ return QByteArray(user % ':' % password).toBase64();
+ }
+
+ static constexpr QByteArrayView user = "user";
+ static constexpr QByteArrayView password = "password";
+ static constexpr QUtf8StringView body = "Authorization required";
+
+ bool withBody = false;
+ bool withContentLength = true;
+ bool withConnectionClose = false;
+ bool withEncryption = false;
+#if QT_CONFIG(ssl)
+ QSslConfiguration configuration;
+#endif
+
+private:
+ QByteArray incomingData;
+ bool finished = false;
+};
+
+struct ServerScenario {
+ QByteArrayView label;
+ bool withContentLength = false;
+ bool withBody = false;
+ bool withConnectionClose = false;
+ bool withEncryption = false;
+};
+struct Credentials { QString username, password; };
+struct ClientScenario {
+ QByteArrayView label;
+ Credentials urlCredentials;
+ QVector<Credentials> callbackCredentials;
+ bool expectSuccess = true;
+};
+
+void tst_QWebSocket::authenticationRequired_data()
+{
+ const QString correctUser = QString::fromUtf8(AuthServer::user.toByteArray());
+ const QString correctPassword = QString::fromUtf8(AuthServer::password.toByteArray());
+
+ QTest::addColumn<ServerScenario>("serverScenario");
+ QTest::addColumn<ClientScenario>("clientScenario");
+
+ // Need to test multiple server scenarios:
+ // 1. Normal server (connection: keep-alive, Content-Length)
+ // 2. Older server (connection: close, Content-Length)
+ // 3. Even older server (connection: close, no Content-Length)
+ // 4. Strange server (connection: close, no Content-Length, no body)
+ // 5. Quiet server (connection: keep-alive, no Content-Length, no body)
+ ServerScenario serverScenarios[] = {
+ { "normal-server", true, true, false, false },
+ { "connection-close", true, true, true, false },
+ { "connection-close-no-content-length", false, true, true, false },
+ { "connection-close-no-content-length-no-body", false, false, true, false },
+ { "keep-alive-no-content-length-no-body", false, false, false, false },
+ };
+
+ // And some client scenarios
+ // 1. User/pass supplied in url
+ // 2. User/pass supplied in callback
+ // 3. _Wrong_ user/pass supplied in URL, correct in callback
+ // 4. _Wrong_ user/pass supplied in URL, _wrong_ supplied in callback
+ // 5. No user/pass supplied in URL, nothing supplied in callback
+ // 5. No user/pass supplied in URL, wrong, then correct, supplied in callback
+ ClientScenario clientScenarios[]{
+ { "url-ok", {correctUser, correctPassword}, {} },
+ { "callback-ok", {}, { {correctUser, correctPassword } } },
+ { "url-wrong-callback-ok", {u"admin"_s, u"admin"_s}, { {correctUser, correctPassword} } },
+ { "url-wrong-callback-wrong", {u"admin"_s, u"admin"_s}, { {u"test"_s, u"test"_s} }, false },
+ { "no-creds", {{}, {}}, {}, false },
+ { "url-wrong-callback-2-ok", {u"admin"_s, u"admin"_s}, { {u"test"_s, u"test"_s}, {correctUser , correctPassword} } },
+ };
+
+ for (auto &server : serverScenarios) {
+ for (auto &client : clientScenarios) {
+ QTest::addRow("Server:%s,Client:%s", server.label.data(), client.label.data())
+ << server << client;
+ }
+ }
+#if QT_CONFIG(ssl)
+ if (!QSslSocket::supportsSsl()) {
+ qDebug("Skipping the SslServer part of this test because proper TLS is not supported.");
+ return;
+ }
+ // And double that, but now with TLS
+ for (auto &server : serverScenarios) {
+ server.withEncryption = true;
+ for (auto &client : clientScenarios) {
+ QTest::addRow("SslServer:%s,Client:%s", server.label.data(), client.label.data())
+ << server << client;
+ }
+ }
+#endif
+}
+
+void tst_QWebSocket::authenticationRequired()
+{
+ QFETCH(const ServerScenario, serverScenario);
+ QFETCH(const ClientScenario, clientScenario);
+
+ int credentialIndex = 0;
+ auto handleAuthenticationRequired = [&clientScenario,
+ &credentialIndex](QAuthenticator *authenticator) {
+ if (credentialIndex == clientScenario.callbackCredentials.size()) {
+ if (clientScenario.expectSuccess)
+ QFAIL("Ran out of credentials to try, but failed to authorize!");
+ if (clientScenario.callbackCredentials.isEmpty())
+ return;
+ // If we don't expect to succeed, retry the last returned credentials.
+ // QAuthenticator should notice there is no change in user/pass and
+ // ignore it, leading to authentication failure.
+ --credentialIndex;
+ }
+ // Verify that realm parsing works:
+ QCOMPARE_EQ(authenticator->realm(), u"shadow"_s);
+
+ Credentials credentials = clientScenario.callbackCredentials[credentialIndex++];
+ authenticator->setUser(credentials.username);
+ authenticator->setPassword(credentials.password);
+ };
+
+ AuthServer server;
+ server.withBody = serverScenario.withBody;
+ server.withContentLength = serverScenario.withContentLength;
+ server.withConnectionClose = serverScenario.withConnectionClose;
+ server.withEncryption = serverScenario.withEncryption;
+#if QT_CONFIG(ssl)
+ if (serverScenario.withEncryption) {
+ QSslConfiguration config = QSslConfiguration::defaultConfiguration();
+ QList<QSslCertificate> certificates = QSslCertificate::fromPath(u":/localhost.cert"_s);
+ QVERIFY(!certificates.isEmpty());
+ config.setLocalCertificateChain(certificates);
+ QFile keyFile(u":/localhost.key"_s);
+ QVERIFY(keyFile.open(QIODevice::ReadOnly));
+ config.setPrivateKey(QSslKey(keyFile.readAll(), QSsl::Rsa));
+ server.configuration = config;
+ }
+#endif
+
+ QVERIFY(server.listen());
+ QUrl url = QUrl(u"ws://127.0.0.1"_s);
+ if (serverScenario.withEncryption)
+ url.setScheme(u"wss"_s);
+ url.setPort(server.serverPort());
+ url.setUserName(clientScenario.urlCredentials.username);
+ url.setPassword(clientScenario.urlCredentials.password);
+
+ QWebSocket socket;
+ QSignalSpy connectedSpy(&socket, &QWebSocket::connected);
+ QSignalSpy errorSpy(&socket, &QWebSocket::errorOccurred);
+ QSignalSpy stateChangedSpy(&socket, &QWebSocket::stateChanged);
+ connect(&socket, &QWebSocket::authenticationRequired, &socket, handleAuthenticationRequired);
+#if QT_CONFIG(ssl)
+ if (serverScenario.withEncryption) {
+ auto config = socket.sslConfiguration();
+ config.setPeerVerifyMode(QSslSocket::VerifyNone);
+ socket.setSslConfiguration(config);
+ QObject::connect(&socket, &QWebSocket::sslErrors, &socket,
+ qOverload<>(&QWebSocket::ignoreSslErrors));
+ }
+#endif
+ socket.open(url);
+
+ if (clientScenario.expectSuccess) {
+ // Wait for connected!
+ QTRY_COMPARE_EQ(connectedSpy.size(), 1);
+ QCOMPARE_EQ(errorSpy.size(), 0);
+ // connecting->connected
+ const int ExpectedStateChanges = 2;
+ QTRY_COMPARE_EQ(stateChangedSpy.size(), ExpectedStateChanges);
+ auto firstState = stateChangedSpy.at(0).front().value<QAbstractSocket::SocketState>();
+ QCOMPARE_EQ(firstState, QAbstractSocket::ConnectingState);
+ auto secondState = stateChangedSpy.at(1).front().value<QAbstractSocket::SocketState>();
+ QCOMPARE_EQ(secondState, QAbstractSocket::ConnectedState);
+ } else {
+ // Wait for error!
+ QTRY_COMPARE_EQ(errorSpy.size(), 1);
+ QCOMPARE_EQ(connectedSpy.size(), 0);
+ // connecting->unconnected
+ const int ExpectedStateChanges = 2;
+ QTRY_COMPARE_EQ(stateChangedSpy.size(), ExpectedStateChanges);
+ auto firstState = stateChangedSpy.at(0).front().value<QAbstractSocket::SocketState>();
+ QCOMPARE_EQ(firstState, QAbstractSocket::ConnectingState);
+ auto secondState = stateChangedSpy.at(1).front().value<QAbstractSocket::SocketState>();
+ QCOMPARE_EQ(secondState, QAbstractSocket::UnconnectedState);
+ }
+}
void tst_QWebSocket::overlongCloseReason()
{
@@ -796,16 +1251,16 @@ void tst_QWebSocket::overlongCloseReason()
QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port()));
socket.open(url);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QTRY_COMPARE(serverConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QTRY_COMPARE(serverConnectedSpy.size(), 1);
const QString reason(200, QChar::fromLatin1('a'));
socket.close(QWebSocketProtocol::CloseCodeGoingAway, reason);
QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeGoingAway);
// Max length of a control frame is 125, but 2 bytes are used for the close code:
- QCOMPARE(socket.closeReason().length(), 123);
+ QCOMPARE(socket.closeReason().size(), 123);
QCOMPARE(socket.closeReason(), reason.left(123));
- QTRY_COMPARE(socketDisconnectedSpy.count(), 1);
+ QTRY_COMPARE(socketDisconnectedSpy.size(), 1);
}
void tst_QWebSocket::incomingMessageTooLong()
@@ -825,13 +1280,13 @@ void tst_QWebSocket::incomingMessageTooLong()
QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port()));
socket.open(url);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QTRY_COMPARE(serverConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QTRY_COMPARE(serverConnectedSpy.size(), 1);
QString payload(maxAllowedIncomingMessageSize+1, 'a');
QCOMPARE(socket.sendTextMessage(payload), payload.size());
- QTRY_COMPARE(socketDisconnectedSpy.count(), 1);
+ QTRY_COMPARE(socketDisconnectedSpy.size(), 1);
QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeTooMuchData);
}
@@ -853,13 +1308,13 @@ void tst_QWebSocket::incomingFrameTooLong()
QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
QStringLiteral(":") + QString::number(echoServer.port()));
socket.open(url);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
- QTRY_COMPARE(serverConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
+ QTRY_COMPARE(serverConnectedSpy.size(), 1);
QString payload(maxAllowedIncomingFrameSize+1, 'a');
QCOMPARE(socket.sendTextMessage(payload), payload.size());
- QTRY_COMPARE(socketDisconnectedSpy.count(), 1);
+ QTRY_COMPARE(socketDisconnectedSpy.size(), 1);
QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeTooMuchData);
}
@@ -881,7 +1336,58 @@ void tst_QWebSocket::testingFrameAndMessageSizeApi()
QTRY_COMPARE(maxAllowedIncomingMessageSize, socket.maxAllowedIncomingMessageSize());
}
-#endif // QT_NO_NETWORKPROXY
+void tst_QWebSocket::customHeader()
+{
+ QTcpServer server;
+ QSignalSpy serverSpy(&server, &QTcpServer::newConnection);
+
+ server.listen();
+ QUrl url = QUrl(QStringLiteral("ws://127.0.0.1"));
+ url.setPort(server.serverPort());
+
+ QNetworkRequest request(url);
+ request.setRawHeader("CustomHeader", "Example");
+ QWebSocket socket;
+ socket.open(request);
+
+ // Custom websocket server below (needed because a QWebSocketServer on
+ // localhost doesn't show the issue):
+ QVERIFY(serverSpy.wait());
+ QTcpSocket *serverSocket = server.nextPendingConnection();
+ QSignalSpy serverSocketSpy(serverSocket, &QTcpSocket::readyRead);
+ QByteArray data;
+ while (!data.contains("\r\n\r\n")) {
+ QVERIFY(serverSocketSpy.wait());
+ data.append(serverSocket->readAll());
+ }
+ QVERIFY(data.contains("CustomHeader: Example"));
+ const auto view = QLatin1String(data);
+ const auto keyHeader = QLatin1String("Sec-WebSocket-Key:");
+ const qsizetype keyStart = view.indexOf(keyHeader, 0, Qt::CaseInsensitive) + keyHeader.size();
+ QVERIFY(keyStart != -1);
+ const qsizetype keyEnd = view.indexOf(QLatin1String("\r\n"), keyStart);
+ QVERIFY(keyEnd != -1);
+ const QLatin1String keyView = view.sliced(keyStart, keyEnd - keyStart).trimmed();
+ const QByteArray accept =
+ QByteArrayView(keyView) % QByteArrayLiteral("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
+ serverSocket->write(
+ "HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: websocket\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: "
+ % QCryptographicHash::hash(accept, QCryptographicHash::Sha1).toBase64()
+ ); // trailing \r\n\r\n intentionally left off to make the client wait for it
+ serverSocket->flush();
+ // This would freeze prior to the fix for QTBUG-102111, because the client would loop forever.
+ // We use qWait to give the OS some time to move the bytes over to the client and push the event
+ // to our eventloop.
+ QTest::qWait(100);
+ serverSocket->write("\r\n\r\n");
+
+ // And check the client properly connects:
+ QSignalSpy connectedSpy(&socket, &QWebSocket::connected);
+ QVERIFY(connectedSpy.wait());
+}
QTEST_MAIN(tst_QWebSocket)
diff --git a/tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt b/tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt
index 59045da..e9191d6 100644
--- a/tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt
+++ b/tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt
@@ -1,13 +1,16 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qwebsocketcorsauthenticator.pro.
#####################################################################
## tst_qwebsocketcorsauthenticator Test:
#####################################################################
-qt_add_test(tst_qwebsocketcorsauthenticator
+qt_internal_add_test(tst_qwebsocketcorsauthenticator
SOURCES
tst_qwebsocketcorsauthenticator.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSockets
)
diff --git a/tests/auto/websockets/qwebsocketcorsauthenticator/qwebsocketcorsauthenticator.pro b/tests/auto/websockets/qwebsocketcorsauthenticator/qwebsocketcorsauthenticator.pro
deleted file mode 100644
index caa97ad..0000000
--- a/tests/auto/websockets/qwebsocketcorsauthenticator/qwebsocketcorsauthenticator.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_qwebsocketcorsauthenticator
-
-QT = testlib websockets
-
-SOURCES += tst_qwebsocketcorsauthenticator.cpp
-
diff --git a/tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp b/tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp
index 0f72674..2294008 100644
--- a/tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp
+++ b/tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtCore/QDebug>
diff --git a/tests/auto/websockets/qwebsocketserver/BLACKLIST b/tests/auto/websockets/qwebsocketserver/BLACKLIST
new file mode 100644
index 0000000..904335d
--- /dev/null
+++ b/tests/auto/websockets/qwebsocketserver/BLACKLIST
@@ -0,0 +1,5 @@
+# QTBUG-102713
+[tst_scheme]
+android
+[tst_handshakeTimeout]
+android
diff --git a/tests/auto/websockets/qwebsocketserver/CMakeLists.txt b/tests/auto/websockets/qwebsocketserver/CMakeLists.txt
index 9b2eca8..97286dc 100644
--- a/tests/auto/websockets/qwebsocketserver/CMakeLists.txt
+++ b/tests/auto/websockets/qwebsocketserver/CMakeLists.txt
@@ -1,29 +1,26 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qwebsocketserver.pro.
#####################################################################
## tst_qwebsocketserver Test:
#####################################################################
-qt_add_test(tst_qwebsocketserver
+qt_internal_add_test(tst_qwebsocketserver
SOURCES
tst_qwebsocketserver.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSockets
)
# Resources:
-set_source_files_properties("../shared/localhost.cert"
- PROPERTIES QT_RESOURCE_ALIAS "localhost.cert"
-)
-set_source_files_properties("../shared/localhost.key"
- PROPERTIES QT_RESOURCE_ALIAS "localhost.key"
-)
set(qwebsocketshared_resource_files
- "localhost.cert"
- "localhost.key"
+ "../shared/localhost.cert"
+ "../shared/localhost.key"
)
-qt_add_resource(tst_qwebsocketserver "qwebsocketshared"
+qt_internal_add_resource(tst_qwebsocketserver "qwebsocketshared"
PREFIX
"/"
BASE
@@ -39,7 +36,7 @@ qt_add_resource(tst_qwebsocketserver "qwebsocketshared"
## Scopes:
#####################################################################
-qt_extend_target(tst_qwebsocketserver CONDITION boot2qt
+qt_internal_extend_target(tst_qwebsocketserver CONDITION boot2qt
DEFINES
SHOULD_CHECK_SYSCALL_SUPPORT
)
diff --git a/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro b/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro
deleted file mode 100644
index c1ca4af..0000000
--- a/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-QT = testlib websockets
-
-TARGET = tst_qwebsocketserver
-
-TEMPLATE = app
-
-SOURCES += tst_qwebsocketserver.cpp
-
-RESOURCES += $$PWD/../shared/qwebsocketshared.qrc
-
-boot2qt: DEFINES += SHOULD_CHECK_SYSCALL_SUPPORT
diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
index 62d8d43..c0ba30c 100644
--- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
+++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
@@ -1,44 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QString>
#include <QtTest>
#include <QNetworkProxy>
#include <QTcpSocket>
#include <QTcpServer>
#include <QtCore/QScopedPointer>
-#ifndef QT_NO_OPENSSL
#include <QtNetwork/qsslpresharedkeyauthenticator.h>
-#endif
#ifndef QT_NO_SSL
#include <QtNetwork/qsslcipher.h>
#include <QtNetwork/qsslkey.h>
#include <QtNetwork/qsslsocket.h>
#endif
+#include <QtWebSockets/QWebSocketHandshakeOptions>
#include <QtWebSockets/QWebSocketServer>
#include <QtWebSockets/QWebSocket>
#include <QtWebSockets/QWebSocketCorsAuthenticator>
@@ -54,7 +28,6 @@ Q_DECLARE_METATYPE(QWebSocketCorsAuthenticator *)
Q_DECLARE_METATYPE(QSslError)
#endif
-#ifndef QT_NO_OPENSSL
// Use this cipher to force PSK key sharing.
static const QString PSK_CIPHER_WITHOUT_AUTH = QStringLiteral("PSK-AES256-CBC-SHA");
static const QByteArray PSK_CLIENT_PRESHAREDKEY = QByteArrayLiteral("\x1a\x2b\x3c\x4d\x5e\x6f");
@@ -93,7 +66,6 @@ public slots:
}
}
};
-#endif
class tst_QWebSocketServer : public QObject
{
@@ -110,6 +82,8 @@ private Q_SLOTS:
void tst_settersAndGetters();
void tst_listening();
void tst_connectivity();
+ void tst_protocols_data();
+ void tst_protocols();
void tst_preSharedKey();
void tst_maxPendingConnections();
void tst_serverDestroyedWhileSocketConnected();
@@ -137,10 +111,8 @@ void tst_QWebSocketServer::init()
qRegisterMetaType<QWebSocketCorsAuthenticator *>("QWebSocketCorsAuthenticator *");
#ifndef QT_NO_SSL
qRegisterMetaType<QSslError>("QSslError");
-#ifndef QT_NO_OPENSSL
qRegisterMetaType<QSslPreSharedKeyAuthenticator *>();
#endif
-#endif
}
#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
@@ -196,11 +168,7 @@ void tst_QWebSocketServer::tst_initialisation()
QCOMPARE(server.maxPendingConnections(), 30);
QCOMPARE(server.serverPort(), quint16(0));
QCOMPARE(server.serverAddress(), QHostAddress());
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QCOMPARE(server.socketDescriptor(), -1);
-#else // ### Qt 6: Remove leftovers
- QCOMPARE(server.nativeDescriptor(), -1);
-#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.hasPendingConnections());
QVERIFY(!server.nextPendingConnection());
QCOMPARE(server.error(), QWebSocketProtocol::CloseCodeNormal);
@@ -211,7 +179,7 @@ void tst_QWebSocketServer::tst_initialisation()
#ifndef QT_NO_SSL
QCOMPARE(server.sslConfiguration(), QSslConfiguration::defaultConfiguration());
#endif
- QCOMPARE(server.supportedVersions().count(), 1);
+ QCOMPARE(server.supportedVersions().size(), 1);
QCOMPARE(server.supportedVersions().at(0), QWebSocketProtocol::VersionLatest);
QCOMPARE(server.supportedVersions().at(0), QWebSocketProtocol::Version13);
@@ -225,11 +193,7 @@ void tst_QWebSocketServer::tst_initialisation()
QCOMPARE(server.maxPendingConnections(), 30);
QCOMPARE(server.serverPort(), quint16(0));
QCOMPARE(server.serverAddress(), QHostAddress());
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QCOMPARE(server.socketDescriptor(), -1);
-#else // ### Qt 6: Remove leftovers
- QCOMPARE(server.nativeDescriptor(), -1);
-#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.hasPendingConnections());
QVERIFY(!server.nextPendingConnection());
QCOMPARE(server.error(), QWebSocketProtocol::CloseCodeNormal);
@@ -240,7 +204,7 @@ void tst_QWebSocketServer::tst_initialisation()
#ifndef QT_NO_SSL
QCOMPARE(server.sslConfiguration(), QSslConfiguration::defaultConfiguration());
#endif
- QCOMPARE(server.supportedVersions().count(), 1);
+ QCOMPARE(server.supportedVersions().size(), 1);
QCOMPARE(server.supportedVersions().at(0), QWebSocketProtocol::VersionLatest);
QCOMPARE(server.supportedVersions().at(0), QWebSocketProtocol::Version13);
QCOMPARE(server.serverUrl(), QUrl());
@@ -265,13 +229,8 @@ void tst_QWebSocketServer::tst_settersAndGetters()
server.setMaxPendingConnections(INT_MAX);
QCOMPARE(server.maxPendingConnections(), INT_MAX);
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.setSocketDescriptor(-2));
QCOMPARE(server.socketDescriptor(), -1);
-#else // ### Qt 6: Remove leftovers
- QVERIFY(!server.setNativeDescriptor(-2));
- QCOMPARE(server.nativeDescriptor(), -1);
-#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
server.setServerName(QStringLiteral("Qt WebSocketServer"));
QCOMPARE(server.serverName(), QStringLiteral("Qt WebSocketServer"));
@@ -297,7 +256,7 @@ void tst_QWebSocketServer::tst_settersAndGetters()
server.setHandshakeTimeout(64);
QCOMPARE(server.handshakeTimeoutMS(), 64);
-#if QT_HAS_INCLUDE(<chrono>)
+#if __has_include(<chrono>)
auto expected = std::chrono::milliseconds(64);
QCOMPARE(server.handshakeTimeout(), expected);
@@ -329,26 +288,26 @@ void tst_QWebSocketServer::tst_listening()
QVERIFY(server.listen()); //listen on all network interface, choose an appropriate port
QVERIFY(server.isListening());
- QCOMPARE(serverClosedSpy.count(), 0);
+ QCOMPARE(serverClosedSpy.size(), 0);
server.close();
- QTRY_COMPARE(serverClosedSpy.count(), 1);
+ QTRY_COMPARE(serverClosedSpy.size(), 1);
QVERIFY(!server.isListening());
- QCOMPARE(serverErrorSpy.count(), 0);
+ QCOMPARE(serverErrorSpy.size(), 0);
QVERIFY(!server.listen(QHostAddress(QStringLiteral("1.2.3.4")), 0));
QCOMPARE(server.error(), QWebSocketProtocol::CloseCodeAbnormalDisconnection);
QCOMPARE(server.errorString().toLatin1().constData(), "The address is not available");
QVERIFY(!server.isListening());
- QCOMPARE(serverAcceptErrorSpy.count(), 0);
- QCOMPARE(serverConnectionSpy.count(), 0);
- QCOMPARE(corsAuthenticationSpy.count(), 0);
+ QCOMPARE(serverAcceptErrorSpy.size(), 0);
+ QCOMPARE(serverConnectionSpy.size(), 0);
+ QCOMPARE(corsAuthenticationSpy.size(), 0);
#ifndef QT_NO_SSL
- QCOMPARE(peerVerifyErrorSpy.count(), 0);
- QCOMPARE(sslErrorsSpy.count(), 0);
+ QCOMPARE(peerVerifyErrorSpy.size(), 0);
+ QCOMPARE(sslErrorsSpy.size(), 0);
#endif
- QCOMPARE(serverErrorSpy.count(), 1);
- QCOMPARE(serverClosedSpy.count(), 1);
+ QCOMPARE(serverErrorSpy.size(), 1);
+ QCOMPARE(serverClosedSpy.size(), 1);
}
void tst_QWebSocketServer::tst_connectivity()
@@ -377,21 +336,77 @@ void tst_QWebSocketServer::tst_connectivity()
socket.open(server.serverUrl().toString());
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(serverConnectionSpy.count(), 1);
- QCOMPARE(corsAuthenticationSpy.count(), 1);
+ QCOMPARE(serverConnectionSpy.size(), 1);
+ QCOMPARE(corsAuthenticationSpy.size(), 1);
- QCOMPARE(serverClosedSpy.count(), 0);
+ QCOMPARE(serverClosedSpy.size(), 0);
server.close();
- QTRY_COMPARE(serverClosedSpy.count(), 1);
+ QTRY_COMPARE(serverClosedSpy.size(), 1);
#ifndef QT_NO_SSL
- QCOMPARE(peerVerifyErrorSpy.count(), 0);
- QCOMPARE(sslErrorsSpy.count(), 0);
+ QCOMPARE(peerVerifyErrorSpy.size(), 0);
+ QCOMPARE(sslErrorsSpy.size(), 0);
#endif
- QCOMPARE(serverErrorSpy.count(), 0);
+ QCOMPARE(serverErrorSpy.size(), 0);
+}
+
+void tst_QWebSocketServer::tst_protocols_data()
+{
+ QTest::addColumn<QStringList>("clientProtocols");
+ QTest::addColumn<QStringList>("headerProtocols");
+ QTest::addColumn<QString>("expectedProtocol");
+
+ QTest::addRow("none") << QStringList{} << QStringList{} << QString{};
+ QTest::addRow("same order as server")
+ << QStringList{ "chat", "superchat" } << QStringList{} << QStringLiteral("chat");
+ QTest::addRow("different order from server")
+ << QStringList{ "superchat", "chat" } << QStringList{} << QStringLiteral("superchat");
+ QTest::addRow("unsupported protocol") << QStringList{ "foo" } << QStringList{} << QString{};
+ QTest::addRow("mixed supported/unsupported protocol")
+ << QStringList{ "foo", "chat" } << QStringList{} << QStringLiteral("chat");
+
+ QTest::addRow("same order as server, in header")
+ << QStringList{} << QStringList{ "chat", "superchat" } << QStringLiteral("chat");
+ QTest::addRow("specified in options and in header")
+ << QStringList{ "superchat" } << QStringList{ "chat" } << QStringLiteral("superchat");
+}
+
+void tst_QWebSocketServer::tst_protocols()
+{
+ QFETCH(QStringList, clientProtocols);
+ QFETCH(QStringList, headerProtocols);
+ QFETCH(QString, expectedProtocol);
+
+ QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode);
+ server.setSupportedSubprotocols({ QStringLiteral("chat"), QStringLiteral("superchat") });
+
+ QSignalSpy newConnectionSpy(&server, &QWebSocketServer::newConnection);
+
+ QVERIFY(server.listen());
+
+ QWebSocketHandshakeOptions opt;
+ QNetworkRequest request(server.serverUrl());
+ if (!headerProtocols.isEmpty()) {
+ QString protocols = headerProtocols.join(u',');
+ request.setRawHeader("Sec-WebSocket-Protocol", protocols.toUtf8());
+ }
+ opt.setSubprotocols(clientProtocols);
+
+ QWebSocket client;
+ client.open(request, opt);
+
+ QTRY_COMPARE(client.state(), QAbstractSocket::ConnectedState);
+ QTRY_COMPARE(newConnectionSpy.size(), 1);
+
+ auto *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+
+ QCOMPARE(client.subprotocol(), expectedProtocol);
+ QCOMPARE(serverSocket->subprotocol(), expectedProtocol);
+ QCOMPARE(serverSocket->handshakeOptions().subprotocols(), clientProtocols + headerProtocols);
}
void tst_QWebSocketServer::tst_preSharedKey()
@@ -399,7 +414,9 @@ void tst_QWebSocketServer::tst_preSharedKey()
if (m_shouldSkipUnsupportedIpv6Test)
QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
-#ifndef QT_NO_OPENSSL
+ if (QSslSocket::activeBackend() != u"openssl")
+ QSKIP("OpenSSL required");
+
QWebSocketServer server(QString(), QWebSocketServer::SecureMode);
bool cipherFound = false;
@@ -419,8 +436,7 @@ void tst_QWebSocketServer::tst_preSharedKey()
list << cipher;
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
- if (QSslSocket::sslLibraryVersionNumber() >= 0x10101000L)
- config.setProtocol(QSsl::TlsV1_2); // With TLS 1.3 there are some issues with PSK, force 1.2
+ config.setProtocol(QSsl::TlsV1_2); // With TLS 1.3 there are some issues with PSK, force 1.2
config.setCiphers(list);
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setPreSharedKeyIdentityHint(PSK_SERVER_IDENTITY_HINT);
@@ -461,20 +477,19 @@ void tst_QWebSocketServer::tst_preSharedKey()
socket.open(server.serverUrl().toString());
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(serverConnectionSpy.count(), 1);
- QCOMPARE(serverPskRequiredSpy.count(), 1);
- QCOMPARE(socketPskRequiredSpy.count(), 1);
+ QCOMPARE(serverConnectionSpy.size(), 1);
+ QCOMPARE(serverPskRequiredSpy.size(), 1);
+ QCOMPARE(socketPskRequiredSpy.size(), 1);
- QCOMPARE(serverClosedSpy.count(), 0);
+ QCOMPARE(serverClosedSpy.size(), 0);
server.close();
- QTRY_COMPARE(serverClosedSpy.count(), 1);
- QCOMPARE(sslErrorsSpy.count(), 0);
- QCOMPARE(serverErrorSpy.count(), 0);
-#endif
+ QTRY_COMPARE(serverClosedSpy.size(), 1);
+ QCOMPARE(sslErrorsSpy.size(), 0);
+ QCOMPARE(serverErrorSpy.size(), 0);
}
void tst_QWebSocketServer::tst_maxPendingConnections()
@@ -510,21 +525,21 @@ void tst_QWebSocketServer::tst_maxPendingConnections()
socket1.open(server.serverUrl().toString());
- QTRY_COMPARE(socket1ConnectedSpy.count(), 1);
+ QTRY_COMPARE(socket1ConnectedSpy.size(), 1);
QCOMPARE(socket1.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(serverConnectionSpy.count(), 1);
- QCOMPARE(corsAuthenticationSpy.count(), 1);
+ QCOMPARE(serverConnectionSpy.size(), 1);
+ QCOMPARE(corsAuthenticationSpy.size(), 1);
socket2.open(server.serverUrl().toString());
- QTRY_COMPARE(socket2ConnectedSpy.count(), 1);
+ QTRY_COMPARE(socket2ConnectedSpy.size(), 1);
QCOMPARE(socket2.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(serverConnectionSpy.count(), 2);
- QCOMPARE(corsAuthenticationSpy.count(), 2);
+ QCOMPARE(serverConnectionSpy.size(), 2);
+ QCOMPARE(corsAuthenticationSpy.size(), 2);
socket3.open(server.serverUrl().toString());
QVERIFY(!socket3ConnectedSpy.wait(250));
- QCOMPARE(socket3ConnectedSpy.count(), 0);
+ QCOMPARE(socket3ConnectedSpy.size(), 0);
QCOMPARE(socket3.state(), QAbstractSocket::UnconnectedState);
- QCOMPARE(serverConnectionSpy.count(), 2);
- QCOMPARE(corsAuthenticationSpy.count(), 2);
+ QCOMPARE(serverConnectionSpy.size(), 2);
+ QCOMPARE(corsAuthenticationSpy.size(), 2);
QVERIFY(server.hasPendingConnections());
QWebSocket *pSocket = server.nextPendingConnection();
@@ -539,20 +554,20 @@ void tst_QWebSocketServer::tst_maxPendingConnections()
//will resolve in another commit
#ifndef Q_OS_WIN
- QCOMPARE(serverErrorSpy.count(), 1);
+ QCOMPARE(serverErrorSpy.size(), 1);
QCOMPARE(serverErrorSpy.at(0).at(0).value<QWebSocketProtocol::CloseCode>(),
QWebSocketProtocol::CloseCodeAbnormalDisconnection);
#endif
- QCOMPARE(serverClosedSpy.count(), 0);
+ QCOMPARE(serverClosedSpy.size(), 0);
server.close();
- QTRY_COMPARE(serverClosedSpy.count(), 1);
+ QTRY_COMPARE(serverClosedSpy.size(), 1);
#ifndef QT_NO_SSL
- QCOMPARE(peerVerifyErrorSpy.count(), 0);
- QCOMPARE(sslErrorsSpy.count(), 0);
+ QCOMPARE(peerVerifyErrorSpy.size(), 0);
+ QCOMPARE(sslErrorsSpy.size(), 0);
#endif
- QCOMPARE(serverAcceptErrorSpy.count(), 0);
+ QCOMPARE(serverAcceptErrorSpy.size(), 0);
}
void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected()
@@ -577,16 +592,16 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected()
socket.open(server->serverUrl().toString());
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(serverConnectionSpy.count(), 1);
- QCOMPARE(corsAuthenticationSpy.count(), 1);
+ QCOMPARE(serverConnectionSpy.size(), 1);
+ QCOMPARE(corsAuthenticationSpy.size(), 1);
- QCOMPARE(serverClosedSpy.count(), 0);
+ QCOMPARE(serverClosedSpy.size(), 0);
delete server;
- QTRY_COMPARE(socketDisconnectedSpy.count(), 1);
+ QTRY_COMPARE(socketDisconnectedSpy.size(), 1);
}
#ifndef QT_NO_SSL
@@ -621,7 +636,7 @@ void tst_QWebSocketServer::tst_scheme()
QWebSocket plainSocket;
plainSocket.open(plainServer.serverUrl().toString());
- QTRY_COMPARE(plainServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(plainServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> plainServerSocket(plainServer.nextPendingConnection());
QVERIFY(!plainServerSocket.isNull());
QCOMPARE(plainServerSocket->requestUrl().scheme(), QStringLiteral("ws"));
@@ -645,7 +660,7 @@ void tst_QWebSocketServer::tst_scheme()
});
secureSocket.open(secureServer.serverUrl().toString());
- QTRY_COMPARE(secureServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(secureServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> secureServerSocket(secureServer.nextPendingConnection());
QVERIFY(!secureServerSocket.isNull());
QCOMPARE(secureServerSocket->requestUrl().scheme(), QStringLiteral("wss"));
@@ -669,9 +684,9 @@ void tst_QWebSocketServer::tst_handleConnection()
QWebSocket webSocket;
QSignalSpy wsConnectedSpy(&webSocket, &QWebSocket::connected);
webSocket.open(QStringLiteral("ws://localhost:%1").arg(tcpServer.serverPort()));
- QTRY_COMPARE(wsConnectedSpy.count(), 1);
+ QTRY_COMPARE(wsConnectedSpy.size(), 1);
- QTRY_COMPARE(wsServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(wsServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> webServerSocket(wsServer.nextPendingConnection());
QVERIFY(!webServerSocket.isNull());
@@ -679,7 +694,7 @@ void tst_QWebSocketServer::tst_handleConnection()
QSignalSpy wsMessageReceivedSpy(webServerSocket.data(), &QWebSocket::textMessageReceived);
webSocket.sendTextMessage("dummy");
- QTRY_COMPARE(wsMessageReceivedSpy.count(), 1);
+ QTRY_COMPARE(wsMessageReceivedSpy.size(), 1);
QList<QVariant> arguments = wsMessageReceivedSpy.takeFirst();
QCOMPARE(arguments.first().toString(), QString("dummy"));
@@ -687,7 +702,7 @@ void tst_QWebSocketServer::tst_handleConnection()
webServerSocket->sendTextMessage("hello");
QVERIFY(webServerSocket->bytesToWrite() > 5); // 5 + a few extra bytes for header
QTRY_COMPARE(webServerSocket->bytesToWrite(), 0);
- QTRY_COMPARE(clientMessageReceivedSpy.count(), 1);
+ QTRY_COMPARE(clientMessageReceivedSpy.size(), 1);
arguments = clientMessageReceivedSpy.takeFirst();
QCOMPARE(arguments.first().toString(), QString("hello"));
}
@@ -717,7 +732,7 @@ static void openManyConnections(QList<SocketSpy *> *sockets, quint16 port, int n
static int sumSocketSpyCount(const QList<SocketSpy *> &sockets)
{
return std::accumulate(sockets.cbegin(), sockets.cend(), 0, [](int c, SocketSpy *s) {
- return c + s->disconnectSpy->count();
+ return c + s->disconnectSpy->size();
});
}
@@ -733,7 +748,7 @@ void tst_QWebSocketServer::tst_handshakeTimeout()
QWebSocket socket;
socket.open(plainServer.serverUrl().toString());
- QTRY_COMPARE(plainServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(plainServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> plainServerSocket(plainServer.nextPendingConnection());
QVERIFY(!plainServerSocket.isNull());
@@ -758,14 +773,14 @@ void tst_QWebSocketServer::tst_handshakeTimeout()
QCoreApplication::processEvents();
/* We have 50 plain TCP connections open, that are not proper websockets. */
- QCOMPARE(plainServerConnectionSpy.count(), 0);
+ QCOMPARE(plainServerConnectionSpy.size(), 0);
QWebSocket socket;
socket.open(plainServer.serverUrl().toString());
/* Check that a real websocket will be processed after some non-websocket
* TCP connections timeout. */
- QTRY_COMPARE(plainServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(plainServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> plainServerSocket(plainServer.nextPendingConnection());
QVERIFY(!plainServerSocket.isNull());
@@ -793,10 +808,10 @@ void tst_QWebSocketServer::tst_handshakeTimeout()
openManyConnections(&sockets, secureServer.serverPort(), numConnections);
QCoreApplication::processEvents();
- QCOMPARE(secureServerConnectionSpy.count(), 0);
+ QCOMPARE(secureServerConnectionSpy.size(), 0);
QWebSocket secureSocket;
- connect(&secureSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
+ connect(&secureSocket, &QWebSocket::errorOccurred,
[](QAbstractSocket::SocketError error) {
// This shouldn't print but it's useful for debugging when/if it does.
qDebug() << "Error occurred in the client:" << error;
@@ -807,7 +822,7 @@ void tst_QWebSocketServer::tst_handshakeTimeout()
secureSocket.open(secureServer.serverUrl().toString());
- QTRY_COMPARE(secureServerConnectionSpy.count(), 1);
+ QTRY_COMPARE(secureServerConnectionSpy.size(), 1);
QScopedPointer<QWebSocket> serverSocket(secureServer.nextPendingConnection());
QVERIFY(!serverSocket.isNull());
@@ -829,14 +844,14 @@ void tst_QWebSocketServer::tst_handshakeTimeout()
QSignalSpy socketDisconnectedSpy(&socket, &QWebSocket::disconnected);
socket.open(plainServer.serverUrl().toString());
- QTRY_COMPARE(plainServerConnectionSpy.count(), 1);
- QTRY_COMPARE(socketConnectedSpy.count(), 1);
+ QTRY_COMPARE(plainServerConnectionSpy.size(), 1);
+ QTRY_COMPARE(socketConnectedSpy.size(), 1);
QEventLoop loop;
QTimer::singleShot(500, &loop, &QEventLoop::quit);
loop.exec();
- QCOMPARE(socketDisconnectedSpy.count(), 0);
+ QCOMPARE(socketDisconnectedSpy.size(), 0);
}
}
@@ -864,7 +879,7 @@ void tst_QWebSocketServer::multipleFrames()
QVERIFY(messageReceivedSpy.wait());
// Since there's no guarantee the operating system will fit all 10 websocket frames into 1 tcp
// frame, let's just assume it will do at least 2. EXCEPT_FAIL any which doesn't merge any.
- QVERIFY2(messageReceivedSpy.count() > 1, "Received only 1 message in the TCP frame!");
+ QVERIFY2(messageReceivedSpy.size() > 1, "Received only 1 message in the TCP frame!");
}
QTEST_MAIN(tst_QWebSocketServer)
diff --git a/tests/auto/websockets/shared/qwebsocketshared.qrc b/tests/auto/websockets/shared/qwebsocketshared.qrc
deleted file mode 100644
index 513a87f..0000000
--- a/tests/auto/websockets/shared/qwebsocketshared.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>localhost.cert</file>
- <file>localhost.key</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/websockets/websocketframe/CMakeLists.txt b/tests/auto/websockets/websocketframe/CMakeLists.txt
index 91380bf..a9cf7ea 100644
--- a/tests/auto/websockets/websocketframe/CMakeLists.txt
+++ b/tests/auto/websockets/websocketframe/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from websocketframe.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,10 @@ endif()
## tst_websocketframe Test:
#####################################################################
-qt_add_test(tst_websocketframe
+qt_internal_add_test(tst_websocketframe
SOURCES
tst_websocketframe.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
index 7046657..6f42911 100644
--- a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
+++ b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QDebug>
@@ -80,7 +55,7 @@ QByteArray FrameHelper::wireRepresentation()
{
quint8 byte = 0x00;
QByteArray wireRep;
- quint64 payloadLength = m_payload.length();
+ quint64 payloadLength = m_payload.size();
//FIN, opcode
byte = static_cast<quint8>((m_opCode & 0x0F) | (m_isFinalFrame ? 0x80 : 0x00)); //FIN, opcode
@@ -179,7 +154,7 @@ void tst_WebSocketFrame::tst_initialization()
{
QWebSocketFrame frame;
QVERIFY(!frame.isValid());
- QCOMPARE(frame.payload().length(), 0);
+ QCOMPARE(frame.payload().size(), 0);
}
void tst_WebSocketFrame::tst_copyConstructorAndAssignment()
@@ -340,7 +315,7 @@ void tst_WebSocketFrame::tst_goodFrames()
QCOMPARE(frame.isControlFrame(), isControlFrame);
QCOMPARE(frame.isDataFrame(), isDataFrame);
QCOMPARE(frame.isContinuationFrame(), isContinuationFrame);
- QCOMPARE(frame.payload().length(), payload.length());
+ QCOMPARE(frame.payload().size(), payload.size());
QCOMPARE(frame.payload(), payload);
}
diff --git a/tests/auto/websockets/websocketframe/websocketframe.pro b/tests/auto/websockets/websocketframe/websocketframe.pro
deleted file mode 100644
index babb296..0000000
--- a/tests/auto/websockets/websocketframe/websocketframe.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_websocketframe
-
-QT = testlib websockets-private
-
-SOURCES += tst_websocketframe.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/websocketprotocol/CMakeLists.txt b/tests/auto/websockets/websocketprotocol/CMakeLists.txt
index 978f16e..dbb24db 100644
--- a/tests/auto/websockets/websocketprotocol/CMakeLists.txt
+++ b/tests/auto/websockets/websocketprotocol/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from websocketprotocol.pro.
if(NOT QT_FEATURE_private_tests)
@@ -8,10 +11,10 @@ endif()
## tst_websocketprotocol Test:
#####################################################################
-qt_add_test(tst_websocketprotocol
+qt_internal_add_test(tst_websocketprotocol
SOURCES
tst_websocketprotocol.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::WebSocketsPrivate
)
diff --git a/tests/auto/websockets/websocketprotocol/tst_websocketprotocol.cpp b/tests/auto/websockets/websocketprotocol/tst_websocketprotocol.cpp
index 2f8f933..37165f0 100644
--- a/tests/auto/websockets/websocketprotocol/tst_websocketprotocol.cpp
+++ b/tests/auto/websockets/websocketprotocol/tst_websocketprotocol.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QtEndian>
diff --git a/tests/auto/websockets/websocketprotocol/websocketprotocol.pro b/tests/auto/websockets/websocketprotocol/websocketprotocol.pro
deleted file mode 100644
index 22a8140..0000000
--- a/tests/auto/websockets/websocketprotocol/websocketprotocol.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-CONFIG += console
-CONFIG += testcase
-CONFIG -= app_bundle
-
-TEMPLATE = app
-
-TARGET = tst_websocketprotocol
-
-QT = testlib websockets-private
-
-SOURCES += tst_websocketprotocol.cpp
-
-requires(qtConfig(private_tests))
diff --git a/tests/auto/websockets/websockets.pro b/tests/auto/websockets/websockets.pro
deleted file mode 100644
index b000229..0000000
--- a/tests/auto/websockets/websockets.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS = \
- qwebsocketcorsauthenticator
-
-qtConfig(private_tests): SUBDIRS += \
- websocketprotocol \
- dataprocessor \
- websocketframe \
- handshakerequest \
- handshakeresponse \
- qdefaultmaskgenerator
-
-SUBDIRS += \
- qwebsocket \
- qwebsocketserver
diff --git a/tests/doc/README b/tests/doc/README.qdocinc
index da9b2b5..da9b2b5 100644
--- a/tests/doc/README
+++ b/tests/doc/README.qdocinc
diff --git a/tests/manual/compliance/tst_compliance.cpp b/tests/manual/compliance/tst_compliance.cpp
index 8ef3c14..20dc4bf 100644
--- a/tests/manual/compliance/tst_compliance.cpp
+++ b/tests/manual/compliance/tst_compliance.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QSignalSpy>
diff --git a/tests/manual/websockets/tst_websockets.cpp b/tests/manual/websockets/tst_websockets.cpp
index fa5a236..3c9e758 100644
--- a/tests/manual/websockets/tst_websockets.cpp
+++ b/tests/manual/websockets/tst_websockets.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebSockets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QSignalSpy>
diff --git a/tests/tests.pro b/tests/tests.pro
deleted file mode 100644
index dfc1ea0..0000000
--- a/tests/tests.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-TEMPLATE = subdirs
-
-CONFIG += no_docs_target
-
-SUBDIRS += auto