uws-react-native 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +84 -0
- package/UwsReactNative.podspec +71 -0
- package/android/build.gradle.kts +138 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
- package/apple/OnLoad.mm +17 -0
- package/cpp/CMakeLists.txt +154 -0
- package/cpp/UwsReactNativeModule.cpp +191 -0
- package/cpp/UwsReactNativeModule.h +30 -0
- package/cpp/app/AppHost.h +37 -0
- package/cpp/app/AppRunner.h +88 -0
- package/cpp/app/CMakeLists.txt +39 -0
- package/cpp/app/HttpRequestObject.h +173 -0
- package/cpp/app/HttpResponseObject.h +623 -0
- package/cpp/app/RecognizedString.h +71 -0
- package/cpp/app/TemplatedAppObject.h +472 -0
- package/cpp/bridging/ArrayBuffer.h +150 -0
- package/cpp/bridging/CMakeLists.txt +34 -0
- package/cpp/jsi/Buffer.h +91 -0
- package/cpp/jsi/CMakeLists.txt +34 -0
- package/cpp/uSockets/bsd.c +767 -0
- package/cpp/uSockets/context.c +524 -0
- package/cpp/uSockets/crypto/openssl.c +858 -0
- package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
- package/cpp/uSockets/eventing/asio.cpp +475 -0
- package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
- package/cpp/uSockets/eventing/gcd.c +278 -0
- package/cpp/uSockets/eventing/libuv.c +305 -0
- package/cpp/uSockets/internal/eventing/asio.h +45 -0
- package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
- package/cpp/uSockets/internal/eventing/gcd.h +40 -0
- package/cpp/uSockets/internal/eventing/libuv.h +45 -0
- package/cpp/uSockets/internal/internal.h +224 -0
- package/cpp/uSockets/internal/loop_data.h +38 -0
- package/cpp/uSockets/internal/networking/bsd.h +109 -0
- package/cpp/uSockets/io_uring/internal.h +98 -0
- package/cpp/uSockets/io_uring/io_context.c +302 -0
- package/cpp/uSockets/io_uring/io_loop.c +422 -0
- package/cpp/uSockets/io_uring/io_socket.c +139 -0
- package/cpp/uSockets/libusockets.h +350 -0
- package/cpp/uSockets/loop.c +396 -0
- package/cpp/uSockets/quic.c +1071 -0
- package/cpp/uSockets/quic.h +68 -0
- package/cpp/uSockets/socket.c +231 -0
- package/cpp/uSockets/udp.c +151 -0
- package/cpp/uWebSockets/uWebSockets/App.h +676 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
- package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
- package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
- package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
- package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
- package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
- package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
- package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
- package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
- package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
- package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
- package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
- package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
- package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
- package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
- package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
- package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
- package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
- package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
- package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
- package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
- package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
- package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
- package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
- package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
- package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
- package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
- package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/App.js +17 -0
- package/lib/commonjs/modules/App.js.map +1 -0
- package/lib/commonjs/modules/CompressOptions.js +103 -0
- package/lib/commonjs/modules/CompressOptions.js.map +1 -0
- package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
- package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
- package/lib/commonjs/modules/ListenOptions.js +12 -0
- package/lib/commonjs/modules/ListenOptions.js.map +1 -0
- package/lib/commonjs/modules/SSLApp.js +15 -0
- package/lib/commonjs/modules/SSLApp.js.map +1 -0
- package/lib/commonjs/modules/getParts.js +28 -0
- package/lib/commonjs/modules/getParts.js.map +1 -0
- package/lib/commonjs/modules/index.js +61 -0
- package/lib/commonjs/modules/index.js.map +1 -0
- package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
- package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
- package/lib/commonjs/modules/us_socket_local_port.js +22 -0
- package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/AppDescriptor.js +2 -0
- package/lib/commonjs/types/AppDescriptor.js.map +1 -0
- package/lib/commonjs/types/AppOptions.js +2 -0
- package/lib/commonjs/types/AppOptions.js.map +1 -0
- package/lib/commonjs/types/HttpRequest.js +6 -0
- package/lib/commonjs/types/HttpRequest.js.map +1 -0
- package/lib/commonjs/types/HttpResponse.js +6 -0
- package/lib/commonjs/types/HttpResponse.js.map +1 -0
- package/lib/commonjs/types/HttpRouterOptions.js +2 -0
- package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
- package/lib/commonjs/types/MultipartField.js +2 -0
- package/lib/commonjs/types/MultipartField.js.map +1 -0
- package/lib/commonjs/types/RecognizedString.js +2 -0
- package/lib/commonjs/types/RecognizedString.js.map +1 -0
- package/lib/commonjs/types/TemplatedApp.js +6 -0
- package/lib/commonjs/types/TemplatedApp.js.map +1 -0
- package/lib/commonjs/types/WebSocket.js +6 -0
- package/lib/commonjs/types/WebSocket.js.map +1 -0
- package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
- package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/us_listen_socket.js +2 -0
- package/lib/commonjs/types/us_listen_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket.js +2 -0
- package/lib/commonjs/types/us_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket_context_t.js +2 -0
- package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/App.js +12 -0
- package/lib/module/modules/App.js.map +1 -0
- package/lib/module/modules/CompressOptions.js +103 -0
- package/lib/module/modules/CompressOptions.js.map +1 -0
- package/lib/module/modules/EnvironmentVariables.js +13 -0
- package/lib/module/modules/EnvironmentVariables.js.map +1 -0
- package/lib/module/modules/ListenOptions.js +8 -0
- package/lib/module/modules/ListenOptions.js.map +1 -0
- package/lib/module/modules/SSLApp.js +15 -0
- package/lib/module/modules/SSLApp.js.map +1 -0
- package/lib/module/modules/getParts.js +23 -0
- package/lib/module/modules/getParts.js.map +1 -0
- package/lib/module/modules/index.js +11 -0
- package/lib/module/modules/index.js.map +1 -0
- package/lib/module/modules/us_listen_socket_close.js +17 -0
- package/lib/module/modules/us_listen_socket_close.js.map +1 -0
- package/lib/module/modules/us_socket_local_port.js +18 -0
- package/lib/module/modules/us_socket_local_port.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/AppDescriptor.js +2 -0
- package/lib/module/types/AppDescriptor.js.map +1 -0
- package/lib/module/types/AppOptions.js +2 -0
- package/lib/module/types/AppOptions.js.map +1 -0
- package/lib/module/types/HttpRequest.js +4 -0
- package/lib/module/types/HttpRequest.js.map +1 -0
- package/lib/module/types/HttpResponse.js +4 -0
- package/lib/module/types/HttpResponse.js.map +1 -0
- package/lib/module/types/HttpRouterOptions.js +2 -0
- package/lib/module/types/HttpRouterOptions.js.map +1 -0
- package/lib/module/types/MultipartField.js +2 -0
- package/lib/module/types/MultipartField.js.map +1 -0
- package/lib/module/types/RecognizedString.js +2 -0
- package/lib/module/types/RecognizedString.js.map +1 -0
- package/lib/module/types/TemplatedApp.js +4 -0
- package/lib/module/types/TemplatedApp.js.map +1 -0
- package/lib/module/types/WebSocket.js +4 -0
- package/lib/module/types/WebSocket.js.map +1 -0
- package/lib/module/types/WebSocketBehaviour.js +139 -0
- package/lib/module/types/WebSocketBehaviour.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/us_listen_socket.js +2 -0
- package/lib/module/types/us_listen_socket.js.map +1 -0
- package/lib/module/types/us_socket.js +2 -0
- package/lib/module/types/us_socket.js.map +1 -0
- package/lib/module/types/us_socket_context_t.js +2 -0
- package/lib/module/types/us_socket_context_t.js.map +1 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +3 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/App.d.ts +7 -0
- package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/index.d.ts +6 -0
- package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +6 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +3 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/App.d.ts +7 -0
- package/lib/typescript/module/modules/App.d.ts.map +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/module/modules/getParts.d.ts +6 -0
- package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/module/modules/index.d.ts +6 -0
- package/lib/typescript/module/modules/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/module/types/AppOptions.d.ts +17 -0
- package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/MultipartField.d.ts +7 -0
- package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocket.d.ts +96 -0
- package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +6 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/tsconfig.tsbuildinfo +1 -0
- package/package.json +62 -0
- package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
- package/src/index.ts +2 -0
- package/src/modules/App.ts +14 -0
- package/src/modules/CompressOptions.ts +101 -0
- package/src/modules/EnvironmentVariables.ts +16 -0
- package/src/modules/ListenOptions.ts +4 -0
- package/src/modules/SSLApp.ts +13 -0
- package/src/modules/getParts.ts +29 -0
- package/src/modules/index.ts +8 -0
- package/src/modules/us_listen_socket_close.ts +15 -0
- package/src/modules/us_socket_local_port.ts +16 -0
- package/src/types/AppDescriptor.ts +7 -0
- package/src/types/AppOptions.ts +22 -0
- package/src/types/HttpRequest.ts +74 -0
- package/src/types/HttpResponse.ts +309 -0
- package/src/types/HttpRouterOptions.ts +24 -0
- package/src/types/MultipartField.ts +6 -0
- package/src/types/RecognizedString.ts +11 -0
- package/src/types/TemplatedApp.ts +285 -0
- package/src/types/WebSocket.ts +147 -0
- package/src/types/WebSocketBehaviour.ts +137 -0
- package/src/types/index.ts +12 -0
- package/src/types/us_listen_socket.ts +6 -0
- package/src/types/us_socket.ts +6 -0
- package/src/types/us_socket_context_t.ts +6 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2020.
|
|
3
|
+
* Intellectual property of third-party.
|
|
4
|
+
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#ifndef UWS_WEBSOCKETPROTOCOL_H
|
|
19
|
+
#define UWS_WEBSOCKETPROTOCOL_H
|
|
20
|
+
|
|
21
|
+
#include <libusockets.h>
|
|
22
|
+
|
|
23
|
+
#include <cstdint>
|
|
24
|
+
#include <cstring>
|
|
25
|
+
#include <cstdlib>
|
|
26
|
+
#include <string_view>
|
|
27
|
+
|
|
28
|
+
#ifdef UWS_USE_SIMDUTF
|
|
29
|
+
#include <simdutf.h>
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
namespace uWS {
|
|
33
|
+
|
|
34
|
+
/* We should not overcomplicate these */
|
|
35
|
+
constexpr std::string_view ERR_TOO_BIG_MESSAGE("Received too big message");
|
|
36
|
+
constexpr std::string_view ERR_WEBSOCKET_TIMEOUT("WebSocket timed out from inactivity");
|
|
37
|
+
constexpr std::string_view ERR_INVALID_TEXT("Received invalid UTF-8");
|
|
38
|
+
constexpr std::string_view ERR_TOO_BIG_MESSAGE_INFLATION("Received too big message, or other inflation error");
|
|
39
|
+
constexpr std::string_view ERR_INVALID_CLOSE_PAYLOAD("Received invalid close payload");
|
|
40
|
+
constexpr std::string_view ERR_PROTOCOL("Received invalid WebSocket frame");
|
|
41
|
+
constexpr std::string_view ERR_TCP_FIN("Received TCP FIN before WebSocket close frame");
|
|
42
|
+
|
|
43
|
+
enum OpCode : unsigned char {
|
|
44
|
+
CONTINUATION = 0,
|
|
45
|
+
TEXT = 1,
|
|
46
|
+
BINARY = 2,
|
|
47
|
+
CLOSE = 8,
|
|
48
|
+
PING = 9,
|
|
49
|
+
PONG = 10
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
enum {
|
|
53
|
+
CLIENT,
|
|
54
|
+
SERVER
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// 24 bytes perfectly
|
|
58
|
+
template <bool isServer>
|
|
59
|
+
struct WebSocketState {
|
|
60
|
+
public:
|
|
61
|
+
static const unsigned int SHORT_MESSAGE_HEADER = isServer ? 6 : 2;
|
|
62
|
+
static const unsigned int MEDIUM_MESSAGE_HEADER = isServer ? 8 : 4;
|
|
63
|
+
static const unsigned int LONG_MESSAGE_HEADER = isServer ? 14 : 10;
|
|
64
|
+
|
|
65
|
+
// 16 bytes
|
|
66
|
+
struct State {
|
|
67
|
+
unsigned int wantsHead : 1;
|
|
68
|
+
unsigned int spillLength : 4;
|
|
69
|
+
signed int opStack : 2; // -1, 0, 1
|
|
70
|
+
unsigned int lastFin : 1;
|
|
71
|
+
|
|
72
|
+
// 15 bytes
|
|
73
|
+
unsigned char spill[LONG_MESSAGE_HEADER - 1];
|
|
74
|
+
OpCode opCode[2];
|
|
75
|
+
|
|
76
|
+
State() {
|
|
77
|
+
wantsHead = true;
|
|
78
|
+
spillLength = 0;
|
|
79
|
+
opStack = -1;
|
|
80
|
+
lastFin = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
} state;
|
|
84
|
+
|
|
85
|
+
// 8 bytes
|
|
86
|
+
unsigned int remainingBytes = 0;
|
|
87
|
+
char mask[isServer ? 4 : 1];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
namespace protocol {
|
|
91
|
+
|
|
92
|
+
template <typename T>
|
|
93
|
+
T bit_cast(char *c) {
|
|
94
|
+
T val;
|
|
95
|
+
memcpy(&val, c, sizeof(T));
|
|
96
|
+
return val;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Byte swap for little-endian systems */
|
|
100
|
+
template <typename T>
|
|
101
|
+
T cond_byte_swap(T value) {
|
|
102
|
+
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
|
103
|
+
uint32_t endian_test = 1;
|
|
104
|
+
if (*reinterpret_cast<char*>(&endian_test)) {
|
|
105
|
+
uint8_t src[sizeof(T)];
|
|
106
|
+
uint8_t dst[sizeof(T)];
|
|
107
|
+
|
|
108
|
+
std::memcpy(src, &value, sizeof(T));
|
|
109
|
+
for (size_t i = 0; i < sizeof(T); ++i) {
|
|
110
|
+
dst[i] = src[sizeof(T) - 1 - i];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
T result;
|
|
114
|
+
std::memcpy(&result, dst, sizeof(T));
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#ifdef UWS_USE_SIMDUTF
|
|
121
|
+
|
|
122
|
+
static bool isValidUtf8(unsigned char *s, size_t length)
|
|
123
|
+
{
|
|
124
|
+
return simdutf::validate_utf8((const char *)s, length);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#else
|
|
128
|
+
// Based on utf8_check.c by Markus Kuhn, 2005
|
|
129
|
+
// https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c
|
|
130
|
+
// Optimized for predominantly 7-bit content by Alex Hultman, 2016
|
|
131
|
+
// Licensed as Zlib, like the rest of this project
|
|
132
|
+
// This runs about 40% faster than simdutf with g++ -mavx
|
|
133
|
+
static bool isValidUtf8(unsigned char *s, size_t length)
|
|
134
|
+
{
|
|
135
|
+
for (unsigned char *e = s + length; s != e; ) {
|
|
136
|
+
if (s + 16 <= e) {
|
|
137
|
+
uint64_t tmp[2];
|
|
138
|
+
memcpy(tmp, s, 16);
|
|
139
|
+
if (((tmp[0] & 0x8080808080808080) | (tmp[1] & 0x8080808080808080)) == 0) {
|
|
140
|
+
s += 16;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
while (!(*s & 0x80)) {
|
|
146
|
+
if (++s == e) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if ((s[0] & 0x60) == 0x40) {
|
|
152
|
+
if (s + 1 >= e || (s[1] & 0xc0) != 0x80 || (s[0] & 0xfe) == 0xc0) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
s += 2;
|
|
156
|
+
} else if ((s[0] & 0xf0) == 0xe0) {
|
|
157
|
+
if (s + 2 >= e || (s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 ||
|
|
158
|
+
(s[0] == 0xe0 && (s[1] & 0xe0) == 0x80) || (s[0] == 0xed && (s[1] & 0xe0) == 0xa0)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
s += 3;
|
|
162
|
+
} else if ((s[0] & 0xf8) == 0xf0) {
|
|
163
|
+
if (s + 3 >= e || (s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 || (s[3] & 0xc0) != 0x80 ||
|
|
164
|
+
(s[0] == 0xf0 && (s[1] & 0xf0) == 0x80) || (s[0] == 0xf4 && s[1] > 0x8f) || s[0] > 0xf4) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
s += 4;
|
|
168
|
+
} else {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
struct CloseFrame {
|
|
178
|
+
uint16_t code;
|
|
179
|
+
char *message;
|
|
180
|
+
size_t length;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
static inline CloseFrame parseClosePayload(char *src, size_t length) {
|
|
184
|
+
/* If we get no code or message, default to reporting 1005 no status code present */
|
|
185
|
+
CloseFrame cf = {1005, nullptr, 0};
|
|
186
|
+
if (length >= 2) {
|
|
187
|
+
memcpy(&cf.code, src, 2);
|
|
188
|
+
cf = {cond_byte_swap<uint16_t>(cf.code), src + 2, length - 2};
|
|
189
|
+
if (cf.code < 1000 || cf.code > 4999 || (cf.code > 1011 && cf.code < 4000) ||
|
|
190
|
+
(cf.code >= 1004 && cf.code <= 1006) || !isValidUtf8((unsigned char *) cf.message, cf.length)) {
|
|
191
|
+
/* Even though we got a WebSocket close frame, it in itself is abnormal */
|
|
192
|
+
return {1006, (char *) ERR_INVALID_CLOSE_PAYLOAD.data(), ERR_INVALID_CLOSE_PAYLOAD.length()};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return cf;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static inline size_t formatClosePayload(char *dst, uint16_t code, const char *message, size_t length) {
|
|
199
|
+
/* We could have more strict checks here, but never append code 0 or 1005 or 1006 */
|
|
200
|
+
if (code && code != 1005 && code != 1006) {
|
|
201
|
+
code = cond_byte_swap<uint16_t>(code);
|
|
202
|
+
memcpy(dst, &code, 2);
|
|
203
|
+
/* It is invalid to pass nullptr to memcpy, even though length is 0 */
|
|
204
|
+
if (message) {
|
|
205
|
+
memcpy(dst + 2, message, length);
|
|
206
|
+
}
|
|
207
|
+
return length + 2;
|
|
208
|
+
}
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static inline size_t messageFrameSize(size_t messageSize) {
|
|
213
|
+
if (messageSize < 126) {
|
|
214
|
+
return 2 + messageSize;
|
|
215
|
+
} else if (messageSize <= UINT16_MAX) {
|
|
216
|
+
return 4 + messageSize;
|
|
217
|
+
}
|
|
218
|
+
return 10 + messageSize;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
enum {
|
|
222
|
+
SND_CONTINUATION = 1,
|
|
223
|
+
SND_NO_FIN = 2,
|
|
224
|
+
SND_COMPRESSED = 64
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
template <bool isServer>
|
|
228
|
+
static inline size_t formatMessage(char *dst, const char *src, size_t length, OpCode opCode, size_t reportedLength, bool compressed, bool fin) {
|
|
229
|
+
size_t messageLength;
|
|
230
|
+
size_t headerLength;
|
|
231
|
+
if (reportedLength < 126) {
|
|
232
|
+
headerLength = 2;
|
|
233
|
+
dst[1] = (char) reportedLength;
|
|
234
|
+
} else if (reportedLength <= UINT16_MAX) {
|
|
235
|
+
headerLength = 4;
|
|
236
|
+
dst[1] = 126;
|
|
237
|
+
uint16_t tmp = cond_byte_swap<uint16_t>((uint16_t) reportedLength);
|
|
238
|
+
memcpy(&dst[2], &tmp, sizeof(uint16_t));
|
|
239
|
+
} else {
|
|
240
|
+
headerLength = 10;
|
|
241
|
+
dst[1] = 127;
|
|
242
|
+
uint64_t tmp = cond_byte_swap<uint64_t>((uint64_t) reportedLength);
|
|
243
|
+
memcpy(&dst[2], &tmp, sizeof(uint64_t));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
dst[0] = (char) ((fin ? 128 : 0) | ((compressed && opCode) ? SND_COMPRESSED : 0) | (char) opCode);
|
|
247
|
+
|
|
248
|
+
//printf("%d\n", (int)dst[0]);
|
|
249
|
+
|
|
250
|
+
char mask[4];
|
|
251
|
+
if (!isServer) {
|
|
252
|
+
dst[1] |= 0x80;
|
|
253
|
+
uint32_t random = (uint32_t) rand();
|
|
254
|
+
memcpy(mask, &random, 4);
|
|
255
|
+
memcpy(dst + headerLength, &random, 4);
|
|
256
|
+
headerLength += 4;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
messageLength = headerLength + length;
|
|
260
|
+
memcpy(dst + headerLength, src, length);
|
|
261
|
+
|
|
262
|
+
if (!isServer) {
|
|
263
|
+
|
|
264
|
+
// overwrites up to 3 bytes outside of the given buffer!
|
|
265
|
+
//WebSocketProtocol<isServer>::unmaskInplace(dst + headerLength, dst + headerLength + length, mask);
|
|
266
|
+
|
|
267
|
+
// this is not optimal
|
|
268
|
+
char *start = dst + headerLength;
|
|
269
|
+
char *stop = start + length;
|
|
270
|
+
int i = 0;
|
|
271
|
+
while (start != stop) {
|
|
272
|
+
(*start++) ^= mask[i++ % 4];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return messageLength;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// essentially this is only a parser
|
|
281
|
+
template <const bool isServer, typename Impl>
|
|
282
|
+
struct WebSocketProtocol {
|
|
283
|
+
public:
|
|
284
|
+
static const unsigned int SHORT_MESSAGE_HEADER = isServer ? 6 : 2;
|
|
285
|
+
static const unsigned int MEDIUM_MESSAGE_HEADER = isServer ? 8 : 4;
|
|
286
|
+
static const unsigned int LONG_MESSAGE_HEADER = isServer ? 14 : 10;
|
|
287
|
+
|
|
288
|
+
protected:
|
|
289
|
+
static inline bool isFin(char *frame) {return *((unsigned char *) frame) & 128;}
|
|
290
|
+
static inline unsigned char getOpCode(char *frame) {return *((unsigned char *) frame) & 15;}
|
|
291
|
+
static inline unsigned char payloadLength(char *frame) {return ((unsigned char *) frame)[1] & 127;}
|
|
292
|
+
static inline bool rsv23(char *frame) {return *((unsigned char *) frame) & 48;}
|
|
293
|
+
static inline bool rsv1(char *frame) {return *((unsigned char *) frame) & 64;}
|
|
294
|
+
|
|
295
|
+
template <int N>
|
|
296
|
+
static inline void UnrolledXor(char * __restrict data, char * __restrict mask) {
|
|
297
|
+
if constexpr (N != 1) {
|
|
298
|
+
UnrolledXor<N - 1>(data, mask);
|
|
299
|
+
}
|
|
300
|
+
data[N - 1] ^= mask[(N - 1) % 4];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
template <int DESTINATION>
|
|
304
|
+
static inline void unmaskImprecise8(char *src, uint64_t mask, unsigned int length) {
|
|
305
|
+
for (unsigned int n = (length >> 3) + 1; n; n--) {
|
|
306
|
+
uint64_t loaded;
|
|
307
|
+
memcpy(&loaded, src, 8);
|
|
308
|
+
loaded ^= mask;
|
|
309
|
+
memcpy(src - DESTINATION, &loaded, 8);
|
|
310
|
+
src += 8;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* DESTINATION = 6 makes this not SIMD, DESTINATION = 4 is with SIMD but we don't want that for short messages */
|
|
315
|
+
template <int DESTINATION>
|
|
316
|
+
static inline void unmaskImprecise4(char *src, uint32_t mask, unsigned int length) {
|
|
317
|
+
for (unsigned int n = (length >> 2) + 1; n; n--) {
|
|
318
|
+
uint32_t loaded;
|
|
319
|
+
memcpy(&loaded, src, 4);
|
|
320
|
+
loaded ^= mask;
|
|
321
|
+
memcpy(src - DESTINATION, &loaded, 4);
|
|
322
|
+
src += 4;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
template <int HEADER_SIZE>
|
|
327
|
+
static inline void unmaskImpreciseCopyMask(char *src, unsigned int length) {
|
|
328
|
+
if constexpr (HEADER_SIZE != 6) {
|
|
329
|
+
char mask[8] = {src[-4], src[-3], src[-2], src[-1], src[-4], src[-3], src[-2], src[-1]};
|
|
330
|
+
uint64_t maskInt;
|
|
331
|
+
memcpy(&maskInt, mask, 8);
|
|
332
|
+
unmaskImprecise8<HEADER_SIZE>(src, maskInt, length);
|
|
333
|
+
} else {
|
|
334
|
+
char mask[4] = {src[-4], src[-3], src[-2], src[-1]};
|
|
335
|
+
uint32_t maskInt;
|
|
336
|
+
memcpy(&maskInt, mask, 4);
|
|
337
|
+
unmaskImprecise4<HEADER_SIZE>(src, maskInt, length);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
static inline void rotateMask(unsigned int offset, char *mask) {
|
|
342
|
+
char originalMask[4] = {mask[0], mask[1], mask[2], mask[3]};
|
|
343
|
+
mask[(0 + offset) % 4] = originalMask[0];
|
|
344
|
+
mask[(1 + offset) % 4] = originalMask[1];
|
|
345
|
+
mask[(2 + offset) % 4] = originalMask[2];
|
|
346
|
+
mask[(3 + offset) % 4] = originalMask[3];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
static inline void unmaskInplace(char *data, char *stop, char *mask) {
|
|
350
|
+
while (data < stop) {
|
|
351
|
+
*(data++) ^= mask[0];
|
|
352
|
+
*(data++) ^= mask[1];
|
|
353
|
+
*(data++) ^= mask[2];
|
|
354
|
+
*(data++) ^= mask[3];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
template <unsigned int MESSAGE_HEADER, typename T>
|
|
359
|
+
static inline bool consumeMessage(T payLength, char *&src, unsigned int &length, WebSocketState<isServer> *wState, void *user) {
|
|
360
|
+
if (getOpCode(src)) {
|
|
361
|
+
if (wState->state.opStack == 1 || (!wState->state.lastFin && getOpCode(src) < 2)) {
|
|
362
|
+
Impl::forceClose(wState, user, ERR_PROTOCOL);
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
wState->state.opCode[++wState->state.opStack] = (OpCode) getOpCode(src);
|
|
366
|
+
} else if (wState->state.opStack == -1) {
|
|
367
|
+
Impl::forceClose(wState, user, ERR_PROTOCOL);
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
wState->state.lastFin = isFin(src);
|
|
371
|
+
|
|
372
|
+
if (Impl::refusePayloadLength(payLength, wState, user)) {
|
|
373
|
+
Impl::forceClose(wState, user, ERR_TOO_BIG_MESSAGE);
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (payLength + MESSAGE_HEADER <= length) {
|
|
378
|
+
bool fin = isFin(src);
|
|
379
|
+
if (isServer) {
|
|
380
|
+
/* This guy can never be assumed to be perfectly aligned since we can get multiple messages in one read */
|
|
381
|
+
unmaskImpreciseCopyMask<MESSAGE_HEADER>(src + MESSAGE_HEADER, (unsigned int) payLength);
|
|
382
|
+
if (Impl::handleFragment(src, payLength, 0, wState->state.opCode[wState->state.opStack], fin, wState, user)) {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
if (Impl::handleFragment(src + MESSAGE_HEADER, payLength, 0, wState->state.opCode[wState->state.opStack], isFin(src), wState, user)) {
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (fin) {
|
|
392
|
+
wState->state.opStack--;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
src += payLength + MESSAGE_HEADER;
|
|
396
|
+
length -= (unsigned int) (payLength + MESSAGE_HEADER);
|
|
397
|
+
wState->state.spillLength = 0;
|
|
398
|
+
return false;
|
|
399
|
+
} else {
|
|
400
|
+
wState->state.spillLength = 0;
|
|
401
|
+
wState->state.wantsHead = false;
|
|
402
|
+
wState->remainingBytes = (unsigned int) (payLength - length + MESSAGE_HEADER);
|
|
403
|
+
bool fin = isFin(src);
|
|
404
|
+
if constexpr (isServer) {
|
|
405
|
+
memcpy(wState->mask, src + MESSAGE_HEADER - 4, 4);
|
|
406
|
+
uint64_t mask;
|
|
407
|
+
memcpy(&mask, src + MESSAGE_HEADER - 4, 4);
|
|
408
|
+
memcpy(((char *)&mask) + 4, src + MESSAGE_HEADER - 4, 4);
|
|
409
|
+
unmaskImprecise8<0>(src + MESSAGE_HEADER, mask, length);
|
|
410
|
+
rotateMask(4 - (length - MESSAGE_HEADER) % 4, wState->mask);
|
|
411
|
+
}
|
|
412
|
+
Impl::handleFragment(src + MESSAGE_HEADER, length - MESSAGE_HEADER, wState->remainingBytes, wState->state.opCode[wState->state.opStack], fin, wState, user);
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/* This one is nicely vectorized on both ARM64 and X64 - especially with -mavx */
|
|
418
|
+
static inline void unmaskAll(char * __restrict data, char * __restrict mask) {
|
|
419
|
+
for (int i = 0; i < LIBUS_RECV_BUFFER_LENGTH; i += 16) {
|
|
420
|
+
UnrolledXor<16>(data + i, mask);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
static inline bool consumeContinuation(char *&src, unsigned int &length, WebSocketState<isServer> *wState, void *user) {
|
|
425
|
+
if (wState->remainingBytes <= length) {
|
|
426
|
+
if (isServer) {
|
|
427
|
+
unsigned int n = wState->remainingBytes >> 2;
|
|
428
|
+
unmaskInplace(src, src + n * 4, wState->mask);
|
|
429
|
+
for (unsigned int i = 0, s = wState->remainingBytes % 4; i < s; i++) {
|
|
430
|
+
src[n * 4 + i] ^= wState->mask[i];
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (Impl::handleFragment(src, wState->remainingBytes, 0, wState->state.opCode[wState->state.opStack], wState->state.lastFin, wState, user)) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (wState->state.lastFin) {
|
|
439
|
+
wState->state.opStack--;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
src += wState->remainingBytes;
|
|
443
|
+
length -= wState->remainingBytes;
|
|
444
|
+
wState->state.wantsHead = true;
|
|
445
|
+
return true;
|
|
446
|
+
} else {
|
|
447
|
+
if (isServer) {
|
|
448
|
+
/* No need to unmask if mask is 0 */
|
|
449
|
+
uint32_t nullmask = 0;
|
|
450
|
+
if (memcmp(wState->mask, &nullmask, sizeof(uint32_t))) {
|
|
451
|
+
if /*constexpr*/ (LIBUS_RECV_BUFFER_LENGTH == length) {
|
|
452
|
+
unmaskAll(src, wState->mask);
|
|
453
|
+
} else {
|
|
454
|
+
// Slow path
|
|
455
|
+
unmaskInplace(src, src + ((length >> 2) + 1) * 4, wState->mask);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
wState->remainingBytes -= length;
|
|
461
|
+
if (Impl::handleFragment(src, length, wState->remainingBytes, wState->state.opCode[wState->state.opStack], wState->state.lastFin, wState, user)) {
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (isServer && length % 4) {
|
|
466
|
+
rotateMask(4 - (length % 4), wState->mask);
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
public:
|
|
473
|
+
WebSocketProtocol() {
|
|
474
|
+
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
static inline void consume(char *src, unsigned int length, WebSocketState<isServer> *wState, void *user) {
|
|
478
|
+
if (wState->state.spillLength) {
|
|
479
|
+
src -= wState->state.spillLength;
|
|
480
|
+
length += wState->state.spillLength;
|
|
481
|
+
memcpy(src, wState->state.spill, wState->state.spillLength);
|
|
482
|
+
}
|
|
483
|
+
if (wState->state.wantsHead) {
|
|
484
|
+
parseNext:
|
|
485
|
+
while (length >= SHORT_MESSAGE_HEADER) {
|
|
486
|
+
|
|
487
|
+
// invalid reserved bits / invalid opcodes / invalid control frames / set compressed frame
|
|
488
|
+
if ((rsv1(src) && !Impl::setCompressed(wState, user)) || rsv23(src) || (getOpCode(src) > 2 && getOpCode(src) < 8) ||
|
|
489
|
+
getOpCode(src) > 10 || (getOpCode(src) > 2 && (!isFin(src) || payloadLength(src) > 125))) {
|
|
490
|
+
Impl::forceClose(wState, user, ERR_PROTOCOL);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (payloadLength(src) < 126) {
|
|
495
|
+
if (consumeMessage<SHORT_MESSAGE_HEADER, uint8_t>(payloadLength(src), src, length, wState, user)) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
} else if (payloadLength(src) == 126) {
|
|
499
|
+
if (length < MEDIUM_MESSAGE_HEADER) {
|
|
500
|
+
break;
|
|
501
|
+
} else if(consumeMessage<MEDIUM_MESSAGE_HEADER, uint16_t>(protocol::cond_byte_swap<uint16_t>(protocol::bit_cast<uint16_t>(src + 2)), src, length, wState, user)) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
} else if (length < LONG_MESSAGE_HEADER) {
|
|
505
|
+
break;
|
|
506
|
+
} else if (consumeMessage<LONG_MESSAGE_HEADER, uint64_t>(protocol::cond_byte_swap<uint64_t>(protocol::bit_cast<uint64_t>(src + 2)), src, length, wState, user)) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (length) {
|
|
511
|
+
memcpy(wState->state.spill, src, length);
|
|
512
|
+
wState->state.spillLength = length & 0xf;
|
|
513
|
+
}
|
|
514
|
+
} else if (consumeContinuation(src, length, wState, user)) {
|
|
515
|
+
goto parseNext;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
static const int CONSUME_POST_PADDING = 4;
|
|
520
|
+
static const int CONSUME_PRE_PADDING = LONG_MESSAGE_HEADER - 1;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
#endif // UWS_WEBSOCKETPROTOCOL_H
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
/**
|
|
9
|
+
* This spec is only for C++.
|
|
10
|
+
*/
|
|
11
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing("ReactNativeUws");
|
|
12
|
+
//# sourceMappingURL=NativeReactNativeUws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../../src","sources":["_internal/native-modules/NativeReactNativeUws.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GA+BeC,gCAAmB,CAACC,YAAY,CAC9C,gBACD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _index = require("./modules/index.js");
|
|
7
|
+
Object.keys(_index).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _index[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _index2 = require("./types/index.js");
|
|
18
|
+
Object.keys(_index2).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _index2[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _index2[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_index2"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.App = App;
|
|
7
|
+
var _NativeReactNativeUws = _interopRequireDefault(require("../_internal/native-modules/NativeReactNativeUws.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a non-SSL app. An app is your starting point where you attach behavior to URL routes.
|
|
11
|
+
* This is also where you listen and run your app, set any SSL options (in case of SSLApp) and the like.
|
|
12
|
+
*/
|
|
13
|
+
function App(/* options?: AppOptions */
|
|
14
|
+
) {
|
|
15
|
+
return _NativeReactNativeUws.default.App(/* options */);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=App.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_NativeReactNativeUws","_interopRequireDefault","require","e","__esModule","default","App","NativeReactNativeUws"],"sourceRoot":"../../../src","sources":["modules/App.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAmF,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAOnF;AACA;AACA;AACA;AACO,SAASG,GAAGA,CAAC;AAAA,EAA2C;EAC9D,OAAOC,6BAAoB,CAACD,GAAG,CAAC,cAAc;AAC/C","ignoreList":[]}
|