更新libwebsocket 到patch1201 2993/1 2993/head 2996/target/1 2997/target/1
author孙春阳 <snickersun@163.com>
Mon, 29 Dec 2025 08:05:15 +0000 (16:05 +0800)
committer孙春阳 <snickersun@163.com>
Mon, 29 Dec 2025 08:05:15 +0000 (16:05 +0800)
12 files changed:
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js-ln/libwebsocket.a
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_debug.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h with 95% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_frame.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h with 58% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_list.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h with 89% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_opts.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h with 82% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_priv.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h with 91% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_string.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h with 85% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/internal/net_websocket_thread.h [moved from code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h with 82% similarity]
code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp
code/sdk/zhihui/websocket/src/zhihui_websocket.c

index 8dfa5e2..c8de21d 100644 (file)
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
index 8dfa5e2..c8de21d 100644 (file)
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
index c9d6278..302c7cd 100644 (file)
@@ -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;
 
 
@@ -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 <stdint.h>
+#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
 #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);
@@ -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 <stdio.h>
-#include <pthread.h>
+#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
index 307e315..23419a9 100644 (file)
@@ -105,7 +105,7 @@ static void OnError(int client, struct WebSocketErrorResult errorResult)
     JSI::ReleaseValueList(value, err);\r
 }\r
 \r
-static void OnClose(int client)\r
+static void OnClose(int client, struct WebSocketErrorResult errorResult)\r
 {\r
     auto it = WebsocketModule::eventCallbacks.find(std::string("open"));\r
     if (it == WebsocketModule::eventCallbacks.end()) {\r
index 8b2fdb9..17e3ff6 100644 (file)
@@ -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);
     }
 }