From: 孙春阳 Date: Mon, 29 Dec 2025 08:05:15 +0000 (+0800) Subject: 更新libwebsocket 到patch1201 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f6362e41ad1c805fbd8f02445d20c767e7a1858e;p=mirrors%2FFD230.git 更新libwebsocket 到patch1201 --- diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js-ln/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js-ln/libwebsocket.a index 8dfa5e251..c8de21d14 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js-ln/libwebsocket.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js-ln/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a index 8dfa5e251..c8de21d14 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h index c9d627801..302c7cda3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h @@ -73,7 +73,7 @@ typedef void (*WebSocketOnErrorCallback)(int client, struct WebSocketErrorResult * * @param client WebSocket client. */ -typedef void (*WebSocketOnCloseCallback)(int client); +typedef void (*WebSocketOnCloseCallback)(int client, struct WebSocketErrorResult errorResult); typedef enum WebSocketErrCode { @@ -158,6 +158,8 @@ typedef enum WebSocketErrCode { WEBSOCKET_ERROR_CONNECT_TO_HOST = (-19), WEBSOCKET_ERROR_CONNECT_CLOSED = (-20), + + WEBSOCKE_ERROR_CONNECTION_NOT_CLOSED = (-21), } WebSocketErrCode; diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_debug.h similarity index 95% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_debug.h index 00c99b6cc..4e4a0be2b 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_debug.h @@ -7,7 +7,7 @@ #include -#define WS_DBG_LEVEL WEBSOCKET_DBG_ON +#define WS_DBG_LEVEL WEBSOCKET_DBG_OFF #define WS_INFO_LEVEL WEBSOCKET_DBG_ON diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_frame.h similarity index 58% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_frame.h index 1112cedc9..fd6971db4 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_frame.h @@ -2,13 +2,14 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. */ -#ifndef _WS_FRAME_H__ -#define _WS_FRAME_H__ +#ifndef _NET_WS_FRAME_H__ +#define _NET_WS_FRAME_H__ -#include "net_websocket.h" #include +#include "net_websocket.h" +#include "net_websocket_priv.h" -typedef enum _rws_opcode { +typedef enum { WS_OPCODE_CONTINUATION = 0x0, // %x0 denotes a continuation frame WS_OPCODE_TEXT_FRAME = 0x1, // %x1 denotes a text frame WS_OPCODE_BINARY_FRAME = 0x2, // %x2 denotes a binary frame @@ -20,7 +21,7 @@ typedef enum _rws_opcode { typedef enum WsBinaryCode { WS_BINARY_START, WS_BINARY_CONTINUE, WS_BINARY_END } WsBinary; typedef struct WsFrameStruct { - void *data; + uint8_t *data; size_t length; WsOpcode opcode; uint8_t mask[4]; /* 4: mask length */ @@ -29,20 +30,24 @@ typedef struct WsFrameStruct { uint8_t headerSize; } WsFrame; -size_t WsCheckRecvFrameSize(const void *data, const size_t data_size); +size_t WsCheckRecvFrameSize(const uint8_t *data, const size_t data_size); -WsFrame *WsFrameCreateWithRecvData(const void *data, const size_t data_size); +WsFrame *WsFrameCreateWithRecvData(struct WebSocketClient *clientPtr, const uint8_t *data, const size_t length); -void WsFrameFillWithSendBinData(WsFrame *f, const void *data, const size_t length, WsBinary binType); +void WsFrameFillWithSendBinData(WsFrame *frame, const uint8_t *data, const size_t length, WsBinary binType); // data - should be null, and setted by newly created. 'data' & 'data_size' can be null -void WsFrameFillWithSendData(WsFrame *f, const void *data, const size_t data_size, bool is_finish); +void WsFrameFillWithSendData(WsFrame *frame, const uint8_t *data, const size_t data_size, bool is_finish); // combine datas of 2 frames. combined is 'to' void WsFrameCombineDatas(WsFrame *to, WsFrame *from); -WsFrame *WsFrameCreate(void); +WsFrame *WsFrameCreate(struct WebSocketClient *clientPtr); + +void WsDeleteFrame(WsFrame *frame); + +void WsInitFrameRandom(struct WebSocketClient *clientPtr); -void WsDeleteFrame(WsFrame *f); +void WsFreeRandom(struct WebSocketClient *clientPtr); #endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_list.h similarity index 89% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_list.h index 1a34ddc37..74bd2747a 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_list.h @@ -2,8 +2,8 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. */ -#ifndef __WS_LIST_H__ -#define __WS_LIST_H__ +#ifndef __NET_WS_LIST_H__ +#define __NET_WS_LIST_H__ #include diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_opts.h similarity index 82% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_opts.h index 61ec0835a..54dca87d0 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_opts.h @@ -11,13 +11,12 @@ #define WS_MAX_CLIENT_NUM 4 -#define WS_MAX_URI_LENGTH 512 - #define WS_MAX_DATA_LENGTH (20 * 1024) -#define WS_HANDSHAKE_BUF_LEN 1024 - #define WSS_READ_TIMEOUT_MS 100 +#define WS_THREAD_STACK_SIZE (6 * 1024) + +#define WS_THREAD_SLEEP_MS 100 #endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_priv.h similarity index 91% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_priv.h index 2159d7b66..0151115c8 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_priv.h @@ -17,11 +17,12 @@ #include "net_websocket_frame.h" #include "net_websocket_list.h" +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/entropy.h" + #ifdef WEBSOCKET_SSL_ENABLE #include "mbedtls/net_sockets.h" #include "mbedtls/ssl.h" -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" #endif typedef int WsSocket; @@ -44,13 +45,16 @@ typedef struct WsSslStruct { } WsSsl; #endif +#define WS_MAX_SCHEME_LEN 16 + struct WebSocketClient { int clientfd; int port; WsSocket socket; - char scheme[WS_MAX_URI_LENGTH]; - char host[WS_MAX_URI_LENGTH]; - char path[WS_MAX_URI_LENGTH]; + char scheme[WS_MAX_SCHEME_LEN]; + char *url; + char *host; + char *requestOption; char *secWsProtocol; // "Sec-WebSocket-Protocol" field char *secWsAccept; // "Sec-WebSocket-Accept" field from handshake @@ -61,7 +65,6 @@ struct WebSocketClient { bool isConnected; // sock connected + handshake done - void *userObject; /** Pointer to the callback invoked when a connection message is received */ WebSocketOnOpenCallback onOpen; /** Pointer to the callback invoked when a message is received */ @@ -71,7 +74,7 @@ struct WebSocketClient { /** Pointer to the callback invoked when a close message is received */ WebSocketOnCloseCallback onClose; - void *received; + uint8_t *received; size_t receivedSize; // size of 'received' memory size_t receivedLen; // length of actualy readed message @@ -80,7 +83,9 @@ struct WebSocketClient { WsMutex workMutex; WsMutex sendMutex; - WsSem exitSem; + + mbedtls_entropy_context randomEntropy; /* random entropy */ + mbedtls_ctr_drbg_context randomCtrDrbg; #ifdef WEBSOCKET_SSL_ENABLE const char *serverCert; /**< Server certification. */ @@ -93,6 +98,8 @@ struct WebSocketClient { #endif char *recvBuffer; int recvBufferSize; + + struct WebSocketErrorResult errorResult; }; void WebSocketClientClosePriv(struct WebSocketClient *clientPtr); @@ -101,8 +108,6 @@ struct WebSocketClient *WsGetClient(int fd); int AllocWsClient(void); -bool WsParseUrl(const char *url, char *prefix, char *address, char *path, int *port); - int WsSocketSendTextPriv(struct WebSocketClient *clientPtr, const char *text); int WsClientSendBinStartPriv(struct WebSocketClient *clientPtr, const char *data, size_t length); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_string.h similarity index 85% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_string.h index 12451a505..2e4325c37 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_string.h @@ -1,8 +1,8 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. */ -#ifndef __RWS_STRING_H__ -#define __RWS_STRING_H__ +#ifndef __NET_WS_STRING_H__ +#define __NET_WS_STRING_H__ #include #include diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_thread.h similarity index 82% rename from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h rename to code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_thread.h index 9da00ec0f..08d6fea63 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_thread.h @@ -2,11 +2,11 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. */ -#ifndef __RWS_THREAD_H__ -#define __RWS_THREAD_H__ +#ifndef __NET_WS_THREAD_H__ +#define __NET_WS_THREAD_H__ #include -#include +#include "cmsis_os2.h" #define RWS_WAIT_FOREVER 0xffffffffu @@ -18,8 +18,8 @@ typedef void (*WsThreadFunct)(void *userObject); struct WsThreadStruct { WsThreadFunct threadFunction; - void *userObject; - pthread_t thread; + osThreadId_t thread; + void *stackMem; }; /** @@ -60,5 +60,8 @@ void WsSemDelete(WsSem sem); void WsSemSignal(WsSem sem); +int WsThreadSuspend(WsThread workThread); + +int WsThreadResume(WsThread workThread); #endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp index 307e315d1..23419a95a 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp @@ -105,7 +105,7 @@ static void OnError(int client, struct WebSocketErrorResult errorResult) JSI::ReleaseValueList(value, err); } -static void OnClose(int client) +static void OnClose(int client, struct WebSocketErrorResult errorResult) { auto it = WebsocketModule::eventCallbacks.find(std::string("open")); if (it == WebsocketModule::eventCallbacks.end()) { diff --git a/code/sdk/zhihui/websocket/src/zhihui_websocket.c b/code/sdk/zhihui/websocket/src/zhihui_websocket.c index 8b2fdb949..17e3ff619 100644 --- a/code/sdk/zhihui/websocket/src/zhihui_websocket.c +++ b/code/sdk/zhihui/websocket/src/zhihui_websocket.c @@ -354,7 +354,11 @@ static void zhihui_ws_recv_thread_func(void *arg) // 调用关闭回调 if (client->on_close) { - client->on_close(client->client_fd); + struct WebSocketErrorResult error = { + .errorCode = WEBSOCKET_CONNECTION_CLOSED_BY_PEER, + .errorMessage = "WebSocket connection closed by peer" + }; + client->on_close(client->client_fd,error); } }