From 631ad1661427a8363b62455f5502c3ff44ca6500 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 22 Nov 2023 14:52:31 +0800 Subject: [PATCH 01/36] add websocket interface build Signed-off-by: liuxiyao223 --- nestack/net_websocket/BUILD.gn | 30 ++ nestack/net_websocket/include/net_websocket.h | 141 +++++++++ .../include/net_websocket_type.h | 286 ++++++++++++++++++ nestack/net_websocket/libwebsocket.ndk.json | 9 + 4 files changed, 466 insertions(+) create mode 100755 nestack/net_websocket/BUILD.gn create mode 100755 nestack/net_websocket/include/net_websocket.h create mode 100755 nestack/net_websocket/include/net_websocket_type.h create mode 100755 nestack/net_websocket/libwebsocket.ndk.json diff --git a/nestack/net_websocket/BUILD.gn b/nestack/net_websocket/BUILD.gn new file mode 100755 index 00000000000..f777ab28c28 --- /dev/null +++ b/nestack/net_websocket/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_ndk_library("libnet_websocket") { + output_name = "net_websocket" + output_extension = "so" + ndk_description_file = "./libwebsocket.ndk.json" + min_compact_version = "1" + system_capability = "SystemCapability.Communication.Netstack" +} + +ohos_ndk_headers("websocket_header") { + dest_dir = "$ndk_headers_out_dir/net_websocket" + sources = [ + "./include/net_websocket.h", + "./include/net_websocket_type.h", + ] +} diff --git a/nestack/net_websocket/include/net_websocket.h b/nestack/net_websocket/include/net_websocket.h new file mode 100755 index 00000000000..8470bcc3ca6 --- /dev/null +++ b/nestack/net_websocket/include/net_websocket.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_WEBSOCKET_H +#define NET_WEBSOCKET_H + +#include +#include +#include + +/** + * @addtogroup netstack + * @{ + * + * @brief Provides C APIs for the WebSocket client module. + + * @since 11 + * @version 1.0 + */ + +/** + * @file net_websocket.h + * + * @brief Defines the APIs for the WebSocket client module. + * + * @library libnet_websocket.so + * @syscap SystemCapability.Communication.Netstack + * @since 11 + * @version 1.0 + */ + +#include "net_websocket_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Constructor of OH_NetStack_WebsocketClient. + * + * @param onMessage Callback function invoked when a message is received. + * @param onClose Callback function invoked when a connection closing message is closed. + * @param onError Callback function invoked when a connection error message is received. + * @param onOpen Callback function invoked when a connection setup message is received. + * @return Pointer to the WebSocket client if success; NULL otherwise. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient *OH_NetStack_WebsocketClient_Construct( + OH_NetStack_WebsocketClient_OnOpenCallback onOpen, OH_NetStack_WebsocketClient_OnMessageCallback onMessage, + OH_NetStack_WebsocketClient_OnErrorCallback onError, OH_NetStack_WebsocketClient_OnCloseCallback onclose); + +/** + * @brief Adds the header information to the client request. + * + * @param client Pointer to the WebSocket client. + * @param header Header information + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *client, + struct OH_NetStack_WebsocketClient_Slist header); + +/** + * @brief Connects the client to the server. + * + * @param client Pointer to the WebSocket client. + * @param url URL for the client to connect to the server. + * @param options Optional parameters. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Connect(struct OH_NetStack_WebsocketClient *client, const char *url, + struct OH_NetStack_WebsocketClient_RequestOptions options); + +/** + * @brief Sends data from the client to the server. + * + * @param client Pointer to the WebSocket client. + * @param data Data sent by the client. + * @param length Length of the data sent by the client. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Send(struct OH_NetStack_WebsocketClient *client, char *data, size_t length); + +/** + * @brief Closes a WebSocket connection. + * + * @param client Pointer to the WebSocket client. + * @param url URL for the client to connect to the server. + * @param options Optional parameters. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Close(struct OH_NetStack_WebsocketClient *client, + struct OH_NetStack_WebsocketClient_CloseOption options); + +/** + * @brief Releases the context and resources of the WebSocket connection. + * + * @param client Pointer to the WebSocket client. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *client); + +#ifdef __cplusplus +} +#endif + +#endif // NET_WEBSOCKET_H diff --git a/nestack/net_websocket/include/net_websocket_type.h b/nestack/net_websocket/include/net_websocket_type.h new file mode 100755 index 00000000000..9fd5e0b3ac1 --- /dev/null +++ b/nestack/net_websocket/include/net_websocket_type.h @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_WEBSOCKET_TYPE_H +#define NET_WEBSOCKET_TYPE_H + +/** + * @addtogroup netstack + * @{ + * + * @brief Provides C APIs for the WebSocket client module. + * + * @since 11 + * @version 1.0 + */ + +/** + * @file net_websocket_type.h + * @brief Defines the data structure for the C APIs of the WebSocket client module. + * + * @library libnet_websocket.so + * @syscap SystemCapability.Communication.Netstack + * @since 11 + * @version 1.0 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the parameters for connection closing by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_CloseResult { + /** Error code */ + uint32_t code; + /** Error cause */ + const char *reason; +}; + +/** + * @brief Defines the parameters for proactive connection closing by the client. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_CloseOption { + /** Error code */ + uint32_t code; + /** Error cause */ + const char *reason; +}; + +/** + * @brief Defines the parameters for the connection error reported by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_ErrorResult { + /** Error code */ + uint32_t errorCode; + /** Error message */ + const char *errorMessage; +}; + +/** + * @brief Defines the parameters for the connection success reported by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_OpenResult { + /** Connection success code */ + uint32_t code; + /** Connection success reason */ + const char *reason; +}; + +/** + * @brief Defines the callback function invoked when an open message is received. + * + * @param client WebSocket client. + * @param openResult Content of the open message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnOpenCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_OpenResult openResult); + +/** + * @brief Defines the callback function invoked when data is received. + * + * @param client WebSocket client. + * @param data Data received by the WebSocket client. + * @param length Length of the data received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnMessageCallback)(struct OH_NetStack_WebsocketClient *client, char *data, + uint32_t length); + +/** + * @brief Defines the callback function invoked when an error message is received. + * + * @param client WebSocket client. + * @param errorResult Content of the connection error message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnErrorCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_ErrorResult errorResult); + +/** + * @brief Defines the callback function invoked when a close message is received. + * + * @param client WebSocket client. + * @param closeResult Content of the close message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnCloseCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_CloseResult closeResult); + +/** + * @brief Adds the header linked list to the WebSocket client. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_Slist { + /** Header field name */ + const char *fieldName; + /** Header field content */ + const char *fieldValue; + /** Next pointer of the header linked list */ + struct OH_NetStack_WebsocketClient_Slist *next; +}; + +/** + * @brief Defines the parameters for the connection between the WebSocket client and server. + * + * @param headers Header information. + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_RequestOptions { + struct OH_NetStack_WebsocketClient_Slist *headers; +}; + +/** + * @brief Defines the WebSocket client structure. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient { + /** Pointer to the callback invoked when a connection message is received */ + OH_NetStack_WebsocketClient_OnOpenCallback onOpen; + /** Pointer to the callback invoked when a message is received */ + OH_NetStack_WebsocketClient_OnMessageCallback onMessage; + /** Pointer to the callback invoked when an error message is received */ + OH_NetStack_WebsocketClient_OnErrorCallback onError; + /** Pointer to the callback invoked when a close message is received */ + OH_NetStack_WebsocketClient_OnCloseCallback onClose; + /** Content of the request for establishing a connection on the client */ + OH_NetStack_WebsocketClient_RequestOptions requestOptions; +}; + +typedef enum OH_Websocket_ErrCode { + /** + * Operation success. + */ + WEBSOCKET_OK = 0, + + /** + * @brief Error code base. + */ + E_BASE = 1000, + + /** + * @brief The WebSocket client is null. + */ + WEBSOCKET_CLIENT_IS_NULL = (E_BASE + 1), + + /** + * @brief A WebSocket client is not created. + */ + WEBSOCKET_CLIENT_IS_NOT_CREAT = (E_BASE + 2), + + /** + * @brief An error occurs while setting up a WebSocket connection. + */ + WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), + + /** + * @brief An error occurs while parsing WebSocket connection parameters. + */ + WEBSOCKET_CONNECTION_PARSEURL_ERROR = (E_BASE + 5), + + /** + * @brief The memory is insufficient for creating a context during WebSocket connection setup. + */ + WEBSOCKET_CONNECTION_NO_MEMOERY = (E_BASE + 6), + + /** + * @brief The WebSocket connection is closed by the peer. + */ + WEBSOCKET_PEER_INITIATED_CLOSE = (E_BASE + 7), + + /** + * @brief The WebSocket connection is destroyed. + */ + WEBSOCKET_DESTROY = (E_BASE + 8), + + /** + * @brief An incorrect protocol is used for WebSocket connection. + */ + WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), + + /** + * @brief The memory for the WebSocket client to send data is insufficient. + */ + WEBSOCKET_SEND_NO_MEMOERY_ERROR = (E_BASE + 10), + + /** + * @brief The data sent by the WebSocket client is null. + */ + WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), + + /** + * @brief The length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_DATA_LENGTH_EXCEEDS = (E_BASE + 12), + + /** + * @brief The queue length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_QUEUE_LENGTH_EXCEEDS = (E_BASE + 13), + + /** + * @brief The context of the WebSocket client is null. + */ + WEBSOCKET_ERROR_NO_CLIENTCONTEX = (E_BASE + 14), + + /** + * @brief The header of the WebSocket client is null. + */ + WEBSOCKET_ERROR_NO_HEADR_CONTEXT = (E_BASE + 15), + + /** + * @brief The header of the WebSocket client exceeds the limit. + */ + WEBSOCKET_ERROR_NO_HEADR_EXCEEDS = (E_BASE + 16), + + /** + * @brief The WebSocket client is not connected. + */ + WEBSOCKET_ERROR_HAVE_NO_CONNECT = (E_BASE + 17), + + /** + * @brief The WebSocket client does not have the connection context. + */ + WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), +} OH_Websocket_ErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // NET_WEBSOCKET_TYPE_H \ No newline at end of file diff --git a/nestack/net_websocket/libwebsocket.ndk.json b/nestack/net_websocket/libwebsocket.ndk.json new file mode 100755 index 00000000000..9a17f527c83 --- /dev/null +++ b/nestack/net_websocket/libwebsocket.ndk.json @@ -0,0 +1,9 @@ +[ + {"name": "OH_NetStack_WebsocketClient_Construct"}, + {"name": "OH_NetStack_WebSocketClient_AddHeader"}, + {"name": "OH_NetStack_WebSocketClient_Connect"}, + {"name": "OH_NetStack_WebSocketClient_Send"}, + {"name": "OH_NetStack_WebSocketClient_Close"}, + {"name": "OH_NetStack_WebsocketClient_Destroy"}, + {"name": "OH_NetStack_WebSocketClient_FreeAll"} +] \ No newline at end of file -- Gitee From c7d147c1ddafa06739cba294d6fd8fd9e2a18684 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 24 Nov 2023 07:56:57 +0000 Subject: [PATCH 02/36] update nestack/net_websocket/include/net_websocket.h. Signed-off-by: Aurora --- nestack/net_websocket/include/net_websocket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nestack/net_websocket/include/net_websocket.h b/nestack/net_websocket/include/net_websocket.h index 8470bcc3ca6..419488869d8 100755 --- a/nestack/net_websocket/include/net_websocket.h +++ b/nestack/net_websocket/include/net_websocket.h @@ -138,4 +138,4 @@ int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *clie } #endif -#endif // NET_WEBSOCKET_H +#endif // NET_WEBSOCKET_H \ No newline at end of file -- Gitee From 60d9b37a5037d3cb5609c3325dfb882caeb5bca9 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 24 Nov 2023 08:01:40 +0000 Subject: [PATCH 03/36] update nestack/net_websocket/include/net_websocket.h. Signed-off-by: Aurora --- nestack/net_websocket/include/net_websocket.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nestack/net_websocket/include/net_websocket.h b/nestack/net_websocket/include/net_websocket.h index 419488869d8..d47efc797cf 100755 --- a/nestack/net_websocket/include/net_websocket.h +++ b/nestack/net_websocket/include/net_websocket.h @@ -36,7 +36,7 @@ * @brief Defines the APIs for the WebSocket client module. * * @library libnet_websocket.so - * @syscap SystemCapability.Communication.Netstack + * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ @@ -70,7 +70,6 @@ struct OH_NetStack_WebsocketClient *OH_NetStack_WebsocketClient_Construct( * @param client Pointer to the WebSocket client. * @param header Header information * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 @@ -85,7 +84,6 @@ int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *cl * @param url URL for the client to connect to the server. * @param options Optional parameters. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 -- Gitee From 2f385bec1ad5e48e8fa087045407a57c55d9cc69 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 24 Nov 2023 08:04:20 +0000 Subject: [PATCH 04/36] update nestack/net_websocket/BUILD.gn. Signed-off-by: Aurora --- nestack/net_websocket/BUILD.gn | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nestack/net_websocket/BUILD.gn b/nestack/net_websocket/BUILD.gn index f777ab28c28..c8828d77cf0 100755 --- a/nestack/net_websocket/BUILD.gn +++ b/nestack/net_websocket/BUILD.gn @@ -18,7 +18,11 @@ ohos_ndk_library("libnet_websocket") { output_extension = "so" ndk_description_file = "./libwebsocket.ndk.json" min_compact_version = "1" - system_capability = "SystemCapability.Communication.Netstack" + system_capability = "SystemCapability.Communication.NetStack" + system_capability_headers = [ + "./include/net_websocket.h", + "./include/net_websocket_type.h", + ] } ohos_ndk_headers("websocket_header") { -- Gitee From 7879113a4c4f9fda4fe2b98590a727a60b101d5b Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 24 Nov 2023 08:16:52 +0000 Subject: [PATCH 05/36] update nestack/net_websocket/include/net_websocket_type.h. Signed-off-by: Aurora --- nestack/net_websocket/include/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nestack/net_websocket/include/net_websocket_type.h b/nestack/net_websocket/include/net_websocket_type.h index 9fd5e0b3ac1..9cd8bf9c628 100755 --- a/nestack/net_websocket/include/net_websocket_type.h +++ b/nestack/net_websocket/include/net_websocket_type.h @@ -31,7 +31,7 @@ * @brief Defines the data structure for the C APIs of the WebSocket client module. * * @library libnet_websocket.so - * @syscap SystemCapability.Communication.Netstack + * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -- Gitee From f3d50628344d2369e0b1b57830c0ca841f2f94c4 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 24 Nov 2023 08:23:43 +0000 Subject: [PATCH 06/36] update nestack/net_websocket/include/net_websocket.h. Signed-off-by: Aurora --- nestack/net_websocket/include/net_websocket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestack/net_websocket/include/net_websocket.h b/nestack/net_websocket/include/net_websocket.h index d47efc797cf..9258fc7793a 100755 --- a/nestack/net_websocket/include/net_websocket.h +++ b/nestack/net_websocket/include/net_websocket.h @@ -55,7 +55,6 @@ extern "C" { * @param onError Callback function invoked when a connection error message is received. * @param onOpen Callback function invoked when a connection setup message is received. * @return Pointer to the WebSocket client if success; NULL otherwise. - * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 @@ -84,6 +83,7 @@ int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *cl * @param url URL for the client to connect to the server. * @param options Optional parameters. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 @@ -136,4 +136,4 @@ int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *clie } #endif -#endif // NET_WEBSOCKET_H \ No newline at end of file +#endif // NET_WEBSOCKET_H -- Gitee From 92f488af5f8c613ed140cfb9c2e6b7fd9404e5a7 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 24 Nov 2023 19:42:01 +0800 Subject: [PATCH 07/36] add websocket client interface sdk c Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/BUILD.gn | 34 +++ .../net_websocket/libwebsocket.ndk.json | 9 + .../netstack/net_websocket/net_websocket.h | 139 +++++++++ .../net_websocket/net_websocket_type.h | 286 ++++++++++++++++++ 4 files changed, 468 insertions(+) create mode 100755 network/netstack/net_websocket/BUILD.gn create mode 100755 network/netstack/net_websocket/libwebsocket.ndk.json create mode 100755 network/netstack/net_websocket/net_websocket.h create mode 100755 network/netstack/net_websocket/net_websocket_type.h diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn new file mode 100755 index 00000000000..ace428a5c41 --- /dev/null +++ b/network/netstack/net_websocket/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_ndk_library("libnet_websocket") { + output_name = "net_websocket" + output_extension = "so" + ndk_description_file = "./libwebsocket.ndk.json" + min_compact_version = "1" + system_capability = "SystemCapability.Communication.NetStack" + system_capability_headers = [ + "network/netstack/net_websocket/net_websocket.h", + "network/netstack/net_websocket/net_websocket_type.h", + ] +} + +ohos_ndk_headers("websocket_header") { + dest_dir = "$ndk_headers_out_dir/network/netstack/net_websocket" + sources = [ + "net_websocket.h", + "net_websocket_type.h", + ] +} diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json new file mode 100755 index 00000000000..9a17f527c83 --- /dev/null +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -0,0 +1,9 @@ +[ + {"name": "OH_NetStack_WebsocketClient_Construct"}, + {"name": "OH_NetStack_WebSocketClient_AddHeader"}, + {"name": "OH_NetStack_WebSocketClient_Connect"}, + {"name": "OH_NetStack_WebSocketClient_Send"}, + {"name": "OH_NetStack_WebSocketClient_Close"}, + {"name": "OH_NetStack_WebsocketClient_Destroy"}, + {"name": "OH_NetStack_WebSocketClient_FreeAll"} +] \ No newline at end of file diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h new file mode 100755 index 00000000000..9258fc7793a --- /dev/null +++ b/network/netstack/net_websocket/net_websocket.h @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_WEBSOCKET_H +#define NET_WEBSOCKET_H + +#include +#include +#include + +/** + * @addtogroup netstack + * @{ + * + * @brief Provides C APIs for the WebSocket client module. + + * @since 11 + * @version 1.0 + */ + +/** + * @file net_websocket.h + * + * @brief Defines the APIs for the WebSocket client module. + * + * @library libnet_websocket.so + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ + +#include "net_websocket_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Constructor of OH_NetStack_WebsocketClient. + * + * @param onMessage Callback function invoked when a message is received. + * @param onClose Callback function invoked when a connection closing message is closed. + * @param onError Callback function invoked when a connection error message is received. + * @param onOpen Callback function invoked when a connection setup message is received. + * @return Pointer to the WebSocket client if success; NULL otherwise. + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient *OH_NetStack_WebsocketClient_Construct( + OH_NetStack_WebsocketClient_OnOpenCallback onOpen, OH_NetStack_WebsocketClient_OnMessageCallback onMessage, + OH_NetStack_WebsocketClient_OnErrorCallback onError, OH_NetStack_WebsocketClient_OnCloseCallback onclose); + +/** + * @brief Adds the header information to the client request. + * + * @param client Pointer to the WebSocket client. + * @param header Header information + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *client, + struct OH_NetStack_WebsocketClient_Slist header); + +/** + * @brief Connects the client to the server. + * + * @param client Pointer to the WebSocket client. + * @param url URL for the client to connect to the server. + * @param options Optional parameters. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Connect(struct OH_NetStack_WebsocketClient *client, const char *url, + struct OH_NetStack_WebsocketClient_RequestOptions options); + +/** + * @brief Sends data from the client to the server. + * + * @param client Pointer to the WebSocket client. + * @param data Data sent by the client. + * @param length Length of the data sent by the client. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Send(struct OH_NetStack_WebsocketClient *client, char *data, size_t length); + +/** + * @brief Closes a WebSocket connection. + * + * @param client Pointer to the WebSocket client. + * @param url URL for the client to connect to the server. + * @param options Optional parameters. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebSocketClient_Close(struct OH_NetStack_WebsocketClient *client, + struct OH_NetStack_WebsocketClient_CloseOption options); + +/** + * @brief Releases the context and resources of the WebSocket connection. + * + * @param client Pointer to the WebSocket client. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ +int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *client); + +#ifdef __cplusplus +} +#endif + +#endif // NET_WEBSOCKET_H diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h new file mode 100755 index 00000000000..9cd8bf9c628 --- /dev/null +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_WEBSOCKET_TYPE_H +#define NET_WEBSOCKET_TYPE_H + +/** + * @addtogroup netstack + * @{ + * + * @brief Provides C APIs for the WebSocket client module. + * + * @since 11 + * @version 1.0 + */ + +/** + * @file net_websocket_type.h + * @brief Defines the data structure for the C APIs of the WebSocket client module. + * + * @library libnet_websocket.so + * @syscap SystemCapability.Communication.NetStack + * @since 11 + * @version 1.0 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the parameters for connection closing by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_CloseResult { + /** Error code */ + uint32_t code; + /** Error cause */ + const char *reason; +}; + +/** + * @brief Defines the parameters for proactive connection closing by the client. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_CloseOption { + /** Error code */ + uint32_t code; + /** Error cause */ + const char *reason; +}; + +/** + * @brief Defines the parameters for the connection error reported by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_ErrorResult { + /** Error code */ + uint32_t errorCode; + /** Error message */ + const char *errorMessage; +}; + +/** + * @brief Defines the parameters for the connection success reported by the server. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_OpenResult { + /** Connection success code */ + uint32_t code; + /** Connection success reason */ + const char *reason; +}; + +/** + * @brief Defines the callback function invoked when an open message is received. + * + * @param client WebSocket client. + * @param openResult Content of the open message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnOpenCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_OpenResult openResult); + +/** + * @brief Defines the callback function invoked when data is received. + * + * @param client WebSocket client. + * @param data Data received by the WebSocket client. + * @param length Length of the data received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnMessageCallback)(struct OH_NetStack_WebsocketClient *client, char *data, + uint32_t length); + +/** + * @brief Defines the callback function invoked when an error message is received. + * + * @param client WebSocket client. + * @param errorResult Content of the connection error message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnErrorCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_ErrorResult errorResult); + +/** + * @brief Defines the callback function invoked when a close message is received. + * + * @param client WebSocket client. + * @param closeResult Content of the close message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*OH_NetStack_WebsocketClient_OnCloseCallback)(struct OH_NetStack_WebsocketClient *client, + OH_NetStack_WebsocketClient_CloseResult closeResult); + +/** + * @brief Adds the header linked list to the WebSocket client. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_Slist { + /** Header field name */ + const char *fieldName; + /** Header field content */ + const char *fieldValue; + /** Next pointer of the header linked list */ + struct OH_NetStack_WebsocketClient_Slist *next; +}; + +/** + * @brief Defines the parameters for the connection between the WebSocket client and server. + * + * @param headers Header information. + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient_RequestOptions { + struct OH_NetStack_WebsocketClient_Slist *headers; +}; + +/** + * @brief Defines the WebSocket client structure. + * + * @since 11 + * @version 1.0 + */ +struct OH_NetStack_WebsocketClient { + /** Pointer to the callback invoked when a connection message is received */ + OH_NetStack_WebsocketClient_OnOpenCallback onOpen; + /** Pointer to the callback invoked when a message is received */ + OH_NetStack_WebsocketClient_OnMessageCallback onMessage; + /** Pointer to the callback invoked when an error message is received */ + OH_NetStack_WebsocketClient_OnErrorCallback onError; + /** Pointer to the callback invoked when a close message is received */ + OH_NetStack_WebsocketClient_OnCloseCallback onClose; + /** Content of the request for establishing a connection on the client */ + OH_NetStack_WebsocketClient_RequestOptions requestOptions; +}; + +typedef enum OH_Websocket_ErrCode { + /** + * Operation success. + */ + WEBSOCKET_OK = 0, + + /** + * @brief Error code base. + */ + E_BASE = 1000, + + /** + * @brief The WebSocket client is null. + */ + WEBSOCKET_CLIENT_IS_NULL = (E_BASE + 1), + + /** + * @brief A WebSocket client is not created. + */ + WEBSOCKET_CLIENT_IS_NOT_CREAT = (E_BASE + 2), + + /** + * @brief An error occurs while setting up a WebSocket connection. + */ + WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), + + /** + * @brief An error occurs while parsing WebSocket connection parameters. + */ + WEBSOCKET_CONNECTION_PARSEURL_ERROR = (E_BASE + 5), + + /** + * @brief The memory is insufficient for creating a context during WebSocket connection setup. + */ + WEBSOCKET_CONNECTION_NO_MEMOERY = (E_BASE + 6), + + /** + * @brief The WebSocket connection is closed by the peer. + */ + WEBSOCKET_PEER_INITIATED_CLOSE = (E_BASE + 7), + + /** + * @brief The WebSocket connection is destroyed. + */ + WEBSOCKET_DESTROY = (E_BASE + 8), + + /** + * @brief An incorrect protocol is used for WebSocket connection. + */ + WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), + + /** + * @brief The memory for the WebSocket client to send data is insufficient. + */ + WEBSOCKET_SEND_NO_MEMOERY_ERROR = (E_BASE + 10), + + /** + * @brief The data sent by the WebSocket client is null. + */ + WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), + + /** + * @brief The length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_DATA_LENGTH_EXCEEDS = (E_BASE + 12), + + /** + * @brief The queue length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_QUEUE_LENGTH_EXCEEDS = (E_BASE + 13), + + /** + * @brief The context of the WebSocket client is null. + */ + WEBSOCKET_ERROR_NO_CLIENTCONTEX = (E_BASE + 14), + + /** + * @brief The header of the WebSocket client is null. + */ + WEBSOCKET_ERROR_NO_HEADR_CONTEXT = (E_BASE + 15), + + /** + * @brief The header of the WebSocket client exceeds the limit. + */ + WEBSOCKET_ERROR_NO_HEADR_EXCEEDS = (E_BASE + 16), + + /** + * @brief The WebSocket client is not connected. + */ + WEBSOCKET_ERROR_HAVE_NO_CONNECT = (E_BASE + 17), + + /** + * @brief The WebSocket client does not have the connection context. + */ + WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), +} OH_Websocket_ErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // NET_WEBSOCKET_TYPE_H \ No newline at end of file -- Gitee From f40f74dfa6e524ab34f6e6065eaa7a49f7414590 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Sat, 25 Nov 2023 20:43:17 +0800 Subject: [PATCH 08/36] add websocket code Signed-off-by: liuxiyao223 --- nestack/net_websocket/BUILD.gn | 34 --- nestack/net_websocket/include/net_websocket.h | 139 --------- .../include/net_websocket_type.h | 286 ------------------ nestack/net_websocket/libwebsocket.ndk.json | 9 - network/netstack/net_websocket/BUILD.gn | 4 +- 5 files changed, 2 insertions(+), 470 deletions(-) delete mode 100755 nestack/net_websocket/BUILD.gn delete mode 100755 nestack/net_websocket/include/net_websocket.h delete mode 100755 nestack/net_websocket/include/net_websocket_type.h delete mode 100755 nestack/net_websocket/libwebsocket.ndk.json diff --git a/nestack/net_websocket/BUILD.gn b/nestack/net_websocket/BUILD.gn deleted file mode 100755 index c8828d77cf0..00000000000 --- a/nestack/net_websocket/BUILD.gn +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -ohos_ndk_library("libnet_websocket") { - output_name = "net_websocket" - output_extension = "so" - ndk_description_file = "./libwebsocket.ndk.json" - min_compact_version = "1" - system_capability = "SystemCapability.Communication.NetStack" - system_capability_headers = [ - "./include/net_websocket.h", - "./include/net_websocket_type.h", - ] -} - -ohos_ndk_headers("websocket_header") { - dest_dir = "$ndk_headers_out_dir/net_websocket" - sources = [ - "./include/net_websocket.h", - "./include/net_websocket_type.h", - ] -} diff --git a/nestack/net_websocket/include/net_websocket.h b/nestack/net_websocket/include/net_websocket.h deleted file mode 100755 index 9258fc7793a..00000000000 --- a/nestack/net_websocket/include/net_websocket.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NET_WEBSOCKET_H -#define NET_WEBSOCKET_H - -#include -#include -#include - -/** - * @addtogroup netstack - * @{ - * - * @brief Provides C APIs for the WebSocket client module. - - * @since 11 - * @version 1.0 - */ - -/** - * @file net_websocket.h - * - * @brief Defines the APIs for the WebSocket client module. - * - * @library libnet_websocket.so - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ - -#include "net_websocket_type.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Constructor of OH_NetStack_WebsocketClient. - * - * @param onMessage Callback function invoked when a message is received. - * @param onClose Callback function invoked when a connection closing message is closed. - * @param onError Callback function invoked when a connection error message is received. - * @param onOpen Callback function invoked when a connection setup message is received. - * @return Pointer to the WebSocket client if success; NULL otherwise. - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient *OH_NetStack_WebsocketClient_Construct( - OH_NetStack_WebsocketClient_OnOpenCallback onOpen, OH_NetStack_WebsocketClient_OnMessageCallback onMessage, - OH_NetStack_WebsocketClient_OnErrorCallback onError, OH_NetStack_WebsocketClient_OnCloseCallback onclose); - -/** - * @brief Adds the header information to the client request. - * - * @param client Pointer to the WebSocket client. - * @param header Header information - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *client, - struct OH_NetStack_WebsocketClient_Slist header); - -/** - * @brief Connects the client to the server. - * - * @param client Pointer to the WebSocket client. - * @param url URL for the client to connect to the server. - * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -int OH_NetStack_WebSocketClient_Connect(struct OH_NetStack_WebsocketClient *client, const char *url, - struct OH_NetStack_WebsocketClient_RequestOptions options); - -/** - * @brief Sends data from the client to the server. - * - * @param client Pointer to the WebSocket client. - * @param data Data sent by the client. - * @param length Length of the data sent by the client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -int OH_NetStack_WebSocketClient_Send(struct OH_NetStack_WebsocketClient *client, char *data, size_t length); - -/** - * @brief Closes a WebSocket connection. - * - * @param client Pointer to the WebSocket client. - * @param url URL for the client to connect to the server. - * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -int OH_NetStack_WebSocketClient_Close(struct OH_NetStack_WebsocketClient *client, - struct OH_NetStack_WebsocketClient_CloseOption options); - -/** - * @brief Releases the context and resources of the WebSocket connection. - * - * @param client Pointer to the WebSocket client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. - * @permission ohos.permission.INTERNET - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ -int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *client); - -#ifdef __cplusplus -} -#endif - -#endif // NET_WEBSOCKET_H diff --git a/nestack/net_websocket/include/net_websocket_type.h b/nestack/net_websocket/include/net_websocket_type.h deleted file mode 100755 index 9cd8bf9c628..00000000000 --- a/nestack/net_websocket/include/net_websocket_type.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (C) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NET_WEBSOCKET_TYPE_H -#define NET_WEBSOCKET_TYPE_H - -/** - * @addtogroup netstack - * @{ - * - * @brief Provides C APIs for the WebSocket client module. - * - * @since 11 - * @version 1.0 - */ - -/** - * @file net_websocket_type.h - * @brief Defines the data structure for the C APIs of the WebSocket client module. - * - * @library libnet_websocket.so - * @syscap SystemCapability.Communication.NetStack - * @since 11 - * @version 1.0 - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Defines the parameters for connection closing by the server. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_CloseResult { - /** Error code */ - uint32_t code; - /** Error cause */ - const char *reason; -}; - -/** - * @brief Defines the parameters for proactive connection closing by the client. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_CloseOption { - /** Error code */ - uint32_t code; - /** Error cause */ - const char *reason; -}; - -/** - * @brief Defines the parameters for the connection error reported by the server. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_ErrorResult { - /** Error code */ - uint32_t errorCode; - /** Error message */ - const char *errorMessage; -}; - -/** - * @brief Defines the parameters for the connection success reported by the server. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_OpenResult { - /** Connection success code */ - uint32_t code; - /** Connection success reason */ - const char *reason; -}; - -/** - * @brief Defines the callback function invoked when an open message is received. - * - * @param client WebSocket client. - * @param openResult Content of the open message received by the WebSocket client. - * @since 11 - * @version 1.0 - */ -typedef void (*OH_NetStack_WebsocketClient_OnOpenCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_OpenResult openResult); - -/** - * @brief Defines the callback function invoked when data is received. - * - * @param client WebSocket client. - * @param data Data received by the WebSocket client. - * @param length Length of the data received by the WebSocket client. - * @since 11 - * @version 1.0 - */ -typedef void (*OH_NetStack_WebsocketClient_OnMessageCallback)(struct OH_NetStack_WebsocketClient *client, char *data, - uint32_t length); - -/** - * @brief Defines the callback function invoked when an error message is received. - * - * @param client WebSocket client. - * @param errorResult Content of the connection error message received by the WebSocket client. - * @since 11 - * @version 1.0 - */ -typedef void (*OH_NetStack_WebsocketClient_OnErrorCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_ErrorResult errorResult); - -/** - * @brief Defines the callback function invoked when a close message is received. - * - * @param client WebSocket client. - * @param closeResult Content of the close message received by the WebSocket client. - * @since 11 - * @version 1.0 - */ -typedef void (*OH_NetStack_WebsocketClient_OnCloseCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_CloseResult closeResult); - -/** - * @brief Adds the header linked list to the WebSocket client. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_Slist { - /** Header field name */ - const char *fieldName; - /** Header field content */ - const char *fieldValue; - /** Next pointer of the header linked list */ - struct OH_NetStack_WebsocketClient_Slist *next; -}; - -/** - * @brief Defines the parameters for the connection between the WebSocket client and server. - * - * @param headers Header information. - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient_RequestOptions { - struct OH_NetStack_WebsocketClient_Slist *headers; -}; - -/** - * @brief Defines the WebSocket client structure. - * - * @since 11 - * @version 1.0 - */ -struct OH_NetStack_WebsocketClient { - /** Pointer to the callback invoked when a connection message is received */ - OH_NetStack_WebsocketClient_OnOpenCallback onOpen; - /** Pointer to the callback invoked when a message is received */ - OH_NetStack_WebsocketClient_OnMessageCallback onMessage; - /** Pointer to the callback invoked when an error message is received */ - OH_NetStack_WebsocketClient_OnErrorCallback onError; - /** Pointer to the callback invoked when a close message is received */ - OH_NetStack_WebsocketClient_OnCloseCallback onClose; - /** Content of the request for establishing a connection on the client */ - OH_NetStack_WebsocketClient_RequestOptions requestOptions; -}; - -typedef enum OH_Websocket_ErrCode { - /** - * Operation success. - */ - WEBSOCKET_OK = 0, - - /** - * @brief Error code base. - */ - E_BASE = 1000, - - /** - * @brief The WebSocket client is null. - */ - WEBSOCKET_CLIENT_IS_NULL = (E_BASE + 1), - - /** - * @brief A WebSocket client is not created. - */ - WEBSOCKET_CLIENT_IS_NOT_CREAT = (E_BASE + 2), - - /** - * @brief An error occurs while setting up a WebSocket connection. - */ - WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), - - /** - * @brief An error occurs while parsing WebSocket connection parameters. - */ - WEBSOCKET_CONNECTION_PARSEURL_ERROR = (E_BASE + 5), - - /** - * @brief The memory is insufficient for creating a context during WebSocket connection setup. - */ - WEBSOCKET_CONNECTION_NO_MEMOERY = (E_BASE + 6), - - /** - * @brief The WebSocket connection is closed by the peer. - */ - WEBSOCKET_PEER_INITIATED_CLOSE = (E_BASE + 7), - - /** - * @brief The WebSocket connection is destroyed. - */ - WEBSOCKET_DESTROY = (E_BASE + 8), - - /** - * @brief An incorrect protocol is used for WebSocket connection. - */ - WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), - - /** - * @brief The memory for the WebSocket client to send data is insufficient. - */ - WEBSOCKET_SEND_NO_MEMOERY_ERROR = (E_BASE + 10), - - /** - * @brief The data sent by the WebSocket client is null. - */ - WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), - - /** - * @brief The length of the data sent by the WebSocket client exceeds the limit. - */ - WEBSOCKET_DATA_LENGTH_EXCEEDS = (E_BASE + 12), - - /** - * @brief The queue length of the data sent by the WebSocket client exceeds the limit. - */ - WEBSOCKET_QUEUE_LENGTH_EXCEEDS = (E_BASE + 13), - - /** - * @brief The context of the WebSocket client is null. - */ - WEBSOCKET_ERROR_NO_CLIENTCONTEX = (E_BASE + 14), - - /** - * @brief The header of the WebSocket client is null. - */ - WEBSOCKET_ERROR_NO_HEADR_CONTEXT = (E_BASE + 15), - - /** - * @brief The header of the WebSocket client exceeds the limit. - */ - WEBSOCKET_ERROR_NO_HEADR_EXCEEDS = (E_BASE + 16), - - /** - * @brief The WebSocket client is not connected. - */ - WEBSOCKET_ERROR_HAVE_NO_CONNECT = (E_BASE + 17), - - /** - * @brief The WebSocket client does not have the connection context. - */ - WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), -} OH_Websocket_ErrCode; - -#ifdef __cplusplus -} -#endif - -#endif // NET_WEBSOCKET_TYPE_H \ No newline at end of file diff --git a/nestack/net_websocket/libwebsocket.ndk.json b/nestack/net_websocket/libwebsocket.ndk.json deleted file mode 100755 index 9a17f527c83..00000000000 --- a/nestack/net_websocket/libwebsocket.ndk.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - {"name": "OH_NetStack_WebsocketClient_Construct"}, - {"name": "OH_NetStack_WebSocketClient_AddHeader"}, - {"name": "OH_NetStack_WebSocketClient_Connect"}, - {"name": "OH_NetStack_WebSocketClient_Send"}, - {"name": "OH_NetStack_WebSocketClient_Close"}, - {"name": "OH_NetStack_WebsocketClient_Destroy"}, - {"name": "OH_NetStack_WebSocketClient_FreeAll"} -] \ No newline at end of file diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn index ace428a5c41..8ec894bd9de 100755 --- a/network/netstack/net_websocket/BUILD.gn +++ b/network/netstack/net_websocket/BUILD.gn @@ -19,9 +19,9 @@ ohos_ndk_library("libnet_websocket") { ndk_description_file = "./libwebsocket.ndk.json" min_compact_version = "1" system_capability = "SystemCapability.Communication.NetStack" - system_capability_headers = [ + system_capability_headers = [ "network/netstack/net_websocket/net_websocket.h", - "network/netstack/net_websocket/net_websocket_type.h", + "network/netstack/net_websocket/net_websocket_type.h", ] } -- Gitee From 96c3ff38fc74f633aa3b54d0e47a23a26096c2e5 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 13 Dec 2023 09:49:37 +0800 Subject: [PATCH 09/36] add websocket code Signed-off-by: liuxiyao223 --- .../net_websocket/libwebsocket.ndk.json | 10 +- .../netstack/net_websocket/net_websocket.h | 43 ++++---- .../net_websocket/net_websocket_type.h | 102 +++++++++--------- 3 files changed, 75 insertions(+), 80 deletions(-) diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json index 9a17f527c83..3745a333ebe 100755 --- a/network/netstack/net_websocket/libwebsocket.ndk.json +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -1,9 +1,9 @@ [ {"name": "OH_NetStack_WebsocketClient_Construct"}, - {"name": "OH_NetStack_WebSocketClient_AddHeader"}, - {"name": "OH_NetStack_WebSocketClient_Connect"}, - {"name": "OH_NetStack_WebSocketClient_Send"}, - {"name": "OH_NetStack_WebSocketClient_Close"}, + {"name": "OH_NetStack_WebsocketClient_AddHeader"}, + {"name": "OH_NetStack_WebsocketClient_Connect"}, + {"name": "OH_NetStack_WebsocketClient_Send"}, + {"name": "OH_NetStack_WebsocketClient_Close"}, {"name": "OH_NetStack_WebsocketClient_Destroy"}, - {"name": "OH_NetStack_WebSocketClient_FreeAll"} + {"name": "OH_NetStack_WebsocketClient_FreeAll"} ] \ No newline at end of file diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 9258fc7793a..ac4af24e174 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -24,7 +24,7 @@ * @addtogroup netstack * @{ * - * @brief Provides C APIs for the WebSocket client module. + * @brief Provides C APIs for the websocket client module. * @since 11 * @version 1.0 @@ -33,7 +33,7 @@ /** * @file net_websocket.h * - * @brief Defines the APIs for the WebSocket client module. + * @brief Defines the APIs for the websocket client module. * * @library libnet_websocket.so * @syscap SystemCapability.Communication.NetStack @@ -48,38 +48,38 @@ extern "C" { #endif /** - * @brief Constructor of OH_NetStack_WebsocketClient. + * @brief Constructor of websocket. * * @param onMessage Callback function invoked when a message is received. * @param onClose Callback function invoked when a connection closing message is closed. * @param onError Callback function invoked when a connection error message is received. * @param onOpen Callback function invoked when a connection setup message is received. - * @return Pointer to the WebSocket client if success; NULL otherwise. + * @return Pointer to the websocket client if success; NULL otherwise. * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient *OH_NetStack_WebsocketClient_Construct( - OH_NetStack_WebsocketClient_OnOpenCallback onOpen, OH_NetStack_WebsocketClient_OnMessageCallback onMessage, - OH_NetStack_WebsocketClient_OnErrorCallback onError, OH_NetStack_WebsocketClient_OnCloseCallback onclose); +struct Websocket *OH_NetStack_WebsocketClient_Construct(Websocket_OnOpenCallback onOpen, + Websocket_OnMessageCallback onMessage, + Websocket_OnErrorCallback onError, + Websocket_OnCloseCallback onclose); /** * @brief Adds the header information to the client request. * - * @param client Pointer to the WebSocket client. + * @param client Pointer to the websocket client. * @param header Header information * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *client, - struct OH_NetStack_WebsocketClient_Slist header); +int OH_NetStack_WebsocketClient_AddHeader(struct Websocket *client, struct Websocket_HeaderNode header); /** * @brief Connects the client to the server. * - * @param client Pointer to the WebSocket client. + * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. @@ -88,13 +88,13 @@ int OH_NetStack_WebSocketClient_AddHeader(struct OH_NetStack_WebsocketClient *cl * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Connect(struct OH_NetStack_WebsocketClient *client, const char *url, - struct OH_NetStack_WebsocketClient_RequestOptions options); +int OH_NetStack_WebsocketClient_Connect(struct Websocket *client, const char *url, + struct Websocket_RequestOptions options); /** * @brief Sends data from the client to the server. * - * @param client Pointer to the WebSocket client. + * @param client Pointer to the websocket client. * @param data Data sent by the client. * @param length Length of the data sent by the client. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. @@ -103,12 +103,12 @@ int OH_NetStack_WebSocketClient_Connect(struct OH_NetStack_WebsocketClient *clie * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Send(struct OH_NetStack_WebsocketClient *client, char *data, size_t length); +int OH_NetStack_WebsocketClient_Send(struct Websocket *client, char *data, size_t length); /** - * @brief Closes a WebSocket connection. + * @brief Closes a webSocket connection. * - * @param client Pointer to the WebSocket client. + * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. @@ -117,20 +117,19 @@ int OH_NetStack_WebSocketClient_Send(struct OH_NetStack_WebsocketClient *client, * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Close(struct OH_NetStack_WebsocketClient *client, - struct OH_NetStack_WebsocketClient_CloseOption options); +int OH_NetStack_WebsocketClient_Close(struct Websocket *client, struct Websocket_CloseOption options); /** - * @brief Releases the context and resources of the WebSocket connection. + * @brief Releases the context and resources of the websocket connection. * - * @param client Pointer to the WebSocket client. + * @param client Pointer to the websocket client. * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_Destroy(struct OH_NetStack_WebsocketClient *client); +int OH_NetStack_WebsocketClient_Destroy(struct Websocket *client); #ifdef __cplusplus } diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 9cd8bf9c628..ee3251b3721 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -20,7 +20,7 @@ * @addtogroup netstack * @{ * - * @brief Provides C APIs for the WebSocket client module. + * @brief Provides C APIs for the websocket client module. * * @since 11 * @version 1.0 @@ -28,7 +28,7 @@ /** * @file net_websocket_type.h - * @brief Defines the data structure for the C APIs of the WebSocket client module. + * @brief Defines the data structure for the C APIs of the websocket client module. * * @library libnet_websocket.so * @syscap SystemCapability.Communication.NetStack @@ -46,7 +46,7 @@ extern "C" { * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_CloseResult { +struct Websocket_CloseResult { /** Error code */ uint32_t code; /** Error cause */ @@ -59,7 +59,7 @@ struct OH_NetStack_WebsocketClient_CloseResult { * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_CloseOption { +struct Websocket_CloseOption { /** Error code */ uint32_t code; /** Error cause */ @@ -72,7 +72,7 @@ struct OH_NetStack_WebsocketClient_CloseOption { * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_ErrorResult { +struct Websocket_ErrorResult { /** Error code */ uint32_t errorCode; /** Error message */ @@ -85,7 +85,7 @@ struct OH_NetStack_WebsocketClient_ErrorResult { * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_OpenResult { +struct Websocket_OpenResult { /** Connection success code */ uint32_t code; /** Connection success reason */ @@ -95,91 +95,87 @@ struct OH_NetStack_WebsocketClient_OpenResult { /** * @brief Defines the callback function invoked when an open message is received. * - * @param client WebSocket client. - * @param openResult Content of the open message received by the WebSocket client. + * @param client websocket client. + * @param openResult Content of the open message received by the websocket client. * @since 11 * @version 1.0 */ -typedef void (*OH_NetStack_WebsocketClient_OnOpenCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_OpenResult openResult); +typedef void (*Websocket_OnOpenCallback)(struct Websocket *client, Websocket_OpenResult openResult); /** * @brief Defines the callback function invoked when data is received. * - * @param client WebSocket client. - * @param data Data received by the WebSocket client. - * @param length Length of the data received by the WebSocket client. + * @param client websocket client. + * @param data Data received by the websocket client. + * @param length Length of the data received by the websocket client. * @since 11 * @version 1.0 */ -typedef void (*OH_NetStack_WebsocketClient_OnMessageCallback)(struct OH_NetStack_WebsocketClient *client, char *data, - uint32_t length); +typedef void (*Websocket_OnMessageCallback)(struct Websocket *client, char *data, uint32_t length); /** * @brief Defines the callback function invoked when an error message is received. * - * @param client WebSocket client. - * @param errorResult Content of the connection error message received by the WebSocket client. + * @param client websocket client. + * @param errorResult Content of the connection error message received by the websocket client. * @since 11 * @version 1.0 */ -typedef void (*OH_NetStack_WebsocketClient_OnErrorCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_ErrorResult errorResult); +typedef void (*Websocket_OnErrorCallback)(struct Websocket *client, Websocket_ErrorResult errorResult); /** * @brief Defines the callback function invoked when a close message is received. * - * @param client WebSocket client. - * @param closeResult Content of the close message received by the WebSocket client. + * @param client webSocket client. + * @param closeResult Content of the close message received by the webSocket client. * @since 11 * @version 1.0 */ -typedef void (*OH_NetStack_WebsocketClient_OnCloseCallback)(struct OH_NetStack_WebsocketClient *client, - OH_NetStack_WebsocketClient_CloseResult closeResult); +typedef void (*Websocket_OnCloseCallback)(struct Websocket *client, Websocket_CloseResult closeResult); /** - * @brief Adds the header linked list to the WebSocket client. + * @brief Adds the header linked list to the websocket client. * * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_Slist { +struct Websocket_HeaderNode { /** Header field name */ const char *fieldName; /** Header field content */ const char *fieldValue; /** Next pointer of the header linked list */ - struct OH_NetStack_WebsocketClient_Slist *next; + struct Websocket_HeaderNode *next; }; /** - * @brief Defines the parameters for the connection between the WebSocket client and server. + * @brief Defines the parameters for the connection between the websocket client and server. * * @param headers Header information. * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient_RequestOptions { - struct OH_NetStack_WebsocketClient_Slist *headers; +struct Websocket_RequestOptions { + struct Websocket_HeaderNode *headers; }; /** - * @brief Defines the WebSocket client structure. + * @brief Defines the websocket client structu re. * * @since 11 * @version 1.0 */ -struct OH_NetStack_WebsocketClient { +struct Websocket { /** Pointer to the callback invoked when a connection message is received */ - OH_NetStack_WebsocketClient_OnOpenCallback onOpen; + Websocket_OnOpenCallback onOpen; /** Pointer to the callback invoked when a message is received */ - OH_NetStack_WebsocketClient_OnMessageCallback onMessage; + Websocket_OnMessageCallback onMessage; /** Pointer to the callback invoked when an error message is received */ - OH_NetStack_WebsocketClient_OnErrorCallback onError; + Websocket_OnErrorCallback onError; /** Pointer to the callback invoked when a close message is received */ - OH_NetStack_WebsocketClient_OnCloseCallback onClose; + Websocket_OnCloseCallback onClose; /** Content of the request for establishing a connection on the client */ - OH_NetStack_WebsocketClient_RequestOptions requestOptions; + Websocket_RequestOptions requestOptions; }; typedef enum OH_Websocket_ErrCode { @@ -194,87 +190,87 @@ typedef enum OH_Websocket_ErrCode { E_BASE = 1000, /** - * @brief The WebSocket client is null. + * @brief The websocket client is null. */ WEBSOCKET_CLIENT_IS_NULL = (E_BASE + 1), /** - * @brief A WebSocket client is not created. + * @brief A webSocket client is not created. */ WEBSOCKET_CLIENT_IS_NOT_CREAT = (E_BASE + 2), /** - * @brief An error occurs while setting up a WebSocket connection. + * @brief An error occurs while setting up a websocket connection. */ WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), /** - * @brief An error occurs while parsing WebSocket connection parameters. + * @brief An error occurs while parsing websocket connection parameters. */ WEBSOCKET_CONNECTION_PARSEURL_ERROR = (E_BASE + 5), /** - * @brief The memory is insufficient for creating a context during WebSocket connection setup. + * @brief The memory is insufficient for creating a context during websocket connection setup. */ WEBSOCKET_CONNECTION_NO_MEMOERY = (E_BASE + 6), /** - * @brief The WebSocket connection is closed by the peer. + * @brief The websocket connection is closed by the peer. */ WEBSOCKET_PEER_INITIATED_CLOSE = (E_BASE + 7), /** - * @brief The WebSocket connection is destroyed. + * @brief The websocket connection is destroyed. */ WEBSOCKET_DESTROY = (E_BASE + 8), /** - * @brief An incorrect protocol is used for WebSocket connection. + * @brief An incorrect protocol is used for websocket connection. */ WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), /** - * @brief The memory for the WebSocket client to send data is insufficient. + * @brief The memory for the websocket client to send data is insufficient. */ WEBSOCKET_SEND_NO_MEMOERY_ERROR = (E_BASE + 10), /** - * @brief The data sent by the WebSocket client is null. + * @brief The data sent by the websocket client is null. */ WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), /** - * @brief The length of the data sent by the WebSocket client exceeds the limit. + * @brief The length of the data sent by the websocket client exceeds the limit. */ WEBSOCKET_DATA_LENGTH_EXCEEDS = (E_BASE + 12), /** - * @brief The queue length of the data sent by the WebSocket client exceeds the limit. + * @brief The queue length of the data sent by the websocket client exceeds the limit. */ WEBSOCKET_QUEUE_LENGTH_EXCEEDS = (E_BASE + 13), /** - * @brief The context of the WebSocket client is null. + * @brief The context of the websocket client is null. */ WEBSOCKET_ERROR_NO_CLIENTCONTEX = (E_BASE + 14), /** - * @brief The header of the WebSocket client is null. + * @brief The header of the webSocket client is null. */ WEBSOCKET_ERROR_NO_HEADR_CONTEXT = (E_BASE + 15), /** - * @brief The header of the WebSocket client exceeds the limit. + * @brief The header of the websocket client exceeds the limit. */ WEBSOCKET_ERROR_NO_HEADR_EXCEEDS = (E_BASE + 16), /** - * @brief The WebSocket client is not connected. + * @brief The websocket client is not connected. */ WEBSOCKET_ERROR_HAVE_NO_CONNECT = (E_BASE + 17), /** - * @brief The WebSocket client does not have the connection context. + * @brief The websocket client does not have the connection context. */ WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), } OH_Websocket_ErrCode; -- Gitee From ed54037e45d39884ddee7d295a5e2ce8fca83a4d Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 13 Dec 2023 15:31:42 +0800 Subject: [PATCH 10/36] add websocket code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket_type.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index ee3251b3721..aa73dff1f73 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -178,7 +178,7 @@ struct Websocket { Websocket_RequestOptions requestOptions; }; -typedef enum OH_Websocket_ErrCode { +typedef enum Websocket_ErrCode { /** * Operation success. */ @@ -273,7 +273,7 @@ typedef enum OH_Websocket_ErrCode { * @brief The websocket client does not have the connection context. */ WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), -} OH_Websocket_ErrCode; +} Websocket_ErrCode; #ifdef __cplusplus } -- Gitee From 9fe26e07e6947d21f495c254c51b5bc2c6bc1179 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 13 Dec 2023 20:15:22 +0800 Subject: [PATCH 11/36] add websocket code Signed-off-by: liuxiyao223 --- .../net_websocket/libwebsocket.ndk.json | 14 +- .../netstack/net_websocket/net_websocket.h | 30 ++--- .../net_websocket/net_websocket_type.h | 122 +++++++++--------- 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json index 3745a333ebe..eef7fb3b1ff 100755 --- a/network/netstack/net_websocket/libwebsocket.ndk.json +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -1,9 +1,9 @@ [ - {"name": "OH_NetStack_WebsocketClient_Construct"}, - {"name": "OH_NetStack_WebsocketClient_AddHeader"}, - {"name": "OH_NetStack_WebsocketClient_Connect"}, - {"name": "OH_NetStack_WebsocketClient_Send"}, - {"name": "OH_NetStack_WebsocketClient_Close"}, - {"name": "OH_NetStack_WebsocketClient_Destroy"}, - {"name": "OH_NetStack_WebsocketClient_FreeAll"} + {"name": "OH_NetStack_WebSocketClient_Constructor"}, + {"name": "OH_NetStack_WebSocketClient_AddHeader"}, + {"name": "OH_NetStack_WebSocketClient_Connect"}, + {"name": "OH_NetStack_WebSocketClient_Send"}, + {"name": "OH_NetStack_WebSocketClient_Close"}, + {"name": "OH_NetStack_WebSocketClient_Destroy"}, + {"name": "OH_NetStack_WebSocketClient_FreeAll"} ] \ No newline at end of file diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index ac4af24e174..8538a6f61df 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,22 +59,22 @@ extern "C" { * @since 11 * @version 1.0 */ -struct Websocket *OH_NetStack_WebsocketClient_Construct(Websocket_OnOpenCallback onOpen, - Websocket_OnMessageCallback onMessage, - Websocket_OnErrorCallback onError, - Websocket_OnCloseCallback onclose); +struct WebSocket *OH_NetStack_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, + WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, + WebSocket_OnCloseCallback onclose); /** * @brief Adds the header information to the client request. * * @param client Pointer to the websocket client. * @param header Header information - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_AddHeader(struct Websocket *client, struct Websocket_HeaderNode header); +int OH_NetStack_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_HeaderNode header); /** * @brief Connects the client to the server. @@ -82,14 +82,14 @@ int OH_NetStack_WebsocketClient_AddHeader(struct Websocket *client, struct Webso * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_Connect(struct Websocket *client, const char *url, - struct Websocket_RequestOptions options); +int OH_NetStack_WebSocketClient_Connect(struct WebSocket *client, const char *url, + struct WebSocket_RequestOptions options); /** * @brief Sends data from the client to the server. @@ -97,13 +97,13 @@ int OH_NetStack_WebsocketClient_Connect(struct Websocket *client, const char *ur * @param client Pointer to the websocket client. * @param data Data sent by the client. * @param length Length of the data sent by the client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_Send(struct Websocket *client, char *data, size_t length); +int OH_NetStack_WebSocketClient_Send(struct WebSocket *client, char *data, size_t length); /** * @brief Closes a webSocket connection. @@ -111,25 +111,25 @@ int OH_NetStack_WebsocketClient_Send(struct Websocket *client, char *data, size_ * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_Close(struct Websocket *client, struct Websocket_CloseOption options); +int OH_NetStack_WebSocketClient_Close(struct WebSocket *client, struct WebSocket_CloseOption options); /** * @brief Releases the context and resources of the websocket connection. * * @param client Pointer to the websocket client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 */ -int OH_NetStack_WebsocketClient_Destroy(struct Websocket *client); +int OH_NetStack_WebSocketClient_Destroy(struct WebSocket *client); #ifdef __cplusplus } diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index aa73dff1f73..bf9b1d130d1 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -20,7 +20,7 @@ * @addtogroup netstack * @{ * - * @brief Provides C APIs for the websocket client module. + * @brief Provides C APIs for the WebSocket client module. * * @since 11 * @version 1.0 @@ -28,7 +28,7 @@ /** * @file net_websocket_type.h - * @brief Defines the data structure for the C APIs of the websocket client module. + * @brief Defines the data structure for the C APIs of the WebSocket client module. * * @library libnet_websocket.so * @syscap SystemCapability.Communication.NetStack @@ -46,7 +46,7 @@ extern "C" { * @since 11 * @version 1.0 */ -struct Websocket_CloseResult { +struct WebSocket_CloseResult { /** Error code */ uint32_t code; /** Error cause */ @@ -59,7 +59,7 @@ struct Websocket_CloseResult { * @since 11 * @version 1.0 */ -struct Websocket_CloseOption { +struct WebSocket_CloseOption { /** Error code */ uint32_t code; /** Error cause */ @@ -72,7 +72,7 @@ struct Websocket_CloseOption { * @since 11 * @version 1.0 */ -struct Websocket_ErrorResult { +struct WebSocket_ErrorResult { /** Error code */ uint32_t errorCode; /** Error message */ @@ -85,7 +85,7 @@ struct Websocket_ErrorResult { * @since 11 * @version 1.0 */ -struct Websocket_OpenResult { +struct WebSocket_OpenResult { /** Connection success code */ uint32_t code; /** Connection success reason */ @@ -95,33 +95,33 @@ struct Websocket_OpenResult { /** * @brief Defines the callback function invoked when an open message is received. * - * @param client websocket client. - * @param openResult Content of the open message received by the websocket client. + * @param client WebSocket client. + * @param openResult Content of the open message received by the WebSocket client. * @since 11 * @version 1.0 */ -typedef void (*Websocket_OnOpenCallback)(struct Websocket *client, Websocket_OpenResult openResult); +typedef void (*WebSocket_OnOpenCallback)(struct WebSocket *client, WebSocket_OpenResult openResult); /** * @brief Defines the callback function invoked when data is received. * - * @param client websocket client. - * @param data Data received by the websocket client. - * @param length Length of the data received by the websocket client. + * @param client WebSocket client. + * @param data Data received by the WebSocket client. + * @param length Length of the data received by the WebSocket client. * @since 11 * @version 1.0 */ -typedef void (*Websocket_OnMessageCallback)(struct Websocket *client, char *data, uint32_t length); +typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data, uint32_t length); /** * @brief Defines the callback function invoked when an error message is received. * - * @param client websocket client. - * @param errorResult Content of the connection error message received by the websocket client. + * @param client WebSocket client. + * @param errorResult Content of the connection error message received by the WebSocket client. * @since 11 * @version 1.0 */ -typedef void (*Websocket_OnErrorCallback)(struct Websocket *client, Websocket_ErrorResult errorResult); +typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_ErrorResult errorResult); /** * @brief Defines the callback function invoked when a close message is received. @@ -131,54 +131,54 @@ typedef void (*Websocket_OnErrorCallback)(struct Websocket *client, Websocket_Er * @since 11 * @version 1.0 */ -typedef void (*Websocket_OnCloseCallback)(struct Websocket *client, Websocket_CloseResult closeResult); +typedef void (*WebSocket_OnCloseCallback)(struct WebSocket *client, WebSocket_CloseResult closeResult); /** - * @brief Adds the header linked list to the websocket client. + * @brief Adds the header linked list to the WebSocket client. * * @since 11 * @version 1.0 */ -struct Websocket_HeaderNode { +struct WebSocket_HeaderNode { /** Header field name */ const char *fieldName; /** Header field content */ const char *fieldValue; /** Next pointer of the header linked list */ - struct Websocket_HeaderNode *next; + struct WebSocket_HeaderNode *next; }; /** - * @brief Defines the parameters for the connection between the websocket client and server. + * @brief Defines the parameters for the connection between the WebSocket client and server. * * @param headers Header information. * @since 11 * @version 1.0 */ -struct Websocket_RequestOptions { - struct Websocket_HeaderNode *headers; +struct WebSocket_RequestOptions { + struct WebSocket_HeaderNode *headers; }; /** - * @brief Defines the websocket client structu re. + * @brief Defines the WebSocket client structure. * * @since 11 * @version 1.0 */ -struct Websocket { +struct WebSocket { /** Pointer to the callback invoked when a connection message is received */ - Websocket_OnOpenCallback onOpen; + WebSocket_OnOpenCallback onOpen; /** Pointer to the callback invoked when a message is received */ - Websocket_OnMessageCallback onMessage; + WebSocket_OnMessageCallback onMessage; /** Pointer to the callback invoked when an error message is received */ - Websocket_OnErrorCallback onError; + WebSocket_OnErrorCallback onError; /** Pointer to the callback invoked when a close message is received */ - Websocket_OnCloseCallback onClose; + WebSocket_OnCloseCallback onClose; /** Content of the request for establishing a connection on the client */ - Websocket_RequestOptions requestOptions; + WebSocket_RequestOptions requestOptions; }; -typedef enum Websocket_ErrCode { +typedef enum WebSocket_ErrCode { /** * Operation success. */ @@ -190,90 +190,90 @@ typedef enum Websocket_ErrCode { E_BASE = 1000, /** - * @brief The websocket client is null. + * @brief The WebSocket client is null. */ - WEBSOCKET_CLIENT_IS_NULL = (E_BASE + 1), + WEBSOCKET_CLIENT_NULL = (E_BASE + 1), /** * @brief A webSocket client is not created. */ - WEBSOCKET_CLIENT_IS_NOT_CREAT = (E_BASE + 2), + WEBSOCKET_CLIENT_NOT_CREATED = (E_BASE + 2), /** - * @brief An error occurs while setting up a websocket connection. + * @brief An error occurs while setting up a WebSocket connection. */ WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), /** - * @brief An error occurs while parsing websocket connection parameters. + * @brief An error occurs while parsing WebSocket connection parameters. */ - WEBSOCKET_CONNECTION_PARSEURL_ERROR = (E_BASE + 5), + WEBSOCKET_CONNECTION_PARSE_URL_ERROR = (E_BASE + 5), /** - * @brief The memory is insufficient for creating a context during websocket connection setup. + * @brief The memory is insufficient for creating a context during WebSocket connection setup. */ - WEBSOCKET_CONNECTION_NO_MEMOERY = (E_BASE + 6), + WEBSOCKET_CONNECTION_NO_MEMORY = (E_BASE + 6), /** - * @brief The websocket connection is closed by the peer. + * @brief The WebSocket connection is closed by the peer. */ - WEBSOCKET_PEER_INITIATED_CLOSE = (E_BASE + 7), + WEBSOCKET_CONNECTION_CLOSED_BY_PEER = (E_BASE + 7), /** - * @brief The websocket connection is destroyed. + * @brief The WebSocket connection is destroyed. */ - WEBSOCKET_DESTROY = (E_BASE + 8), + WEBSOCKET_DESTROYED = (E_BASE + 8), /** - * @brief An incorrect protocol is used for websocket connection. + * @brief An incorrect protocol is used for WebSocket connection. */ WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), /** - * @brief The memory for the websocket client to send data is insufficient. + * @brief The memory for the WebSocket client to send data is insufficient. */ - WEBSOCKET_SEND_NO_MEMOERY_ERROR = (E_BASE + 10), + WEBSOCKET_SEND_NO_MEMORY = (E_BASE + 10), /** - * @brief The data sent by the websocket client is null. + * @brief The data sent by the WebSocket client is null. */ WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), /** - * @brief The length of the data sent by the websocket client exceeds the limit. + * @brief The length of the data sent by the WebSocket client exceeds the limit. */ - WEBSOCKET_DATA_LENGTH_EXCEEDS = (E_BASE + 12), + WEBSOCKET_DATA_LENGTH_EXCEEDED = (E_BASE + 12), /** - * @brief The queue length of the data sent by the websocket client exceeds the limit. + * @brief The queue length of the data sent by the WebSocket client exceeds the limit. */ - WEBSOCKET_QUEUE_LENGTH_EXCEEDS = (E_BASE + 13), + WEBSOCKET_QUEUE_LENGTH_EXCEEDED = (E_BASE + 13), /** - * @brief The context of the websocket client is null. + * @brief The context of the WebSocket client is null. */ - WEBSOCKET_ERROR_NO_CLIENTCONTEX = (E_BASE + 14), + WEBSOCKET_NO_CLIENT_CONTEXT = (E_BASE + 14), /** * @brief The header of the webSocket client is null. */ - WEBSOCKET_ERROR_NO_HEADR_CONTEXT = (E_BASE + 15), + WEBSOCKET_NO_HEADER_CONTEXT = (E_BASE + 15), /** - * @brief The header of the websocket client exceeds the limit. + * @brief The header of the WebSocket client exceeds the limit. */ - WEBSOCKET_ERROR_NO_HEADR_EXCEEDS = (E_BASE + 16), + WEBSOCKET_HEADER_EXCEEDED = (E_BASE + 16), /** - * @brief The websocket client is not connected. + * @brief The WebSocket client is not connected. */ - WEBSOCKET_ERROR_HAVE_NO_CONNECT = (E_BASE + 17), + WEBSOCKET_NO_CONNECTION = (E_BASE + 17), /** - * @brief The websocket client does not have the connection context. + * @brief The WebSocket client does not have the connection context. */ - WEBSOCKET_ERROR_HAVE_NO_CONNECT_CONTEXT = (E_BASE + 18), -} Websocket_ErrCode; + WEBSOCKET_NO_CONNECTION_CONTEXT = (E_BASE + 18), +} WebSocket_ErrCode; #ifdef __cplusplus } -- Gitee From a883d21b04ba9422a8756436a5e84032ca910a40 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Thu, 14 Dec 2023 09:49:21 +0800 Subject: [PATCH 12/36] add websocket code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 2 +- network/netstack/net_websocket/net_websocket_type.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 8538a6f61df..f2479100721 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -74,7 +74,7 @@ struct WebSocket *OH_NetStack_WebSocketClient_Constructor(WebSocket_OnOpenCallba * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_HeaderNode header); +int OH_NetStack_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_Header header); /** * @brief Connects the client to the server. diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index bf9b1d130d1..f3cce9e2b2e 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -139,13 +139,13 @@ typedef void (*WebSocket_OnCloseCallback)(struct WebSocket *client, WebSocket_Cl * @since 11 * @version 1.0 */ -struct WebSocket_HeaderNode { +struct WebSocket_Header { /** Header field name */ const char *fieldName; /** Header field content */ const char *fieldValue; /** Next pointer of the header linked list */ - struct WebSocket_HeaderNode *next; + struct WebSocket_Header *next; }; /** @@ -156,7 +156,7 @@ struct WebSocket_HeaderNode { * @version 1.0 */ struct WebSocket_RequestOptions { - struct WebSocket_HeaderNode *headers; + struct WebSocket_Header *headers; }; /** -- Gitee From 6cd90b1a79545223ee57dea1a84ab757712a727e Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Thu, 14 Dec 2023 18:01:31 +0800 Subject: [PATCH 13/36] add websocket code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index f2479100721..57caa9d64db 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,10 +59,8 @@ extern "C" { * @since 11 * @version 1.0 */ -struct WebSocket *OH_NetStack_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, - WebSocket_OnMessageCallback onMessage, - WebSocket_OnErrorCallback onError, - WebSocket_OnCloseCallback onclose); +struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, WebSocket_OnCloseCallback onclose); /** * @brief Adds the header information to the client request. @@ -74,7 +72,7 @@ struct WebSocket *OH_NetStack_WebSocketClient_Constructor(WebSocket_OnOpenCallba * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_Header header); +int OH_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_Header header); /** * @brief Connects the client to the server. @@ -88,8 +86,7 @@ int OH_NetStack_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSo * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Connect(struct WebSocket *client, const char *url, - struct WebSocket_RequestOptions options); +int OH_WebSocketClient_Connect(struct WebSocket *client, const char *url, struct WebSocket_RequestOptions options); /** * @brief Sends data from the client to the server. @@ -103,7 +100,7 @@ int OH_NetStack_WebSocketClient_Connect(struct WebSocket *client, const char *ur * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Send(struct WebSocket *client, char *data, size_t length); +int OH_WebSocketClient_Send(struct WebSocket *client, char *data, size_t length); /** * @brief Closes a webSocket connection. @@ -117,7 +114,7 @@ int OH_NetStack_WebSocketClient_Send(struct WebSocket *client, char *data, size_ * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Close(struct WebSocket *client, struct WebSocket_CloseOption options); +int OH_WebSocketClient_Close(struct WebSocket *client, struct WebSocket_CloseOption options); /** * @brief Releases the context and resources of the websocket connection. @@ -129,7 +126,7 @@ int OH_NetStack_WebSocketClient_Close(struct WebSocket *client, struct WebSocket * @since 11 * @version 1.0 */ -int OH_NetStack_WebSocketClient_Destroy(struct WebSocket *client); +int OH_WebSocketClient_Destroy(struct WebSocket *client); #ifdef __cplusplus } -- Gitee From 34649db02a5d180d502811daa7fae48a678a88e4 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Thu, 14 Dec 2023 18:10:00 +0800 Subject: [PATCH 14/36] add websocket code Signed-off-by: liuxiyao223 --- .../netstack/net_websocket/libwebsocket.ndk.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json index eef7fb3b1ff..e143770463c 100755 --- a/network/netstack/net_websocket/libwebsocket.ndk.json +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -1,9 +1,9 @@ [ - {"name": "OH_NetStack_WebSocketClient_Constructor"}, - {"name": "OH_NetStack_WebSocketClient_AddHeader"}, - {"name": "OH_NetStack_WebSocketClient_Connect"}, - {"name": "OH_NetStack_WebSocketClient_Send"}, - {"name": "OH_NetStack_WebSocketClient_Close"}, - {"name": "OH_NetStack_WebSocketClient_Destroy"}, - {"name": "OH_NetStack_WebSocketClient_FreeAll"} + {"name": "OH_WebSocketClient_Constructor"}, + {"name": "OH_WebSocketClient_AddHeader"}, + {"name": "OH_WebSocketClient_Connect"}, + {"name": "OH_WebSocketClient_Send"}, + {"name": "OH_WebSocketClient_Close"}, + {"name": "OH_WebSocketClient_Destroy"}, + {"name": "OH_WebSocketClient_FreeAll"} ] \ No newline at end of file -- Gitee From 6bacd0625497c0c3226545c6b077347bcbb424fb Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 16:14:10 +0800 Subject: [PATCH 15/36] add websocket code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 12 ++++++------ network/netstack/net_websocket/net_websocket_type.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 57caa9d64db..4654ec07854 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -67,7 +67,7 @@ struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen * * @param client Pointer to the websocket client. * @param header Header information - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @syscap SystemCapability.Communication.NetStack * @since 11 * @version 1.0 @@ -80,7 +80,7 @@ int OH_WebSocketClient_AddHeader(struct WebSocket *client, struct WebSocket_Head * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 @@ -94,7 +94,7 @@ int OH_WebSocketClient_Connect(struct WebSocket *client, const char *url, struct * @param client Pointer to the websocket client. * @param data Data sent by the client. * @param length Length of the data sent by the client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 @@ -103,12 +103,12 @@ int OH_WebSocketClient_Connect(struct WebSocket *client, const char *url, struct int OH_WebSocketClient_Send(struct WebSocket *client, char *data, size_t length); /** - * @brief Closes a webSocket connection. + * @brief Closes a websocket connection. * * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. * @param options Optional parameters. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 @@ -120,7 +120,7 @@ int OH_WebSocketClient_Close(struct WebSocket *client, struct WebSocket_CloseOpt * @brief Releases the context and resources of the websocket connection. * * @param client Pointer to the websocket client. - * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebSocket_ErrCode}. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link OH_Websocket_ErrCode}. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetStack * @since 11 diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index f3cce9e2b2e..0ba38662c57 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -95,7 +95,7 @@ struct WebSocket_OpenResult { /** * @brief Defines the callback function invoked when an open message is received. * - * @param client WebSocket client. + * @param client websocket client. * @param openResult Content of the open message received by the WebSocket client. * @since 11 * @version 1.0 @@ -105,7 +105,7 @@ typedef void (*WebSocket_OnOpenCallback)(struct WebSocket *client, WebSocket_Ope /** * @brief Defines the callback function invoked when data is received. * - * @param client WebSocket client. + * @param client websocket client. * @param data Data received by the WebSocket client. * @param length Length of the data received by the WebSocket client. * @since 11 @@ -116,7 +116,7 @@ typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data /** * @brief Defines the callback function invoked when an error message is received. * - * @param client WebSocket client. + * @param client websocket client. * @param errorResult Content of the connection error message received by the WebSocket client. * @since 11 * @version 1.0 @@ -126,7 +126,7 @@ typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_Er /** * @brief Defines the callback function invoked when a close message is received. * - * @param client webSocket client. + * @param client websocket client. * @param closeResult Content of the close message received by the webSocket client. * @since 11 * @version 1.0 -- Gitee From b6d0bd74c26d6c750a7e088d21600fd45c0602c3 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 17:11:55 +0800 Subject: [PATCH 16/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 2 +- network/netstack/net_websocket/net_websocket_type.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 4654ec07854..cc3d60231a1 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -103,7 +103,7 @@ int OH_WebSocketClient_Connect(struct WebSocket *client, const char *url, struct int OH_WebSocketClient_Send(struct WebSocket *client, char *data, size_t length); /** - * @brief Closes a websocket connection. + * @brief Closes a webSocket connection. * * @param client Pointer to the websocket client. * @param url URL for the client to connect to the server. diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 0ba38662c57..5904b6aae01 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -96,7 +96,7 @@ struct WebSocket_OpenResult { * @brief Defines the callback function invoked when an open message is received. * * @param client websocket client. - * @param openResult Content of the open message received by the WebSocket client. + * @param openResult Content of the open message received by the websocket client. * @since 11 * @version 1.0 */ @@ -106,8 +106,8 @@ typedef void (*WebSocket_OnOpenCallback)(struct WebSocket *client, WebSocket_Ope * @brief Defines the callback function invoked when data is received. * * @param client websocket client. - * @param data Data received by the WebSocket client. - * @param length Length of the data received by the WebSocket client. + * @param data Data received by the websocket client. + * @param length Length of the data received by the websocket client. * @since 11 * @version 1.0 */ @@ -117,7 +117,7 @@ typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data * @brief Defines the callback function invoked when an error message is received. * * @param client websocket client. - * @param errorResult Content of the connection error message received by the WebSocket client. + * @param errorResult Content of the connection error message received by the webSocket client. * @since 11 * @version 1.0 */ @@ -127,7 +127,7 @@ typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_Er * @brief Defines the callback function invoked when a close message is received. * * @param client websocket client. - * @param closeResult Content of the close message received by the webSocket client. + * @param closeResult Content of the close message received by the websocket client. * @since 11 * @version 1.0 */ -- Gitee From 23bf79d42cbe53a74235943f8a8e3b3aa8454866 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 17:27:45 +0800 Subject: [PATCH 17/36] add websocket code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket_type.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 5904b6aae01..c3868f01c96 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -117,7 +117,7 @@ typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data * @brief Defines the callback function invoked when an error message is received. * * @param client websocket client. - * @param errorResult Content of the connection error message received by the webSocket client. + * @param errorResult Content of the connection error message received by the websocket client. * @since 11 * @version 1.0 */ @@ -126,8 +126,8 @@ typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_Er /** * @brief Defines the callback function invoked when a close message is received. * - * @param client websocket client. - * @param closeResult Content of the close message received by the websocket client. + * @param client webSocket client. + * @param closeResult Content of the close message received by the webSocket client. * @since 11 * @version 1.0 */ -- Gitee From 4a662129ecdf0d23fb38c0f00a78f3bf85f8f97d Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 18:13:18 +0800 Subject: [PATCH 18/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index c3868f01c96..205318e8c04 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -134,7 +134,7 @@ typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_Er typedef void (*WebSocket_OnCloseCallback)(struct WebSocket *client, WebSocket_CloseResult closeResult); /** - * @brief Adds the header linked list to the WebSocket client. + * @brief Adds the header linked list to the websocket client. * * @since 11 * @version 1.0 -- Gitee From c33dbb22461337400c78f0a2a4e09ad998a81f50 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 19:42:42 +0800 Subject: [PATCH 19/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- .../net_websocket/net_websocket_type.h | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 205318e8c04..9636ffc8b0d 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -190,67 +190,67 @@ typedef enum WebSocket_ErrCode { E_BASE = 1000, /** - * @brief The WebSocket client is null. + * @brief The websocket client is null. */ WEBSOCKET_CLIENT_NULL = (E_BASE + 1), /** - * @brief A webSocket client is not created. + * @brief A websocket client is not created. */ WEBSOCKET_CLIENT_NOT_CREATED = (E_BASE + 2), /** - * @brief An error occurs while setting up a WebSocket connection. + * @brief An error occurs while setting up a websocket connection. */ WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3), /** - * @brief An error occurs while parsing WebSocket connection parameters. + * @brief An error occurs while parsing websocket connection parameters. */ WEBSOCKET_CONNECTION_PARSE_URL_ERROR = (E_BASE + 5), /** - * @brief The memory is insufficient for creating a context during WebSocket connection setup. + * @brief The memory is insufficient for creating a context during websocket connection setup. */ WEBSOCKET_CONNECTION_NO_MEMORY = (E_BASE + 6), /** - * @brief The WebSocket connection is closed by the peer. + * @brief The websocket connection is closed by the peer. */ WEBSOCKET_CONNECTION_CLOSED_BY_PEER = (E_BASE + 7), /** - * @brief The WebSocket connection is destroyed. + * @brief The websocket connection is destroyed. */ WEBSOCKET_DESTROYED = (E_BASE + 8), /** - * @brief An incorrect protocol is used for WebSocket connection. + * @brief An incorrect protocol is used for websocket connection. */ WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9), /** - * @brief The memory for the WebSocket client to send data is insufficient. + * @brief The memory for the websocket client to send data is insufficient. */ WEBSOCKET_SEND_NO_MEMORY = (E_BASE + 10), /** - * @brief The data sent by the WebSocket client is null. + * @brief The data sent by the websocket client is null. */ WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11), /** - * @brief The length of the data sent by the WebSocket client exceeds the limit. + * @brief The length of the data sent by the websocket client exceeds the limit. */ WEBSOCKET_DATA_LENGTH_EXCEEDED = (E_BASE + 12), /** - * @brief The queue length of the data sent by the WebSocket client exceeds the limit. + * @brief The queue length of the data sent by the websocket client exceeds the limit. */ WEBSOCKET_QUEUE_LENGTH_EXCEEDED = (E_BASE + 13), /** - * @brief The context of the WebSocket client is null. + * @brief The context of the websocket client is null. */ WEBSOCKET_NO_CLIENT_CONTEXT = (E_BASE + 14), @@ -260,7 +260,7 @@ typedef enum WebSocket_ErrCode { WEBSOCKET_NO_HEADER_CONTEXT = (E_BASE + 15), /** - * @brief The header of the WebSocket client exceeds the limit. + * @brief The header of the websocket client exceeds the limit. */ WEBSOCKET_HEADER_EXCEEDED = (E_BASE + 16), @@ -270,7 +270,7 @@ typedef enum WebSocket_ErrCode { WEBSOCKET_NO_CONNECTION = (E_BASE + 17), /** - * @brief The WebSocket client does not have the connection context. + * @brief The websocket client does not have the connection context. */ WEBSOCKET_NO_CONNECTION_CONTEXT = (E_BASE + 18), } WebSocket_ErrCode; -- Gitee From 8f5601ef4a45214a138233f9c93bb142ba97629b Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 16 Dec 2023 09:56:24 +0000 Subject: [PATCH 20/36] update network/netstack/net_websocket/BUILD.gn. Signed-off-by: Aurora --- network/netstack/net_websocket/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn index 8ec894bd9de..bc719edb5d5 100755 --- a/network/netstack/net_websocket/BUILD.gn +++ b/network/netstack/net_websocket/BUILD.gn @@ -32,3 +32,4 @@ ohos_ndk_headers("websocket_header") { "net_websocket_type.h", ] } + -- Gitee From 592a05eb0d49ee6305a5cf36d5f1fb3726eb16b9 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 16 Dec 2023 10:19:04 +0000 Subject: [PATCH 21/36] update network/netstack/net_websocket/BUILD.gn. Signed-off-by: Aurora --- network/netstack/net_websocket/BUILD.gn | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn index bc719edb5d5..b12b3522cc1 100755 --- a/network/netstack/net_websocket/BUILD.gn +++ b/network/netstack/net_websocket/BUILD.gn @@ -31,5 +31,4 @@ ohos_ndk_headers("websocket_header") { "net_websocket.h", "net_websocket_type.h", ] -} - +} \ No newline at end of file -- Gitee From fc5acf17e07089b69083574c92b19dec042342c0 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 18 Dec 2023 02:34:20 +0000 Subject: [PATCH 22/36] update network/netstack/net_websocket/net_websocket_type.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 9636ffc8b0d..58799e9338a 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -146,7 +146,7 @@ struct WebSocket_Header { const char *fieldValue; /** Next pointer of the header linked list */ struct WebSocket_Header *next; -}; +} /** * @brief Defines the parameters for the connection between the WebSocket client and server. -- Gitee From 7558e3e012200b43630e7cf298c54aa81bb76576 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Mon, 18 Dec 2023 10:36:00 +0800 Subject: [PATCH 23/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 58799e9338a..9636ffc8b0d 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -146,7 +146,7 @@ struct WebSocket_Header { const char *fieldValue; /** Next pointer of the header linked list */ struct WebSocket_Header *next; -} +}; /** * @brief Defines the parameters for the connection between the WebSocket client and server. -- Gitee From 7dd783bb4f40736e153234f30480fbfb06fb4ef9 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 18 Dec 2023 02:55:03 +0000 Subject: [PATCH 24/36] update network/netstack/net_websocket/net_websocket.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index cc3d60231a1..93c1039d93a 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,8 +59,10 @@ extern "C" { * @since 11 * @version 1.0 */ -struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, WebSocket_OnMessageCallback onMessage, - WebSocket_OnErrorCallback onError, WebSocket_OnCloseCallback onclose); +struct Websocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, + WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, + WebSocket_OnCloseCallback onclose) /** * @brief Adds the header information to the client request. -- Gitee From 94f1eed54b651dac3d39e4aca64a8fb47440d75d Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Mon, 18 Dec 2023 11:06:35 +0800 Subject: [PATCH 25/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 93c1039d93a..cc3d60231a1 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,10 +59,8 @@ extern "C" { * @since 11 * @version 1.0 */ -struct Websocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, - WebSocket_OnMessageCallback onMessage, - WebSocket_OnErrorCallback onError, - WebSocket_OnCloseCallback onclose) +struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, WebSocket_OnCloseCallback onclose); /** * @brief Adds the header information to the client request. -- Gitee From 2f947962348f9683fbf446bd2189e3ff54b209d1 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 18 Dec 2023 03:20:02 +0000 Subject: [PATCH 26/36] update network/netstack/net_websocket/net_websocket.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index cc3d60231a1..93c1039d93a 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,8 +59,10 @@ extern "C" { * @since 11 * @version 1.0 */ -struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, WebSocket_OnMessageCallback onMessage, - WebSocket_OnErrorCallback onError, WebSocket_OnCloseCallback onclose); +struct Websocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, + WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, + WebSocket_OnCloseCallback onclose) /** * @brief Adds the header information to the client request. -- Gitee From 5b845179ce1bc0916d0f673a588cf5caa144d00b Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Mon, 18 Dec 2023 11:23:45 +0800 Subject: [PATCH 27/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket.h b/network/netstack/net_websocket/net_websocket.h index 93c1039d93a..cc3d60231a1 100755 --- a/network/netstack/net_websocket/net_websocket.h +++ b/network/netstack/net_websocket/net_websocket.h @@ -59,10 +59,8 @@ extern "C" { * @since 11 * @version 1.0 */ -struct Websocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, - WebSocket_OnMessageCallback onMessage, - WebSocket_OnErrorCallback onError, - WebSocket_OnCloseCallback onclose) +struct WebSocket *OH_WebSocketClient_Constructor(WebSocket_OnOpenCallback onOpen, WebSocket_OnMessageCallback onMessage, + WebSocket_OnErrorCallback onError, WebSocket_OnCloseCallback onclose); /** * @brief Adds the header information to the client request. -- Gitee From a94ed6681328043db18586077cd2f089baaedfb3 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 18 Dec 2023 09:38:38 +0000 Subject: [PATCH 28/36] update network/netstack/net_websocket/net_websocket_type.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 9636ffc8b0d..ca5fc28a8f1 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -195,7 +195,7 @@ typedef enum WebSocket_ErrCode { WEBSOCKET_CLIENT_NULL = (E_BASE + 1), /** - * @brief A websocket client is not created. + * @brief A webSocket client is not created. */ WEBSOCKET_CLIENT_NOT_CREATED = (E_BASE + 2), -- Gitee From 05839e660de3d5bd845dc72471ba0c8b7c1755c7 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 18 Dec 2023 09:46:20 +0000 Subject: [PATCH 29/36] update network/netstack/net_websocket/net_websocket_type.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index ca5fc28a8f1..97f8a8687d8 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -265,7 +265,7 @@ typedef enum WebSocket_ErrCode { WEBSOCKET_HEADER_EXCEEDED = (E_BASE + 16), /** - * @brief The WebSocket client is not connected. + * @brief The websocket client is not connected. */ WEBSOCKET_NO_CONNECTION = (E_BASE + 17), -- Gitee From 746336ab064cccf04444cbdba1070178f4c664d7 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 19 Dec 2023 06:38:36 +0000 Subject: [PATCH 30/36] update network/netstack/net_websocket/libwebsocket.ndk.json. Signed-off-by: Aurora --- network/netstack/net_websocket/libwebsocket.ndk.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json index e143770463c..f699898a373 100755 --- a/network/netstack/net_websocket/libwebsocket.ndk.json +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -4,6 +4,5 @@ {"name": "OH_WebSocketClient_Connect"}, {"name": "OH_WebSocketClient_Send"}, {"name": "OH_WebSocketClient_Close"}, - {"name": "OH_WebSocketClient_Destroy"}, - {"name": "OH_WebSocketClient_FreeAll"} + {"name": "OH_WebSocketClient_Destroy"} ] \ No newline at end of file -- Gitee From edb891cee7110febeb1c78c727d64892e0a9aa41 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 19 Dec 2023 06:57:09 +0000 Subject: [PATCH 31/36] update network/netstack/net_websocket/net_websocket_type.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 97f8a8687d8..86f1ef6731d 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -156,7 +156,7 @@ struct WebSocket_Header { * @version 1.0 */ struct WebSocket_RequestOptions { - struct WebSocket_Header *headers; +struct WebSocket_Header *headers; }; /** -- Gitee From 6b7ef595ac46925da4a806b4f9a937339aabd9b6 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 19 Dec 2023 07:07:04 +0000 Subject: [PATCH 32/36] update network/netstack/net_websocket/net_websocket_type.h. Signed-off-by: Aurora --- network/netstack/net_websocket/net_websocket_type.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 86f1ef6731d..38026fe482b 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -155,9 +155,7 @@ struct WebSocket_Header { * @since 11 * @version 1.0 */ -struct WebSocket_RequestOptions { -struct WebSocket_Header *headers; -}; +struct WebSocket_RequestOptions { struct WebSocket_Header *headers; }; /** * @brief Defines the WebSocket client structure. -- Gitee From 87ff065f6d4fdce62d869d6f97b3ae6dc9d3c443 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Tue, 19 Dec 2023 15:41:33 +0800 Subject: [PATCH 33/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/net_websocket_type.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/net_websocket_type.h b/network/netstack/net_websocket/net_websocket_type.h index 38026fe482b..97f8a8687d8 100755 --- a/network/netstack/net_websocket/net_websocket_type.h +++ b/network/netstack/net_websocket/net_websocket_type.h @@ -155,7 +155,9 @@ struct WebSocket_Header { * @since 11 * @version 1.0 */ -struct WebSocket_RequestOptions { struct WebSocket_Header *headers; }; +struct WebSocket_RequestOptions { + struct WebSocket_Header *headers; +}; /** * @brief Defines the WebSocket client structure. -- Gitee From b6cc89ddb399e37d3dc6b18ecaa44ff99f2c2a5d Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Tue, 19 Dec 2023 20:33:28 +0800 Subject: [PATCH 34/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn index b12b3522cc1..8ec894bd9de 100755 --- a/network/netstack/net_websocket/BUILD.gn +++ b/network/netstack/net_websocket/BUILD.gn @@ -31,4 +31,4 @@ ohos_ndk_headers("websocket_header") { "net_websocket.h", "net_websocket_type.h", ] -} \ No newline at end of file +} -- Gitee From 11ae4ce7b11320a893636c1fbbb6839c3b6ba2a3 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 20 Dec 2023 17:17:55 +0800 Subject: [PATCH 35/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- .../net_websocket/libwebsocket.ndk.json | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/network/netstack/net_websocket/libwebsocket.ndk.json b/network/netstack/net_websocket/libwebsocket.ndk.json index f699898a373..48b4ef5501a 100755 --- a/network/netstack/net_websocket/libwebsocket.ndk.json +++ b/network/netstack/net_websocket/libwebsocket.ndk.json @@ -1,8 +1,26 @@ [ - {"name": "OH_WebSocketClient_Constructor"}, - {"name": "OH_WebSocketClient_AddHeader"}, - {"name": "OH_WebSocketClient_Connect"}, - {"name": "OH_WebSocketClient_Send"}, - {"name": "OH_WebSocketClient_Close"}, - {"name": "OH_WebSocketClient_Destroy"} + { + "first_introduced": "11", + "name": "OH_WebSocketClient_Constructor" + }, + { + "first_introduced": "11", + "name": "OH_WebSocketClient_AddHeader" + }, + { + "first_introduced": "11", + "name": "OH_WebSocketClient_Connect" + }, + { + "first_introduced": "11", + "name": "OH_WebSocketClient_Send" + }, + { + "first_introduced": "11", + "name": "OH_WebSocketClient_Close" + }, + { + "first_introduced": "11", + "name": "OH_WebSocketClient_Destroy" + } ] \ No newline at end of file -- Gitee From 7b9984d82836d6789dfe294d86837b0cb0390044 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Wed, 20 Dec 2023 18:02:47 +0800 Subject: [PATCH 36/36] add websocket inner api and capi function code Signed-off-by: liuxiyao223 --- network/netstack/net_websocket/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/network/netstack/net_websocket/BUILD.gn b/network/netstack/net_websocket/BUILD.gn index 8ec894bd9de..8bfe616c447 100755 --- a/network/netstack/net_websocket/BUILD.gn +++ b/network/netstack/net_websocket/BUILD.gn @@ -20,13 +20,13 @@ ohos_ndk_library("libnet_websocket") { min_compact_version = "1" system_capability = "SystemCapability.Communication.NetStack" system_capability_headers = [ - "network/netstack/net_websocket/net_websocket.h", - "network/netstack/net_websocket/net_websocket_type.h", + "network/netstack/net_websocket.h", + "network/netstack/net_websocket_type.h", ] } ohos_ndk_headers("websocket_header") { - dest_dir = "$ndk_headers_out_dir/network/netstack/net_websocket" + dest_dir = "$ndk_headers_out_dir/network/netstack" sources = [ "net_websocket.h", "net_websocket_type.h", -- Gitee