From: luozheng <1732036298@qq.com> Date: Sat, 19 Jul 2025 07:08:40 +0000 (+0800) Subject: open_source文件夹下的openharmony文件夹下third_party和foundation文件夹合并提交 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~237 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=203cb2d596612c16ad794ed252d19838de4604de;p=mirrors%2FFD230.git open_source文件夹下的openharmony文件夹下third_party和foundation文件夹合并提交 --- diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-cli/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-cli/libams.a index ed105e4ed..084a0faf4 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-cli/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-cli/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-ser/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-ser/libams.a index bce4d9af1..ea7325ce7 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-ser/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-auto-ota-ser/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a index 8279bdf6c..b294a766d 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a index 38fd93400..a4d263868 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt index 0c1478344..6e76b8c55 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt @@ -48,7 +48,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/ohos_deps ${ROOT_DIR}/application/wearable/nativeabilityfwk/include ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/set_desktop/include ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector/libs ${ROOT_DIR}/open_source/openharmony/third_party/cJSON ${ROOT_DIR}/open_source/openharmony/third_party/qrcodegen/cpp @@ -218,7 +217,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/ohos_deps ${ROOT_DIR}/application/wearable/nativeabilityfwk/include ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/set_desktop/include ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector/libs ${ROOT_DIR}/open_source/openharmony/third_party/cJSON ${ROOT_DIR}/open_source/openharmony/third_party/qrcodegen/cpp @@ -267,6 +265,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/components/baidu_map_component.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/app_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/device_module.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/modules/nativeapi_ohos_deviceinfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/network/network_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/nfc_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/vibrator_module.cpp @@ -509,3 +508,244 @@ install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/interfaces" "*") install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/include" "*") build_component() + +set(COMPONENT_NAME "netstack_http") +set(MODULE_NAME "ohos") +set(AUTO_DEF_FILE_ID TRUE) + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/include + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/http/src/http_api.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/http/src/http_client.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/http/src/http_wrapper.c +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES + CONFIG_USE_LWIP + CONFIG_HTTP_SECURE +) + +set(PRIVATE_DEFINES +) + +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/interfaces" "*") +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/include" "*") + +build_component() + +set(COMPONENT_NAME "ace_http") +set(MODULE_NAME "ohos") +set(AUTO_DEF_FILE_ID TRUE) + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/base + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/net + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/modules/net/http_module.cpp +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES + FEATURE_MODULE_HTTP +) + +set(PRIVATE_DEFINES +) + +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/interfaces" "*") +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/include" "*") + +build_component() + +set(COMPONENT_NAME "ace_websocket") +set(MODULE_NAME "ohos") +set(AUTO_DEF_FILE_ID TRUE) + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/base + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/net + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/modules/websocket/websocket_module.cpp +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES + FEATURE_MODULE_WEBSOCKET +) + +set(PRIVATE_DEFINES +) + +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/interfaces" "*") +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/include" "*") + +build_component() + +set(COMPONENT_NAME "websocket") +set(MODULE_NAME "ohos") +set(AUTO_DEF_FILE_ID TRUE) + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_frame.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_list.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_priv.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_api.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_string.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/netstack/websocket/src/net_websocket_thread.c +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_DEFINES + WEBSOCKET_SSL_ENABLE +) + +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/interfaces" "*") +install_sdk_by_sh("${CMAKE_CURRENT_SOURCE_DIR}/include" "*") + +build_component() \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h index b7ee4182e..95b2f3430 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h @@ -273,9 +273,9 @@ jerry_value_t ListForWatcherCallbackFunc(const jerry_value_t func, const jerry_value_t *args, const jerry_length_t argsLength); #ifdef JS_TOUCH_EVENT_SUPPORT -jerry_value_t *ConvertBaseEventInfo(const Event &event, const uint16_t id); -bool CallBaseEvent(const jerry_value_t func, const Event &event, const uint16_t id); -jerry_value_t *ConvertDragEventInfo(const DragEvent &event, const uint16_t id); +jerry_value_t *ConvertBaseEventInfo(const Event &event, const uint16_t id, UIView &view); +bool CallBaseEvent(const jerry_value_t func, const Event &event, const uint16_t id, UIView &view); +jerry_value_t *ConvertDragEventInfo(const DragEvent &event, const uint16_t id, UIView &view); jerry_value_t *ConvertKeyEventInfo(const KeyEvent &event); #endif void ClearEventListener(const jerry_value_t args[], uint8_t argc); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace.a index 6f1bca9d4..911eac802 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace_http.a new file mode 100644 index 000000000..4adbcbe7b Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libace_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libnetstack_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libnetstack_http.a new file mode 100644 index 000000000..772a439fa Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libnetstack_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libwebsocket.a new file mode 100644 index 000000000..575276241 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-cli/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace.a index bd6f95e4d..9ec173911 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace_http.a new file mode 100644 index 000000000..12f9b105b Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libace_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libnetstack_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libnetstack_http.a new file mode 100644 index 000000000..055db3bd0 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libnetstack_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libwebsocket.a new file mode 100644 index 000000000..82997b1ff Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-auto-ota-ser/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a index f829a5801..e807091dc 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace_http.a new file mode 100644 index 000000000..cdfdb3135 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libnetstack_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libnetstack_http.a new file mode 100644 index 000000000..b9c1bb00b Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libnetstack_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a new file mode 100644 index 000000000..93b5e6f80 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-target3/libnetstack_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-target3/libnetstack_http.a new file mode 100644 index 000000000..eb0cef510 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-target3/libnetstack_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a index 89566229a..0bff7a3a2 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace_http.a new file mode 100644 index 000000000..e7707d710 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libnetstack_http.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libnetstack_http.a new file mode 100644 index 000000000..c44ffefb4 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libnetstack_http.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libwebsocket.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libwebsocket.a new file mode 100644 index 000000000..0c6215674 Binary files /dev/null and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libwebsocket.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp index fedbd8cb8..e1ff227e3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp @@ -38,6 +38,8 @@ static Component::AnimationsNode *g_animationListHead = nullptr; static bool g_isAnimatorStarted = false; const char * const Component::ROTATE_SCROLL = "rotation"; const char * const Component::FUNC_SCROLL = "scroll"; +const char * const Component::FUNC_GETX = "getX"; +const char * const Component::FUNC_GETY = "getY"; void Component::HandlerAnimations() { Component::AnimationsNode *point = g_animationListHead; @@ -113,6 +115,8 @@ Component::Component(jerry_value_t options, jerry_value_t children, AppStyleMana jerry_value_t global = jerry_get_global_object(); viewModel_ = jerryx_get_property_str(global, ATTR_ROOT); jerry_release_value(global); + RegisterNamedFunction(OHOS::ACELite::Component::FUNC_GETX, GetX); + RegisterNamedFunction(OHOS::ACELite::Component::FUNC_GETY, GetY); } /** @@ -2121,5 +2125,27 @@ bool Component::ViewOnTouchListener::OnDragEnd(UIView &view, const DragEvent &ev return ret; } +JSValue Component::GetX(const JSValue func, const JSValue dom, const JSValue args[], const jerry_length_t size) +{ + UIView *view = reinterpret_cast(ComponentUtils::GetViewFromBindingObject(dom)); + if (view == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "failed to get globalX. view is nullptr"); + return -1; + } + double x = static_cast(view->GetOrigRect().GetX()); + return jerry_create_number(x); +} + +JSValue Component::GetY(const JSValue func, const JSValue dom, const JSValue args[], const jerry_length_t size) +{ + UIView *view = reinterpret_cast(ComponentUtils::GetViewFromBindingObject(dom)); + if (view == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "failed to get globalY. view is nullptr"); + return -1; + } + double y = static_cast(view->GetOrigRect().GetY()); + return jerry_create_number(y); +} + } // namespace ACELite } // namespace OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h index 18407fe21..ab0f4b6d7 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h @@ -631,6 +631,16 @@ private: */ void RemoveAllChildren(); + /** + * @brief Obtains the X coordinate of the component origin. + */ + static JSValue GetX(const JSValue func, const JSValue dom, const JSValue args[], const jerry_length_t size); + + /** + * @brief Obtains the Y coordinate of the component origin. + */ + static JSValue GetY(const JSValue func, const JSValue dom, const JSValue args[], const jerry_length_t size); + /** * @brief childHead_ the child list */ @@ -682,6 +692,8 @@ private: Dimension marginLeft_; Dimension marginRight_; Dimension marginBottom_; + static const char * const FUNC_GETX; + static const char * const FUNC_GETY; }; } // namespace ACELite } // namespace OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp index 662cfb3cd..1f239a9cd 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp @@ -57,7 +57,7 @@ ViewOnTouchStartListener::~ViewOnTouchStartListener() bool ViewOnTouchStartListener::OnPress(UIView &view, const PressEvent &event) { - return CallBaseEvent(fn_, event, id_); + return CallBaseEvent(fn_, event, id_, view); } ViewOnTouchMoveListener::ViewOnTouchMoveListener(jerry_value_t fn, uint16_t id) @@ -76,8 +76,7 @@ bool ViewOnTouchMoveListener::OnDrag(UIView &view, const DragEvent &event) if (jerry_value_is_undefined(fn_)) { return false; } - - jerry_value_t *args = ConvertDragEventInfo(event, id_); + jerry_value_t *args = ConvertDragEventInfo(event, id_, view); jerry_release_value(CallJSFunctionOnRoot(fn_, args, 1)); ClearEventListener(args, 1); return true; @@ -96,7 +95,7 @@ ViewOnTouchEndListener::~ViewOnTouchEndListener() bool ViewOnTouchEndListener::OnRelease(UIView &view, const ReleaseEvent &event) { - return CallBaseEvent(fn_, event, id_); + return CallBaseEvent(fn_, event, id_, view); } ViewOnTouchCancelListener::ViewOnTouchCancelListener(jerry_value_t fn, uint16_t id) @@ -111,7 +110,7 @@ ViewOnTouchCancelListener::~ViewOnTouchCancelListener() } bool ViewOnTouchCancelListener::OnCancel(UIView &view, const CancelEvent &event) { - return CallBaseEvent(fn_, event, id_); + return CallBaseEvent(fn_, event, id_, view); } #endif // JS_TOUCH_EVENT_SUPPORT diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.cpp index ae9237f38..50412d3f5 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.cpp @@ -105,6 +105,7 @@ PickerViewComponent::PickerViewComponent(jerry_value_t options, jerry_value_t ch textSelected_(0), pTextArray_(nullptr), textArraySize_(0), + overflowMode_(UILabel::LINE_BREAK_CLIP), textPickerListener_(nullptr), #ifdef FEATURE_COMPONENT_DATE_PICKER dateSelected_(nullptr), @@ -418,6 +419,7 @@ void PickerViewComponent::UpdatePickerStyles() const textPicker->SetHighlightFont(selectedFontFamily_, selectedFontSize_); textPicker->SetTextColor(color_, selectedColor_); textPicker->SetItemHeight(pickerItemHeight_); + textPicker->SetTextLineBreakMode(overflowMode_); break; } case PickerType::TIME: { @@ -538,6 +540,32 @@ bool PickerViewComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t return result; } +void PickerViewComponent::SetTextOverflow(const AppStyleItem *styleItem) +{ + if (!IsStyleValueTypeString(styleItem)) { + HILOG_ERROR(HILOG_MODULE_ACE, "text overflow style value is invalid!"); + return; + } + uint16_t propNameId = KeyParser::ParseKeyId(GetStyleStrValue(styleItem), GetStyleStrValueLen(styleItem)); + switch (propNameId) { + case K_CLIP: + overflowMode_ = UILabel::LINE_BREAK_CLIP; + break; + case K_ELLIPSIS: + overflowMode_ = UILabel::LINE_BREAK_ELLIPSIS; + break; + case K_EXPAND: + overflowMode_ = UILabel::LINE_BREAK_ADAPT; + break; + case K_BREAK: + overflowMode_ = UILabel::LINE_BREAK_WRAP; + break; + default: + break; + } + +} + bool PickerViewComponent::ApplyPrivateStyle(const AppStyleItem *styleItem) { uint16_t styleNameId = GetStylePropNameId(styleItem); @@ -561,6 +589,9 @@ bool PickerViewComponent::ApplyPrivateStyle(const AppStyleItem *styleItem) pickerItemHeight_ = fontSize_ + PICKER_ITEM_HEIGHT_GAP; } break; + case K_TEXT_OVERFLOW: + SetTextOverflow(styleItem); + break; case K_FONT_FAMILY: CopyFontFamily(fontFamily_, GetStyleStrValue(styleItem)); break; diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.h index 85fe4e93f..2f9579ee5 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/picker_view_component.h @@ -217,6 +217,7 @@ private: #endif // FEATURE_COMPONENT_DATE_PICKER bool SetPickerSelected(jerry_value_t selectedValue); void SetPickerLoopState(); + void SetTextOverflow(const AppStyleItem* styleItem); void SetPickerListener(jerry_value_t funcValue) const; bool SetTextPickerRange(jerry_value_t rangeValue); void ReleaseTextRange(); @@ -234,6 +235,7 @@ private: char* selectedFontFamily_; uint16_t pickerItemHeight_; bool loopState_; + uint8_t overflowMode_; // text picker-view attributes uint16_t textSelected_; diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h index ec913e8c3..eca7d90ff 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h @@ -17,7 +17,7 @@ #define OHOS_ACELITE_CONFIG_H // some features depend on the low layer configuration -#include "graphic_config.h" +#define ENABLE_ROTATE_INPUT 1 /** * ================================================================================================ @@ -244,4 +244,9 @@ */ #define JS_TOUCH_EVENT_SUPPORT +/** + * support cipher module + */ +#define ENABLE_MODULE_CIPHER + #endif // OHOS_ACELITE_CONFIG_H diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/app_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/app_module.h index 621212ba4..50dca7468 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/app_module.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/app_module.h @@ -23,7 +23,7 @@ #include "product_adapter.h" #include "abilityms_slite_client.h" #include "NativeAbility.h" -#include "SetDesktopModel.h" +#include "settings/SetDesktopModel.h" namespace OHOS { namespace ACELite { diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.cpp index 6598ea0c9..437e634ae 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.cpp @@ -23,6 +23,7 @@ #include "media_log.h" #include "global.h" #include "screen.h" +#include "parameter.h" namespace OHOS { namespace ACELite { @@ -38,10 +39,9 @@ const char * const DeviceModule::DEVICE_WINDOW_HEIGHT_NAME = "windowHeight"; const char * const DeviceModule::DEVICE_SCREEN_DENSITY_NAME = "screenDensity"; const char * const DeviceModule::DEVICE_SCREEN_SHAPE = "screenShape"; const uint32_t DeviceModule::DEVICE_SCREEN_DENSITY = 326; -const uint8_t DeviceModule::DEVICE_API_VERSION = 4; const char * const DeviceModule::DEVICE_TYPE = "deviceType"; const char * const DeviceModule::DEVICE_API_VERSION_NAME = "apiVersion"; - +const char * const DeviceModule::DEVICE_MACADDRESS = "macAddress"; bool DeviceModule::GetBrand(JSIValue result) { bool ret = true; const char *brand = DEVICE_BRAND; @@ -121,6 +121,19 @@ bool DeviceModule::GetRegion(JSIValue result) return ret; } +bool DeviceModule::GetMac(JSIValue result) +{ + int ret = true; + char macAddress[18]; + ret = GetMacAddress(macAddress, sizeof(macAddress)); + if (ret != 0) { + return false; + } else { + JSI::SetStringProperty(result, DEVICE_MACADDRESS, macAddress); + } + return true; +} + bool DeviceModule::GetScreenInfo(JSIValue result) { Screen &screen = Screen::GetInstance(); @@ -152,7 +165,7 @@ bool DeviceModule::GetDeviceType(JSIValue result) bool DeviceModule::GetApiVersion(JSIValue result) { bool ret = true; - uint8_t apiVersion = DEVICE_API_VERSION; + uint8_t apiVersion = GetSdkApiVersion(); JSI::SetNumberProperty(result, DEVICE_API_VERSION_NAME, apiVersion); return ret; } @@ -191,7 +204,7 @@ void DeviceModule::ExecuteGetDeviceInfo(void* data) if (GetBrand(result) && GetManufacturer(result) && GetModel(result) && GetProduct(result) && GetLanguage(result) && GetRegion(result) && GetScreenInfo(result) && - GetApiVersion(result) && GetDeviceType(result)) + GetApiVersion(result) && GetDeviceType(result) && GetMac(result)) { SuccessCallBack(thisVal, args, result); } else { diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.h index 775edc074..7e31afc8c 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/device_module.h @@ -43,12 +43,12 @@ public: static const char * const DEVICE_PRODUCT; static const char * const DEVICE_LANGUAGE; static const char * const DEVICE_REGION; + static const char * const DEVICE_MACADDRESS; static const char * const DEVICE_WINDOW_WIDTH_NAME; static const char * const DEVICE_WINDOW_HEIGHT_NAME; static const char * const DEVICE_SCREEN_DENSITY_NAME; static const char * const DEVICE_SCREEN_SHAPE; static const uint32_t DEVICE_SCREEN_DENSITY; - static const uint8_t DEVICE_API_VERSION; static const char * const DEVICE_TYPE; static const char * const DEVICE_API_VERSION_NAME; static JSIValue GetInfo(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); @@ -61,6 +61,7 @@ public: static bool GetScreenInfo(JSIValue result); static bool GetDeviceType(JSIValue result); static bool GetApiVersion(JSIValue result); + static bool GetMac(JSIValue result); static const char* translateText(char* input); private: diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/geolocation_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/geolocation_module.cpp index ff0369afc..ae517f878 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/geolocation_module.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/geolocation_module.cpp @@ -20,7 +20,6 @@ #include "product_adapter.h" #include #include "geolocation_module.h" -#include "media_log.h" #include "global.h" namespace OHOS { @@ -57,6 +56,7 @@ static CoordTypeMap g_coordTypeMap[] = { JSIValue LocationModule::GetSupportCoordTypes(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { +#if defined(ENABLE_LOCATION) std::vector coordinateSystemTypes; LocationErrCode errCode = Locator::GetInstance().QuerySupportCoordinateSystemType(coordinateSystemTypes); if (errCode != ERRCODE_SUCCESS) { @@ -77,27 +77,48 @@ JSIValue LocationModule::GetSupportCoordTypes(const JSIValue thisVal, const JSIV } } return rltArray; +#else + HILOG_INFO(HILOG_MODULE_ACE, "not support!"); + return JSI::CreateUndefined(); +#endif } JSIValue LocationModule::Unsubscribe(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { +#if defined(ENABLE_LOCATION) ExecuteUnsubscribe(); +#endif return JSI::CreateUndefined(); } JSIValue LocationModule::Subscribe(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { +#if defined(ENABLE_LOCATION) return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribe); +#else + HILOG_INFO(HILOG_MODULE_ACE, "not support!"); + return JSI::CreateUndefined(); +#endif } JSIValue LocationModule::GetLocationType(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { +#if defined(ENABLE_LOCATION) return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetLocationType); +#else + HILOG_INFO(HILOG_MODULE_ACE, "not support!"); + return JSI::CreateUndefined(); +#endif } JSIValue LocationModule::GetLocation(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { +#if defined(ENABLE_LOCATION) return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetLocation); +#else + HILOG_INFO(HILOG_MODULE_ACE, "not support!"); + return JSI::CreateUndefined(); +#endif } JSIValue LocationModule::ExecuteAsyncWork( diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/http_errcode.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/http_errcode.h new file mode 100644 index 000000000..ce683ec8d --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/http_errcode.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 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_ERRCODE_H +#define NET_ERRCODE_H + +/** @brief http requst type */ +typedef enum { + NET_SUCCESS = 200, + NET_PARAMETER_ERROR = 401, + NET_PERMISSION_DENIED = 201, + NET_UNSUPPORTED_PROTOCOL = 2300001, + NET_BAD_URL_FORMAT = 2300003, + NET_PROXY_RESOLVE_ERROR = 2300005, + NET_HOST_RESOLVE_ERROR = 2300006, + NET_SERVER_CONNECT_ERROR = 2300007, + NET_WEIRD_SERVER_REPLY = 2300008, + NET_REMOTE_ACCESS_DENIED = 2300009, + NET_HTTP2_FRAME_ERROR = 2300016, + NET_PARTIAL_FILE = 2300018, + NET_WRITE_DATA_ERROR = 2300023, + NET_UPLOAD_FAILED = 2300025, + NET_OPEN_FILE_ERROR = 2300026, + NET_OUT_OF_MEMORY = 2300027, + NET_TIMEOUT_REACHED = 2300028, + NET_MAX_REDIRECTS = 2300047, + NET_SERVER_NO_RESPONSE = 2300052, + NET_SEND_DATA_ERROR = 2300055, + NET_RECEIVE_DATA_ERROR = 2300056, + NET_LOCAL_SSL_ERROR = 2300058, + NET_SSL_CIPHER_ERROR = 2300059, + NET_SSL_PEER_ERROR = 2300060, + NET_BAD_CONTENT_ENCODING = 2300061, + NET_FILE_SIZE_EXCEEDED = 2300063, + NET_DISK_FULL = 2300070, + NET_REMOTE_FILE_EXISTS = 2300073, + NET_SSL_CA_ERROR = 2300077, + NET_REMOTE_FILE_NOT_FOUND = 2300078, + NET_AUTH_FUNCTION_ERROR = 2300094, + NET_UNKNOWN_ERROR = 2300999, +} HTTP_ERRCODE; + + +#endif /* HTTPCLIENT_H */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/nativeapi_ohos_deviceinfo.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/nativeapi_ohos_deviceinfo.cpp new file mode 100644 index 000000000..d76269111 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/nativeapi_ohos_deviceinfo.cpp @@ -0,0 +1,443 @@ +/* + * Copyright (c) 2020 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. + */ + +#include +#include +#include "global.h" +#include "parameter.h" +// #include "sysversion.h" +#include "ace_log.h" +#include "js_app_context.h" +#include "js_async_work.h" +#include "jsi.h" +static constexpr int MAX_BUFFER = 65; +namespace OHOS { +namespace ACELite { + +JSIValue JSGetDeviceType(void) +{ + const char *value = GetDeviceType(); + if (value == nullptr) { + value = ""; + } + + JSIValue deviceType = JSI::CreateString(value); + return deviceType; +} + +JSIValue JSGetManufacture(void) +{ + const char *value = GetManufacture(); + if (value == nullptr) { + value = ""; + } + + JSIValue manfactureName = JSI::CreateString(value); + return manfactureName; +} + +JSIValue JSGetBrand(void) +{ + const char *value = GetBrand(); + if (value == nullptr) { + value = ""; + } + + JSIValue productBrand = JSI::CreateString(value); + return productBrand; +} + +JSIValue JSGetMarketName(void) +{ + const char *value = GetMarketName(); + if (value == nullptr) { + value = ""; + } + + JSIValue marketName = JSI::CreateString(value); + return marketName; +} + +JSIValue JSGetProductSeries(void) +{ + const char *value = GetProductSeries(); + if (value == nullptr) { + value = ""; + } + + JSIValue productSeries = JSI::CreateString(value); + return productSeries; +} + +JSIValue JSGetProductModel(void) +{ + const char *value = GetProductModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue productModel = JSI::CreateString(value); + return productModel; +} + +JSIValue JSGetSoftwareModel(void) +{ + const char *value = GetSoftwareModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue softwareModel = JSI::CreateString(value); + return softwareModel; +} + +JSIValue JSGetHardwareModel(void) +{ + const char *value = GetHardwareModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue hardwareModel = JSI::CreateString(value); + return hardwareModel; +} + +JSIValue JSGetHardwareProfile(void) +{ + const char *value = GetHardwareProfile(); + if (value == nullptr) { + value = ""; + } + + JSIValue hardwareProfile = JSI::CreateString(value); + return hardwareProfile; +} + +JSIValue JSGetSerial(void) +{ + const char *value = GetSerial(); + if (value == nullptr) { + value = ""; + } + + JSIValue serialNumber = JSI::CreateString(value); + return serialNumber; +} + +JSIValue JSGetBootloaderVersion(void) +{ + const char *value = GetBootloaderVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue bootloaderVersion = JSI::CreateString(value); + return bootloaderVersion; +} + +JSIValue JSGetAbiList(void) +{ + const char *value = GetAbiList(); + if (value == nullptr) { + value = ""; + } + + JSIValue abiList = JSI::CreateString(value); + return abiList; +} + +JSIValue JSGetSecurityPatchTag(void) +{ + const char *value = GetSecurityPatchTag(); + if (value == nullptr) { + value = ""; + } + + JSIValue securityPatchTag = JSI::CreateString(value); + return securityPatchTag; +} + +JSIValue JSGetDisplayVersion(void) +{ + const char *value = GetDisplayVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue productVersion = JSI::CreateString(value); + return productVersion; +} + +JSIValue JSGetIncrementalVersion(void) +{ + const char *value = GetIncrementalVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue incrementalVersion = JSI::CreateString(value); + return incrementalVersion; +} + +JSIValue JSGetOsReleaseType(void) +{ + const char *value = GetOsReleaseType(); + if (value == nullptr) { + value = ""; + } + + JSIValue osReleaseType = JSI::CreateString(value); + return osReleaseType; +} + +JSIValue JSGetOSFullName(void) +{ + const char *value = GetOSFullName(); + if (value == nullptr) { + value = ""; + } + JSIValue osVersion = JSI::CreateString(value); + return osVersion; +} + +JSIValue JSGetMajorVersion(void) +{ + int value = GetMajorVersion(); + JSIValue majorVersion = JSI::CreateUndefined(); + if (value < 0) { + return majorVersion; + } + + majorVersion = JSI::CreateString(std::to_string(value).c_str()); + return majorVersion; +} + +JSIValue JSGetSeniorVersion(void) +{ + int value = GetSeniorVersion(); + JSIValue seniorVersion = JSI::CreateUndefined(); + if (value < 0) { + return seniorVersion; + } + + seniorVersion = JSI::CreateString(std::to_string(value).c_str()); + return seniorVersion; +} + +JSIValue JSGetFeatureVersion(void) +{ + int value = GetFeatureVersion(); + JSIValue featureVersion = JSI::CreateUndefined(); + if (value < 0) { + return featureVersion; + } + + featureVersion = JSI::CreateString(std::to_string(value).c_str()); + return featureVersion; +} + +JSIValue JSGetBuildVersion(void) +{ + int value = GetBuildVersion(); + JSIValue buildVersion = JSI::CreateUndefined(); + if (value < 0) { + return buildVersion; + } + + buildVersion = JSI::CreateString(std::to_string(value).c_str()); + return buildVersion; +} + +JSIValue JSGetSdkApiVersion(void) +{ + int value = GetSdkApiVersion(); + JSIValue sdkApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return sdkApiVersion; + } + + sdkApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return sdkApiVersion; +} + +JSIValue JSGetFirstApiVersion(void) +{ + int value = GetFirstApiVersion(); + JSIValue firstApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return firstApiVersion; + } + + firstApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return firstApiVersion; +} + +JSIValue JSGetVersionId(void) +{ + const char *value = GetVersionId(); + if (value == nullptr) { + value = ""; + } + + JSIValue versionId = JSI::CreateString(value); + return versionId; +} + +JSIValue JSGetBuildType(void) +{ + const char *value = GetBuildType(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildType = JSI::CreateString(value); + return buildType; +} + +JSIValue JSGetBuildUser(void) +{ + const char *value = GetBuildUser(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildUser = JSI::CreateString(value); + return buildUser; +} + +JSIValue JSGetBuildHost(void) +{ + const char *value = GetBuildHost(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildHost = JSI::CreateString(value); + return buildHost; +} + +JSIValue JSGetBuildTime(void) +{ + const char *value = GetBuildTime(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildTime = JSI::CreateString(value); + return buildTime; +} + +JSIValue JSGetBuildRootHash(void) +{ + const char *value = GetBuildRootHash(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildRootHash = JSI::CreateString(value); + return buildRootHash; +} + +JSIValue JSGetDevUdid(void) +{ + char udid[MAX_BUFFER] = { 0 }; + int ret = GetDevUdid(udid, sizeof(udid)); + if (ret < 0) { + return JSI::CreateUndefined(); + } + return JSI::CreateString(udid); +} + +JSIValue JSGetDistributionOSName(void) +{ + const char *value = GetDistributionOSName(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSName = JSI::CreateString(value); + return distributionOSName; +} + +JSIValue JSGetDistributionOSVersion(void) +{ + const char *value = GetDistributionOSVersion(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSVersion = JSI::CreateString(value); + return distributionOSVersion; +} + +JSIValue JSGetDistributionOSApiVersion(void) +{ + int value = GetDistributionOSApiVersion(); + JSIValue distributionOSApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return distributionOSApiVersion; + } + + distributionOSApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return distributionOSApiVersion; +} + +JSIValue JSGetDistributionOSReleaseType(void) +{ + const char *value = GetDistributionOSReleaseType(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSReleaseType = JSI::CreateString(value); + return distributionOSReleaseType; +} + +void InitDeviceInfoModule(JSIValue exports) +{ + JSI::SetNamedProperty(exports, "deviceType", JSGetDeviceType()); + JSI::SetNamedProperty(exports, "manufacture", JSGetManufacture()); + JSI::SetNamedProperty(exports, "brand", JSGetBrand()); + JSI::SetNamedProperty(exports, "marketName", JSGetMarketName()); + JSI::SetNamedProperty(exports, "productSeries", JSGetProductSeries()); + JSI::SetNamedProperty(exports, "productModel", JSGetProductModel()); + JSI::SetNamedProperty(exports, "softwareModel", JSGetSoftwareModel()); + JSI::SetNamedProperty(exports, "hardwareModel", JSGetHardwareModel()); + JSI::SetNamedProperty(exports, "hardwareProfile", JSGetHardwareProfile()); + JSI::SetNamedProperty(exports, "serial", JSGetSerial()); + JSI::SetNamedProperty(exports, "bootloaderVersion", JSGetBootloaderVersion()); + JSI::SetNamedProperty(exports, "abiList", JSGetAbiList()); + JSI::SetNamedProperty(exports, "securityPatchTag", JSGetSecurityPatchTag()); + JSI::SetNamedProperty(exports, "displayVersion", JSGetDisplayVersion()); + JSI::SetNamedProperty(exports, "incrementalVersion", JSGetIncrementalVersion()); + JSI::SetNamedProperty(exports, "osReleaseType", JSGetOsReleaseType()); + JSI::SetNamedProperty(exports, "osFullName", JSGetOSFullName()); + JSI::SetNamedProperty(exports, "majorVersion", JSGetMajorVersion()); + JSI::SetNamedProperty(exports, "seniorVersion", JSGetSeniorVersion()); + JSI::SetNamedProperty(exports, "featureVersion", JSGetFeatureVersion()); + JSI::SetNamedProperty(exports, "buildVersion", JSGetBuildVersion()); + JSI::SetNamedProperty(exports, "sdkApiVersion", JSGetSdkApiVersion()); + JSI::SetNamedProperty(exports, "firstApiVersion", JSGetFirstApiVersion()); + JSI::SetNamedProperty(exports, "versionId", JSGetVersionId()); + JSI::SetNamedProperty(exports, "buildType", JSGetBuildType()); + JSI::SetNamedProperty(exports, "buildUser", JSGetBuildUser()); + JSI::SetNamedProperty(exports, "buildHost", JSGetBuildHost()); + JSI::SetNamedProperty(exports, "buildTime", JSGetBuildTime()); + JSI::SetNamedProperty(exports, "buildRootHash", JSGetBuildRootHash()); + JSI::SetNamedProperty(exports, "udid", JSGetDevUdid()); + JSI::SetNamedProperty(exports, "distributionOSName", JSGetDistributionOSName()); + JSI::SetNamedProperty(exports, "distributionOSVersion", JSGetDistributionOSVersion()); + JSI::SetNamedProperty(exports, "distributionOSApiVersion", JSGetDistributionOSApiVersion()); + JSI::SetNamedProperty(exports, "distributionOSReleaseType", JSGetDistributionOSReleaseType()); +} +} // ACELite +} // OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/net/http_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/net/http_module.h new file mode 100644 index 000000000..feeba8f73 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/net/http_module.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) CompanyNameMagicTag. 2024-2025. All rights reserved. + * Description: http control interfaces + * Author: Software Group + * Create: 2025-03-28 + */ + +#ifndef HTTP_CLIENT_MODULE_H +#define HTTP_CLIENT_MODULE_H + +#include +#include "jsi.h" +#include +#include +#include "httpclient.h" + +namespace OHOS { +namespace ACELite { + +struct EventCallback { + JSIValue callback; + JSIValue context; + bool isOnce; +}; + +struct ThreadNewObj { + JSIValue thisVal; + HttpClient *newHttpClient; + HttpClientData *newHttpClientData; + char *method; + char *url; + JSIValue header; + JSIValue callback; +}; + +// httpClient +constexpr char METHOD[] = "method"; +constexpr char HTTP_CLIENT[] = "httpClient"; +constexpr char URL[] = "url"; +constexpr char HEADER[] = "header"; +constexpr char CLIENT_CERT[] = "clientCert"; + +// httpClientData +constexpr char HTTP_CLIENT_DATA[] = "httpClientData"; +constexpr char POST_BUF[] = "postBuf"; +constexpr char EXTRA_DATA[] = "extraData"; + +// subscriptions +char* DATA_RECEIVE = "dataReceive"; +char* DATA_END = "dataEnd"; +char* DATA_RECEIVE_PROGRESS = "dataReceiveProgress"; +char* DATA_SEND_PROGRESS = "dataSendProgress"; + +class HttpModule final : public MemoryHeap { +public: + HttpModule() = default; + ~HttpModule() = default; + static HttpClient *CreateHttpClient(const JSIValue *args); + static HttpClientData *CreateHttpClientData(const JSIValue *args); + static char *HeaderJsonToString(char* headerJson); + static JSIValue Request(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue RequestInStream(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue CreateHttp(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Once(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Destroy(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static std::map eventCallbacks; + static std::map httpClientInstances; + static std::map httpClientDataInstances; + static void OnTerminate(); + static void CheckSubscription(char *type, JSIValue value); + static int GetErrorCode(int8_t errorCode); +}; +void InitHttpModule(JSIValue exports); + +} // namespace ACELite +} // namespace OHOS + +#endif // HTTP_CLIENT_MODULE_H \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/include/httpclient.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/include/httpclient.h new file mode 100644 index 000000000..9a4712ade --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/include/httpclient.h @@ -0,0 +1,218 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef HTTPCLIENT_H +#define HTTPCLIENT_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief http requst type */ +typedef enum { + HTTP_DELETE, + HTTP_GET, + HTTP_HEAD, + HTTP_POST, + HTTP_PUT +} HTTP_REQUEST_TYPE; + +/** @brief http error code */ +typedef enum { + HTTP_EAGAIN = 1, /**< more data to retrieved */ + HTTP_SUCCESS = 0, /**< operation success */ + HTTP_ENOBUFS = -1, /**< buffer error */ + HTTP_EARG = -2, /**< illegal argument */ + HTTP_ENOTSUPP = -3, /**< not support */ + HTTP_EDNS = -4, /**< DNS fail */ + HTTP_ECONN = -5, /**< connect fail */ + HTTP_ESEND = -6, /**< send packet fail */ + HTTP_ECLSD = -7, /**< connect closed */ + HTTP_ERECV = -8, /**< recv packet fail */ + HTTP_EPARSE = -9, /**< url parse error */ + HTTP_EPROTO = -10, /**< protocol error */ + HTTP_EUNKOWN = -11, /**< unknown error */ + HTTP_ETIMEOUT = -12, /**< timeout */ +} HTTPC_RESULT; + +/** @brief This structure defines the HttpClient structure */ +typedef struct { + int socket; /**< socket ID */ + int remotePort; /**< hTTP or HTTPS port */ + int responseCode; /**< response code */ + char *header; /**< request custom header */ + char *authUser; /**< username for basic authentication */ + char *authPassword; /**< password for basic authentication */ + bool isHttp; /**< http connection? if 1, http; if 0, https */ +#if CONFIG_HTTP_SECURE + const char *serverCert; /**< server certification */ + const char *clientCert; /**< client certification */ + const char *clientPk; /**< client private key */ + int serverCertLen; /**< server certification lenght, server_cert buffer size */ + int clientCertLen; /**< client certification lenght, client_cert buffer size */ + int clientPkLen; /**< client private key lenght, client_pk buffer size */ + void *ssl; /**< ssl content */ +#endif +} HttpClient; + +/** @brief This structure defines the HTTP data structure. */ +typedef struct { + bool isMore; /**< indicates if more data needs to be retrieved. */ + bool isChunked; /**< response data is encoded in portions/chunks.*/ + int method; /**< http method. */ + int retrieveLen; /**< content length to be retrieved. */ + int responseContentLen; /**< response content total length. */ + int contentBlockLen; /**< the content length of one block. */ + int postBufLen; /**< post data length. */ + int responseBufLen; /**< response body buffer length. */ + int headerBufLen; /**< response head buffer lehgth. */ + char *postContentType; /**< content type of the post data. */ + char *postBuf; /**< user data to be posted. */ + char *responseBuf; /**< buffer to store the response body data. */ + char *headerBuf; /**< buffer to store the response head data. */ + bool isRedirected; /**< redirected URL? if 1, has redirect url; if 0, no redirect url */ + char *redirectUrl; /**< redirect url when got http 3** response code. */ +} HttpClientData; + +/** + * This function executes a GET request on a given URL. It blocks until completion. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] url url is the URL to run the request. + * @param[in, out] clientData clientData is a pointer to the #HttpClientData instance to collect the data + * returned by the request. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientGetRequest(HttpClient *client, const char *url, HttpClientData *clientData); + +/** + * This function executes a HEAD request on a given URL. It blocks until completion. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] url url is the URL to run the request. + * @param[in, out] clientData clientData is a pointer to the #HttpClientData instance to collect the data + * returned by the request. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientHeadRequest(HttpClient *client, const char *url, HttpClientData *clientData); + +/** + * This function executes a POST request on a given URL. It blocks until completion. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] url url is the URL to run the request. + * @param[in, out] clientData clientData is a pointer to the #HttpClientData instance to collect the data + * returned by the request. It also contains the data to be posted. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientPostRequest(HttpClient *client, const char *url, HttpClientData *clientData); + +/** + * This function executes a PUT request on a given URL. It blocks until completion. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] url url is the URL to run the request. + * @param[in, out] clientData clientData is a pointer to the #HttpClientData instance to collect the data + * returned by the request. It also contains the data to be put. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientPutRequest(HttpClient *client, const char *url, HttpClientData *clientData); + +/** + * This function executes a DELETE request on a given URL. It blocks until completion. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] url url is the URL to run the request. + * @param[in, out] clientData clientData is a pointer to the #HttpClientData instance to collect the data returned + * by the request. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientDelete(HttpClient *client, const char *url, HttpClientData *clientData); + +/** + * This function allocates buffer for http header/response + * @param[in] clientData pointer to the #HttpClientData. + * @param[in] headerSize header buffer size + * @param[in] respSize response buffer size + * @return HTTP_SUCCESS success + * @return HTTP_EUNKOWN fail + */ +HTTPC_RESULT HttpClientPrepare(HttpClientData *clientData, int headerSize, int respSize); + +/** + * This function deallocates buffer for http header/response. + * @param[in] clientData pointer to the #HttpClientData. + * @return HTTP_SUCCESS success + * @return HTTP_EUNKOWN fail + */ +HTTPC_RESULT HttpClientUnprepare(HttpClientData *clientData); + +/** + * This function reset buffer for http header/response. + * @param[in] clientData pointer to the #HttpClientData. + * @return None. + */ +void HttpClientReset(HttpClientData *clientData); + +/** + * This function establish http/https connection. + * @param[in] client pointer to the #HttpClient. + * @param[in] url remote URL + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientConn(HttpClient *client, const char *url); + +/** + * This function sends HTTP request. + * @param[in] client a pointer to the #HttpClient. + * @param[in] url remote URL + * @param[in] method http request method + * @param[in] clientData a pointer to #HttpClientData. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientSend(HttpClient *client, const char *url, int method, HttpClientData *clientData); + +/** + * This function receives response from remote + * @param[in] client a pointer to #HttpClient. + * @param[out] clientData a pointer to #HttpClientData. + * @return Please refer to #HTTPC_RESULT. + */ +HTTPC_RESULT HttpClientRecvResponse(HttpClient *client, HttpClientData *clientData); + +/** + * This function close http connection. + * @param[in] client client is a pointer to the #HttpClient. + * @return None. + */ +void HttpClientClse(HttpClient *client); + +/** + * This function sets a custom header. + * @param[in] client client is a pointer to the #HttpClient. + * @param[in] header header is a custom header string. + * @return None. + */ +void HttpClientSetCustomHeader(HttpClient *client, char *header); + +/** + * This function gets the HTTP response code assigned to the last request. + * @param[in] client client is a pointer to the #HttpClient. + * @return The HTTP response code of the last request. + */ +int HttpClientGetResponseCode(HttpClient *client); + +/** + * This function get specified response header value. + * @param[in] header_buf header_buf is the response header buffer. + * @param[in] name name is the specified http response header name. + * @param[in, out] val_pos val_pos is the position of header value in header_buf. + * @param[in, out] val_len val_len is header value length. + * @return 0, if value is got. Others, if errors occurred. + */ +int HttpClientGetResponseHeaderValue(char *headerBuf, char *name, int *valPos, int *valLen); + +#ifdef __cplusplus +} +#endif + +#endif /* HTTPCLIENT_H */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_opts.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_opts.h new file mode 100644 index 000000000..9b00983d8 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_opts.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef HTTP_OPTS_H +#define HTTP_OPTS_H + +#ifndef HTTPCLIENT_AUTHB_SIZE +#define HTTPCLIENT_AUTHB_SIZE 128 +#endif + +#ifndef HTTPCLIENT_CHUNK_SIZE +#define HTTPCLIENT_CHUNK_SIZE (2048) // 1024 +#endif + +#ifndef HTTPCLIENT_SEND_BUF_SIZE +#define HTTPCLIENT_SEND_BUF_SIZE 2048 // 512 +#endif + +#ifndef HTTPCLIENT_MAX_HOST_LEN +#define HTTPCLIENT_MAX_HOST_LEN 128 +#endif + +#ifndef HTTPCLIENT_MAX_URL_LEN +#define HTTPCLIENT_MAX_URL_LEN 1024 // 512 +#endif + +#ifndef HTTPCLIENT_MAX_RECV_WAIT_MS +#define HTTPCLIENT_MAX_RECV_WAIT_MS 5000 +#endif + +#ifndef HTTP_PORT +#define HTTP_PORT 80 +#endif + +#ifndef HTTPS_PORT +#define HTTPS_PORT 443 +#endif + +#endif /* HTTP_OPTS_H */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_wrappers.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_wrappers.h new file mode 100644 index 000000000..21295992c --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/http/internal/http_wrappers.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef HTTP_CLIENT_WRAPPER_H +#define HTTP_CLIENT_WRAPPER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define http_info printf +#define http_err printf +#define http_debug + +#ifndef HTTP_MIN +#define HTTP_MIN(x,y) (((x)<(y))?(x):(y)) +#endif +#ifndef HTTP_MAX +#define HTTP_MAX(x,y) (((x)>(y))?(x):(y)) +#endif + +int HttpTcpConnWrapper(HttpClient *client, const char *host); +int HttpTcpCloseWrapper(HttpClient *client); +int HttpTcpSendWrapper(HttpClient *client, const char *data, int length); +int HttpTcpRecvWrapper(HttpClient *client, char *buf, int buflen, int timeout_ms, int *p_read_len); + +#if CONFIG_HTTP_SECURE +int HttpSslConnWrapper(HttpClient *client, const char *host); +int HttpSslCloseWrapper(HttpClient *client); +int HttpSslSendWrapper(HttpClient *client, const char *data, size_t length); +int HttpSslRecvWrapper(HttpClient *client, char *buf, int buflen, int timeout_ms, int *p_read_len); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HTTP_CLIENT_WRAPPER_H */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket.h new file mode 100644 index 000000000..ef9fdf3e9 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef NET_WEBSOCKET_H +#define NET_WEBSOCKET_H + +#include +#include +#include "net_websocket_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @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 client fd >= 0 if success; -1 otherwise + */ +int WebSocketClientConstructor(WebSocketOnOpenCallback onOpen, WebSocketOnMessageCallback onMessage, + WebSocketOnErrorCallback onError, WebSocketOnCloseCallback onclose); + +void WebSocketClientSetProtocol(int client, const char *protocol); + +#ifdef WEBSOCKET_SSL_ENABLE +/** + * @brief Set server certificate for ssl connection. + * @param client client fd. + * @param serverCert Server certificate. + * @param serverCertLen The length of the server certificate caculated by sizeof + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. + */ +int WebSocketClientSetServerCert(int client, const char *serverCert, int serverCertLen); +#endif + +/** + * @brief Connects the client to the server. + * + * @param client client fd. + * @param url URL for the client to connect to the server. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. + */ +int WebSocketClientConnect(int client, const char *url); + +/** + * @brief Sends data from the client to the server. + * + * @param client Client fd. + * @param text Text string sent by the client. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. + */ +int WebSocketClientSendText(int client, const char *text, size_t length); + +/** + * @brief Send bin header to connect socket. + * @detailed Thread safe method. + * @param client client fd. + * @param data header data for sending. + * @param length length of header. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. + */ +int WebSocketClientSendBinStart(int client, const char *data, size_t length); + +/** + @brief Send bin content to connect socket. + @detailed Thread safe method. + @param client Socket object. + @param data content for sending. + @param len length of binary content. + @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. +*/ +int WebSocketClientSendBinContinue(int client, const char *data, size_t length); + +/** + @brief Send final bin to connect socket. + @detailed Thread safe method. + @param client Socket object. + @param data bin string for sending. + @param length length of final. + @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. +*/ +int WebSocketClientSendBinEnd(int client, const char *data, size_t length); + +/** + * @brief Closes a WebSocket connection. + * + * @param client Client fd. + * @return 0 if success; non-0 otherwise. For details about error codes, see {@link WebsocketErrCode}. + */ +int WebSocketClientClose(int client); + +/** + @brief Check is client has connection to host and handshake(sucessfully done). + @detailed Thread safe getter. + @param client Client fd. + @return trw_true - connected to host and handshacked, otherwice false. + */ +bool WebSocketClientIsConnected(int client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h new file mode 100644 index 000000000..00c99b6cc --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_debug.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef __NET_WEBSOCKET_DEBUG_H__ +#define __NET_WEBSOCKET_DEBUG_H__ + +#include + +#define WS_DBG_LEVEL WEBSOCKET_DBG_ON + +#define WS_INFO_LEVEL WEBSOCKET_DBG_ON + +#define WS_ERR_LEVEL WEBSOCKET_DBG_ON + +/** flag for WEBSOCKET_DEBUGF to enable that debug message */ +#define WEBSOCKET_DBG_ON 0x80U +/** flag for WEBSOCKET_DEBUGF to disable that debug message */ +#define WEBSOCKET_DBG_OFF 0x00U + +#define WEBSOCKET_DEBUG + +#ifdef WEBSOCKET_DEBUG +#define WS_PLATFORM_DIAG(x) \ + do { \ + printf x; \ + } while (0) +#define WEBSOCKET_DEBUGF(debug, message) \ + do { \ + if (((debug)&WEBSOCKET_DBG_ON)) { \ + WS_PLATFORM_DIAG(message); \ + } \ + } while (0) + +#else /* WEBSOCKET_DEBUG */ +#define WEBSOCKET_DEBUGF(debug, message) +#endif /* WEBSOCKET_DEBUG */ + +#endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h new file mode 100644 index 000000000..1112cedc9 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_frame.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef _WS_FRAME_H__ +#define _WS_FRAME_H__ + +#include "net_websocket.h" +#include + +typedef enum _rws_opcode { + WS_OPCODE_CONTINUATION = 0x0, // %x0 denotes a continuation frame + WS_OPCODE_TEXT_FRAME = 0x1, // %x1 denotes a text frame + WS_OPCODE_BINARY_FRAME = 0x2, // %x2 denotes a binary frame + WS_OPCODE_CONNECTION_CLOSE = 0x8, // %x8 denotes a connection close + WS_OPCODE_PING = 0x9, // %x9 denotes a ping + WS_OPCODE_PONG = 0xA // %xA denotes a pong +} WsOpcode; + +typedef enum WsBinaryCode { WS_BINARY_START, WS_BINARY_CONTINUE, WS_BINARY_END } WsBinary; + +typedef struct WsFrameStruct { + void *data; + size_t length; + WsOpcode opcode; + uint8_t mask[4]; /* 4: mask length */ + bool isMasked; + bool isFinished; + uint8_t headerSize; +} WsFrame; + +size_t WsCheckRecvFrameSize(const void *data, const size_t data_size); + +WsFrame *WsFrameCreateWithRecvData(const void *data, const size_t data_size); + +void WsFrameFillWithSendBinData(WsFrame *f, const void *data, const size_t length, WsBinary binType); + +// data - should be null, and setted by newly created. 'data' & 'data_size' can be null +void WsFrameFillWithSendData(WsFrame *f, const void *data, const size_t data_size, bool is_finish); + +// combine datas of 2 frames. combined is 'to' +void WsFrameCombineDatas(WsFrame *to, WsFrame *from); + +WsFrame *WsFrameCreate(void); + +void WsDeleteFrame(WsFrame *f); + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h new file mode 100644 index 000000000..1a34ddc37 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_list.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef __WS_LIST_H__ +#define __WS_LIST_H__ + +#include + +typedef union WsNodeValueUnion { + void *object; + char *string; +} WsNodeValue; + +typedef struct WsNodeStruct { + WsNodeValue value; + struct WsNodeStruct *next; +} WsNode, WsList; + +WsList *WsListCreate(void); + +void WsListDelete(WsList *list); + +void WsListDeleteClean(WsList **list); + +int WsListAppend(WsList *list, WsNodeValue value); + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h new file mode 100644 index 000000000..70d7d5d35 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_opts.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef NET_WEBSOCKET_OPTS_H +#define NET_WEBSOCKET_OPTS_H + +#define WEBSOCKET_RECV_BUFF_SIZE (20 * 1024) + +#define WS_MAX_THRESH_VAL (20 * 1024) /* common TTS play size */ + +#define WS_MAX_CLIENT_NUM 4 + +#define WS_MAX_URI_LENGTH 256 + +#define WS_MAX_DATA_LENGTH (20 * 1024) + +#define WS_HANDSHAKE_BUF_LEN 512 + +#define WSS_READ_TIMEOUT_MS 100 + + +#endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h new file mode 100644 index 000000000..2159d7b66 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_priv.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef __NET_WEBSOCKET_PRIV_H__ +#define __NET_WEBSOCKET_PRIV_H__ + +#include "lwip/sockets.h" +#include +#include +#include + +#include "net_websocket.h" +#include "net_websocket_type.h" +#include "net_websocket_opts.h" +#include "net_websocket_thread.h" +#include "net_websocket_frame.h" +#include "net_websocket_list.h" + +#ifdef WEBSOCKET_SSL_ENABLE +#include "mbedtls/net_sockets.h" +#include "mbedtls/ssl.h" +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" +#endif + +typedef int WsSocket; +#define WS_INVALID_SOCKET -1 +#define WS_SOCK_CLOSE(sock) closesocket(sock) + +#define O_NONBLOCK 04000 + +#ifdef WEBSOCKET_SSL_ENABLE +typedef struct WsSslStruct { + mbedtls_ssl_context sslCtx; /* mbedtls ssl context */ + mbedtls_net_context netCtx; /* Fill in socket id */ + mbedtls_ssl_config sslConf; /* SSL configuration */ + mbedtls_entropy_context entropy; + mbedtls_ctr_drbg_context ctrDrbg; + mbedtls_x509_crt_profile profile; + mbedtls_x509_crt cacert; + mbedtls_x509_crt clicert; + mbedtls_pk_context pkey; +} WsSsl; +#endif + +struct WebSocketClient { + int clientfd; + int port; + WsSocket socket; + char scheme[WS_MAX_URI_LENGTH]; + char host[WS_MAX_URI_LENGTH]; + char path[WS_MAX_URI_LENGTH]; + + char *secWsProtocol; // "Sec-WebSocket-Protocol" field + char *secWsAccept; // "Sec-WebSocket-Accept" field from handshake + + WsThread workThread; + + int command; + + bool isConnected; // sock connected + handshake done + + void *userObject; + /** Pointer to the callback invoked when a connection message is received */ + WebSocketOnOpenCallback onOpen; + /** Pointer to the callback invoked when a message is received */ + WebSocketOnMessageCallback onMessage; + /** Pointer to the callback invoked when an error message is received */ + WebSocketOnErrorCallback onError; + /** Pointer to the callback invoked when a close message is received */ + WebSocketOnCloseCallback onClose; + + void *received; + size_t receivedSize; // size of 'received' memory + size_t receivedLen; // length of actualy readed message + + WsList *sendFrames; + WsList *recvdFrames; + + WsMutex workMutex; + WsMutex sendMutex; + WsSem exitSem; + +#ifdef WEBSOCKET_SSL_ENABLE + const char *serverCert; /**< Server certification. */ + const char *clientCert; /**< Client certification. */ + const char *clientPk; /**< Client private key. */ + int serverCertLen; /**< Server certification lenght, server_cert buffer size. */ + int clientCertLen; /**< Client certification lenght, client_cert buffer size. */ + int clientPkLen; /**< Client private key lenght, client_pk buffer size. */ + WsSsl *ssl; /**< Ssl content. */ +#endif + char *recvBuffer; + int recvBufferSize; +}; + +void WebSocketClientClosePriv(struct WebSocketClient *clientPtr); + +struct WebSocketClient *WsGetClient(int fd); + +int AllocWsClient(void); + +bool WsParseUrl(const char *url, char *prefix, char *address, char *path, int *port); + +int WsSocketSendTextPriv(struct WebSocketClient *clientPtr, const char *text); + +int WsClientSendBinStartPriv(struct WebSocketClient *clientPtr, const char *data, size_t length); + +int WsClientIdleDataSend(struct WebSocketClient *clientPtr); + +#define COMMAND_IDLE -1 +#define COMMAND_NONE 0 +#define COMMAND_CONNECT_TO_HOST 1 +#define COMMAND_SEND_HANDSHAKE 2 +#define COMMAND_WAIT_HANDSHAKE_RESPONCE 3 +#define COMMAND_INFORM_CONNECTED 4 +#define COMMAND_INFORM_DISCONNECTED 5 + +#define COMMAND_END 9999 + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h new file mode 100644 index 000000000..12451a505 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_string.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +#ifndef __RWS_STRING_H__ +#define __RWS_STRING_H__ + +#include +#include +#include + +char *WsStringCopy(const char *str); + +char *WsStringCopyLen(const char *str, const size_t len); + +void WsStringDelete(char *str); + +void WsStringDeleteClean(char **str); + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h new file mode 100644 index 000000000..9da00ec0f --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_thread.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef __RWS_THREAD_H__ +#define __RWS_THREAD_H__ + +#include +#include + +#define RWS_WAIT_FOREVER 0xffffffffu + +/** + @brief Callback type of thread function. + @param userObject User object provided during thread creation. + */ +typedef void (*WsThreadFunct)(void *userObject); + +struct WsThreadStruct { + WsThreadFunct threadFunction; + void *userObject; + pthread_t thread; +}; + +/** + @brief Type of all public objects. + */ +typedef void *WsHandle; + +/** + @brief Mutex object handle. + */ +typedef WsHandle WsMutex; + +/** + @brief Mutex object handle. + */ +typedef WsHandle WsSem; + +/** + @brief Thread object handle. + */ +typedef struct WsThreadStruct *WsThread; + +WsThread WsThreadCreate(WsThreadFunct threadFunction, void *userObject); + +void WsThreadMsleep(const unsigned int millisec); + +WsMutex WsMutexCreateRecursive(void); + +void WsMutexLock(WsMutex mutex); + +void WsMutexUnLock(WsMutex mutex); + +void WsMutexDelete(WsMutex mutex); + +WsSem WsSemCreate(void); + +void WsSemDelete(WsSem sem); + +void WsSemSignal(WsSem sem); + + +#endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h new file mode 100644 index 000000000..a1d4fa27a --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/netstack/websocket/include/net_websocket_type.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef NET_WEBSOCKET_TYPE_H +#define NET_WEBSOCKET_TYPE_H + +#include +#include +/** + * @addtogroup netstack + * @{ + * + * @brief Provides C APIs for the WebSocket client module. + * + */ + +/** + * @file net_websocket_type.h + * @brief Defines the data structure for the C APIs of the WebSocket client module. + * + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the parameters for the connection error reported by the server. + */ +struct WebSocketErrorResult { + /** Error code */ + int errorCode; + /** Error message */ + const char *errorMessage; +}; + +/** + * @brief Defines the callback function invoked when an open message is received. + * + * @param client WebSocket client fd. + * @param openResult Content of the open message received by the WebSocket client. + * @since 11 + * @version 1.0 + */ +typedef void (*WebSocketOnOpenCallback)(int client); + +/** + * @brief Defines the callback function invoked when data is received. + * + * @param client WebSocket client fd. + * @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 (*WebSocketOnMessageCallback)(int client, const char *data, size_t length, bool isFinished); + +/** + * @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 (*WebSocketOnErrorCallback)(int client, struct WebSocketErrorResult errorResult); + +/** + * @brief Defines the callback function invoked when a close message is received. + * + * @param client WebSocket client. + */ +typedef void (*WebSocketOnCloseCallback)(int client); + + +typedef enum WebSocketErrCode { + /** + * Operation success. + */ + WEBSOCKET_OK = 0, + + /** + * @brief The WebSocket client is null. + */ + WEBSOCKET_CLIENT_NULL = (-2), + + /** + * @brief A WebSocket client is not created. + */ + WEBSOCKET_CLIENT_NOT_CREATED = (-3), + + /** + * @brief An error occurs while setting up a WebSocket connection. + */ + WEBSOCKET_CONNECTION_ERROR = (-4), + + /** + * @brief An error occurs while parsing WebSocket connection parameters. + */ + WEBSOCKET_CONNECTION_PARSE_URL_ERROR = (-5), + + /** + * @brief The memory is insufficient for creating a context during WebSocket connection setup. + */ + WEBSOCKET_CONNECTION_NO_MEMORY = (-6), + + /** + * @brief The WebSocket connection is closed by the peer. + */ + WEBSOCKET_CONNECTION_CLOSED_BY_PEER = (-7), + + /** + * @brief The WebSocket connection is destroyed. + */ + WEBSOCKET_DESTROYED = (-8), + + /** + * @brief An incorrect protocol is used for WebSocket connection. + */ + WEBSOCKET_PROTOCOL_ERROR = (-9), + + /** + * @brief The memory for the WebSocket client to send data is insufficient. + */ + WEBSOCKET_NO_MEMORY = (-10), + + /** + * @brief The data sent by the WebSocket client is null. + */ + WEBSOCKET_SEND_DATA_NULL = (-11), + + /** + * @brief The length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_DATA_LENGTH_EXCEEDED = (-12), + + /** + * @brief The queue length of the data sent by the WebSocket client exceeds the limit. + */ + WEBSOCKET_QUEUE_LENGTH_EXCEEDED = (-13), + + /** + * @brief The WebSocket client is not connected. + */ + WEBSOCKET_NO_CONNECTION = (-14), + + WEBSOCKET_MISSED_PARAM = (-15), + + WEBSOCKET_ERROR_SEND_HANDSHAKE = (-16), + + WEBSOCKET_ERROR_PARSE_HANDSHAKE = (-17), + + WEBSOCKET_ERROR_READ_WRITE_SOCKET = (-18), + + WEBSOCKET_ERROR_CONNECT_TO_HOST = (-19), + + WEBSOCKET_ERROR_CONNECT_CLOSED = (-20), +} WebSocketErrCode; + + +#ifdef __cplusplus +} +#endif + +#endif // NET_WEBSOCKET_TYPE_H \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/network/network_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/network/network_module.cpp index b58a44585..c6363c052 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/network/network_module.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/network/network_module.cpp @@ -20,7 +20,7 @@ #include #include #include "network_module.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" #include "msg_center_protocol.h" #include "bts_le_gap.h" #include "network_listener.h" diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h index 07dad5756..a38ac4aa9 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h @@ -42,9 +42,11 @@ extern void InitBaiduMapComponentModule(JSIValue exports); #ifdef FEATURE_ACELITE_DFX_MODULE extern void InitDfxModule(JSIValue exports); #endif // FEATURE_ACELITE_DFX_MODULE -// #ifdef ENABLE_MODULE_CIPHER -// extern void InitCipherModule(JSIValue exports); -// #endif +#ifndef XTS_SUPPORT +#ifdef ENABLE_MODULE_CIPHER +extern void InitCipherModule(JSIValue exports); +#endif +#endif // #ifdef FEATURE_MODULE_DIALOG // extern void InitDialogModule(JSIValue exports); // #endif // FEATURE_MODULE_DIALOG @@ -56,6 +58,7 @@ extern void InitNativeApiKv(JSIValue exports); #ifdef FEATURE_MODULE_DEVICE extern void InitDeviceModule(JSIValue exports); +extern void InitDeviceInfoModule(JSIValue exports); #endif #ifdef FEATURE_MODULE_GEO @@ -71,10 +74,18 @@ extern void InitSensorModule(JSIValue exports); extern void InitBrightnessModule(JSIValue exports); #endif +#ifdef FEATURE_MODULE_HTTP +extern void InitHttpClientModule(JSIValue exports); +#endif + #ifdef FEATURE_MODULE_BATTERY extern void InitBatteryModule(JSIValue exports); #endif +#ifdef FEATURE_MODULE_WEBSOCKET +extern void InitWebsocketClientModule(JSIValue exports); +#endif + #ifdef FEATURE_MODULE_CONFIGURATION extern void InitLocaleModule(JSIValue exports); #endif @@ -111,9 +122,11 @@ const Module OHOS_MODULES[] = { {"dfx", InitDfxModule}, #endif // FEATURE_ACELITE_DFX_MODULE {"router", InitRouterModule}, -// #ifdef ENABLE_MODULE_CIPHER -// {"cipher", InitCipherModule}, -// #endif +#ifndef XTS_SUPPORT +#ifdef ENABLE_MODULE_CIPHER + {"cipher", InitCipherModule}, +#endif +#endif // #ifdef FEATURE_MODULE_DIALOG // {"prompt", InitDialogModule}, // #endif // FEATURE_MODULE_DIALOG @@ -124,6 +137,7 @@ const Module OHOS_MODULES[] = { #endif #ifdef FEATURE_MODULE_DEVICE {"device", InitDeviceModule}, + {"deviceInfo", InitDeviceInfoModule}, #endif #ifdef FEATURE_MODULE_GEO {"geolocation", InitLocationModule}, @@ -135,6 +149,9 @@ const Module OHOS_MODULES[] = { #ifdef FEATURE_MODULE_BRIGHTNESS {"brightness", InitBrightnessModule}, #endif +#ifdef FEATURE_MODULE_HTTP + {"net.http", InitHttpClientModule}, +#endif #ifdef FEATURE_MODULE_BATTERY {"battery", InitBatteryModule}, #endif @@ -144,6 +161,9 @@ const Module OHOS_MODULES[] = { // #ifdef FEATURE_ACELITE_SYSTEM_CAPABILITY // {"capability", InitCapabilityModule}, // #endif +#ifdef FEATURE_MODULE_WEBSOCKET + {"net.webSocket", InitWebsocketClientModule}, +#endif #ifdef FEATURE_MODULE_NFC {"nfc.cardEmulation", NfcHceInitModule}, #endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/cjson_parser.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/cjson_parser.cpp index 215ef4de2..a5048c738 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/cjson_parser.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/cjson_parser.cpp @@ -570,7 +570,6 @@ jerry_value_t CJSONParser::GetValue(const char *key, const jerry_value_t args[], // try finding from cache first Node *node = GetValueFromCache(key); if (node == nullptr) { - HILOG_WARN(HILOG_MODULE_ACE, "get value from cache failed"); // no node found from cache, searching from current language file then jerry_value_t resultFromFile = GetValueFromFile(key, arg, argsNum, languageFile_); if (!IS_UNDEFINED(resultFromFile)) { diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp new file mode 100644 index 000000000..5af2226fd --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include "websocket_module.h" +#include "net_websocket.h" +#include +#include "ace_log.h" +#include "errcode.h" +#include "cmsis_os2.h" + +namespace OHOS { +namespace ACELite { + +JSIValue ws; +JSIValue close; +JSIValue on; +JSIValue off; +JSIValue send; +JSIValue connect; + +std::map WebsocketModule::eventCallbacks; + +JSIValue WebsocketModule::CreateWebsocket(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + ws = JSI::CreateObject(); + connect = JSI::CreateFunction(WebsocketModule::Connect); + send = JSI::CreateFunction(WebsocketModule::Send); + on = JSI::CreateFunction(WebsocketModule::On); + off = JSI::CreateFunction(WebsocketModule::Off); + close = JSI::CreateFunction(WebsocketModule::Close); + JSI::SetNamedProperty(ws, "send", send); + JSI::SetNamedProperty(ws, "connect", connect); + JSI::SetNamedProperty(ws, "on", on); + JSI::SetNamedProperty(ws, "off", off); + JSI::SetNamedProperty(ws, "close", close); + return ws; +} + +static void OnOpen(int client) +{ + auto it = WebsocketModule::eventCallbacks.find(std::string("open")); + if (it == WebsocketModule::eventCallbacks.end()) { + HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnOpen Callback!"); + } + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + JSIValue err = JSI::CreateBoolean(false); + JSIValue argv[2] = {err, value}; + if (it != WebsocketModule::eventCallbacks.end()) { + JSI::CallFunction(it->second->callback, it->second->context, argv, 2); + } + JSI::ReleaseValueList(value, err); +} + +static void OnMessage(int client, const char *data, size_t length, bool isFinished) +{ + auto it = WebsocketModule::eventCallbacks.find(std::string("message")); + if (it == WebsocketModule::eventCallbacks.end()) { + HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnMessage Callback!"); + } + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "length", length); + JSI::SetStringProperty(value, "data", data); + JSI::SetNumberProperty(value, "client", client); + } + JSIValue err = JSI::CreateBoolean(false); + JSIValue argv[2] = {err, value}; + if (it != WebsocketModule::eventCallbacks.end()) { + JSI::CallFunction(it->second->callback, it->second->context, argv, 2); + } + JSI::ReleaseValueList(value, err); +} + +static void OnError(int client, struct WebSocketErrorResult errorResult) +{ + auto it = WebsocketModule::eventCallbacks.find(std::string("error")); + if (it == WebsocketModule::eventCallbacks.end()) { + HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnError Callback!"); + } + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + JSIValue err = JSI::CreateBoolean(false); + JSIValue argv[2] = {err, value}; + if (it != WebsocketModule::eventCallbacks.end()) { + JSI::CallFunction(it->second->callback, it->second->context, argv, 2); + } + JSI::ReleaseValueList(value, err); +} + +static void OnClose(int client) +{ + auto it = WebsocketModule::eventCallbacks.find(std::string("open")); + if (it == WebsocketModule::eventCallbacks.end()) { + HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnError Callback!"); + } + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + JSIValue err = JSI::CreateBoolean(false); + JSIValue argv[2] = {err, value}; + if (it != WebsocketModule::eventCallbacks.end()) { + JSI::CallFunction(it->second->callback, it->second->context, argv, 2); + } + JSI::ReleaseValueList(value, err); +} + +JSIValue WebsocketModule::Send(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int client = JSI::ValueToNumber(JSI::AcquireValue(args[1])); + char *message = JSI::ValueToString(JSI::AcquireValue(args[0])); + + size_t length = strlen(message); + int ret = WebSocketClientSendText(client, message, length); + + JSIValue isError; + isError = JSI::CreateBoolean(ret == 0 ? false : true); + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + + JSIValue callback = JSI::AcquireValue(args[2]); + JSIValue argv[ARGC_TWO] = {isError, value}; + JSI::CallFunction(callback, thisVal, argv, ARGC_TWO); + JSI::ReleaseValueList(value, callback); + JSI::ReleaseString(message); + return JSI::CreateUndefined(); +} + +JSIValue WebsocketModule::Connect(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + char *url = JSI::ValueToString(JSI::AcquireValue(args[0])); + int client = WebSocketClientConstructor(OnOpen, OnMessage, OnError, OnClose); + if (client < 0) { + HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConstructor fail!"); + return JSI::CreateUndefined(); + } + + int ret = WebSocketClientConnect(client, url); + if (ret != 0) { + HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConnect fail!"); + return JSI::CreateUndefined(); + } + + JSIValue isError; + isError = JSI::CreateBoolean(ret == 0 ? false : true); + + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + + JSIValue callback = JSI::AcquireValue(args[1]); + JSIValue argv[ARGC_TWO] = {isError, value}; + JSI::CallFunction(callback, thisVal, argv, ARGC_TWO); + JSI::ReleaseValueList(value, callback, isError); + JSI::ReleaseString(url); + return JSI::CreateUndefined(); +} + +JSIValue WebsocketModule::Close(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int client = JSI::ValueToNumber(JSI::AcquireValue(args[0])); + int ret = WebSocketClientClose(client); + if (ret != 0) { + HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConnect fail!"); + } + JSIValue isError; + isError = JSI::CreateBoolean(ret == 0 ? false : true); + JSIValue value = JSI::CreateObject(); + if (value != nullptr) { + JSI::SetNumberProperty(value, "client", client); + } + + JSIValue callback = JSI::AcquireValue(args[1]); + JSIValue argv[ARGC_TWO] = {isError, value}; + JSI::CallFunction(callback, thisVal, argv, ARGC_TWO); + JSI::ReleaseValueList(isError, value, callback); + return JSI::CreateUndefined(); +} + +void WebsocketModule::Destroy() +{ + for (auto it = eventCallbacks.begin(); it != eventCallbacks.end();) { + auto currentIt = it; + ++it; + EventCallback *ec = currentIt->second; + JSI::ReleaseValue(ec->context); + JSI::ReleaseValue(ec->callback); + delete ec; + eventCallbacks.erase(currentIt); + } + eventCallbacks.clear(); + + JSI::ReleaseValue(on); + JSI::ReleaseValue(off); + JSI::ReleaseValue(connect); + JSI::ReleaseValue(close); + JSI::ReleaseValue(send); + JSI::ReleaseValue(ws); +} + +JSIValue WebsocketModule::On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + if (argsSize < 2) { + HILOG_ERROR(HILOG_MODULE_ACE, "Function parameters are not enough!"); + return JSI::CreateBoolean(false); + } + + char *eventName = JSI::ValueToString(JSI::AcquireValue(args[0])); + + auto it = eventCallbacks.find(eventName); + if (it != eventCallbacks.end()) { + EventCallback *oldEc = it->second; + JSI::ReleaseValue(oldEc->callback); + JSI::ReleaseValue(oldEc->context); + delete oldEc; + eventCallbacks.erase(it); + } + + JSIValue callback = JSI::AcquireValue(args[1]); + + EventCallback *ec = new EventCallback; + if (ec != nullptr) { + ec->callback = JSI::AcquireValue(callback); + ec->context = JSI::AcquireValue(thisVal); + eventCallbacks[eventName] = ec; + JSI::ReleaseString(eventName); + JSI::ReleaseValue(callback); + return JSI::CreateBoolean(true); + } else { + JSI::ReleaseString(eventName); + JSI::ReleaseValue(callback); + } + + return JSI::CreateBoolean(false); +} + +JSIValue WebsocketModule::Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + if (argsSize < 1) { + HILOG_ERROR(HILOG_MODULE_ACE, "Function parameters are not enough!"); + return JSI::CreateBoolean(false); + } + + char *eventName = JSI::ValueToString(JSI::AcquireValue(args[0])); + + auto it = eventCallbacks.find(eventName); + if (it != eventCallbacks.end()) { + JSI::ReleaseValue(it->second->callback); + JSI::ReleaseValue(it->second->context); + delete it->second; + eventCallbacks.erase(it); + JSI::ReleaseString(eventName); + return JSI::CreateBoolean(true); + }else { + HILOG_ERROR(HILOG_MODULE_ACE, "Off failed, target not found!"); + JSI::ReleaseString(eventName); + } + return JSI::CreateBoolean(false); +} + +void InitWebsocketClientModule(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "createWebsocket", WebsocketModule::CreateWebsocket); + JSI::SetOnTerminate(exports, WebsocketModule::OnTerminate); +} + +void WebsocketModule::OnTerminate() +{ + WebsocketModule::Destroy(); +} +} // namespace ACELite +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.h new file mode 100644 index 000000000..a65747196 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/websocket/websocket_module.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag. 2024-2025. All rights reserved. + * Description: http control interfaces + * Author: Software Group + * Create: 2025-06-06 + */ + +#ifndef WEBSOCKET_CLIENT_MODULE_H +#define WEBSOCKET_CLIENT_MODULE_H + +#include +#include "jsi.h" +#include +#include + +namespace OHOS { +namespace ACELite { + +struct EventCallback { + JSIValue callback; + JSIValue context; +}; + +class WebsocketModule final : public MemoryHeap { +public: + WebsocketModule() = default; + ~WebsocketModule() = default; + static JSIValue CreateWebsocket(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Connect(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Send(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Close(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static JSIValue Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + static std::map eventCallbacks; + static void Destroy(); + static void OnTerminate(); +}; +void InitWebsocketModule(JSIValue exports); + +} // namespace ACELite +} // namespace OHOS + +#endif // WEBSOCKET_CLIENT_MODULE_H \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-cli/libbms.a b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-cli/libbms.a index 72e2b6a18..0f8144c2d 100644 Binary files a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-cli/libbms.a and b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-cli/libbms.a differ diff --git a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-ser/libbms.a b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-ser/libbms.a index bdaa35601..58dcccd4f 100644 Binary files a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-ser/libbms.a and b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-auto-ota-ser/libbms.a differ diff --git a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-native-js/libbms.a b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-native-js/libbms.a index ac4194c38..f262ad882 100644 Binary files a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-native-js/libbms.a and b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-native-js/libbms.a differ diff --git a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-xts/libbms.a b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-xts/libbms.a index 0c761ced1..dedacf00d 100644 Binary files a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-xts/libbms.a and b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/brandy-xts/libbms.a differ diff --git a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/include/appexecfwk/appexecfwk_lite/services/bundlemgr_lite/include/gt_bundle_installer.h b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/include/appexecfwk/appexecfwk_lite/services/bundlemgr_lite/include/gt_bundle_installer.h index 0e9fd02a2..3e72aa4d3 100644 --- a/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/include/appexecfwk/appexecfwk_lite/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/code/sdk/open_source/openharmony/foundation/appexecfwk/appexecfwk_lite/include/appexecfwk/appexecfwk_lite/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -47,9 +47,9 @@ private: uint8_t PreCheckBundle(const char *path, int32_t &fp, SignatureInfo &signatureInfo, uint32_t &fileSize, uint8_t bundleStyle); uint8_t ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord, - uint8_t bundleStyle, InstallerCallback installerCallback, bool &isUpdate); + uint8_t bundleStyle, InstallerCallback installerCallback, bool &isUpDate, bool keepData); uint8_t HandleFileAndBackUpRecord(const InstallRecord &record, const char *tmpPath, const char *randStr, - const char *dataPath, bool isUpdate); + const char *dataPath, bool isUpDate, bool keepData); uint8_t UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelId, uint32_t iconId, BundleInfo *bundleInfo, bool isUpdate); void RecordThirdSystemBundle(const char *bundleName, const char *path); diff --git a/code/sdk/open_source/openharmony/foundation/multimedia/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.h b/code/sdk/open_source/openharmony/foundation/multimedia/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.h index 6d1c9178e..138993815 100644 --- a/code/sdk/open_source/openharmony/foundation/multimedia/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.h +++ b/code/sdk/open_source/openharmony/foundation/multimedia/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.h @@ -49,6 +49,11 @@ public: handle exception */ static void ExceptionStop(void); + + /** + * Cancel + */ + static JSIValue Cancel(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); }; void InitAudioCapturerModule(JSIValue exports); diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-cli/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-cli/libjerryscript.a index a74badd84..0d64dd196 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-cli/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-cli/libjerryscript.a differ diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-ser/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-ser/libjerryscript.a index 79e6edeab..96543a87c 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-ser/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-auto-ota-ser/libjerryscript.a differ diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a index 00de31cdc..bafd4fc5f 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a differ diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a index 845c578e8..59ffd4c76 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a differ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt index 8950d1f52..b2d368d96 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt @@ -77,17 +77,23 @@ set(SOURCES ${CMAKE_LWIP_ADAPTER_DIR}/src/arch/ethernetif.c ${CMAKE_LWIP_ADAPTER_DIR}/src/test/lwip_test.c ${CMAKE_LWIP_ADAPTER_DIR}/src/test/socket_test.c - + ${CMAKE_CURRENT_SOURCE_DIR}/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.c ) +if("__LITEOS__" IN_LIST DEFINES) + list(APPEND SOURCES + ${ROOT_DIR}/open_source/mbedtls/mbedtls_v3.6.0/library/net_sockets.c + ) +endif() + set(PUBLIC_HEADER - ${CMAKE_LWIP_ADAPTER_DIR}/src/include ) set(PRIVATE_HEADER ${CMAKE_LWIP_SOURCE_DIR}/src/include ${CMAKE_LWIP_SOURCE_DIR}/src/include/lwip/nettool ${CMAKE_LWIP_ADAPTER_DIR}/src/include + ${CMAKE_CURRENT_SOURCE_DIR}/lwip_adapter/lwip_driver_adapter/ ${ROOT_DIR}/include/middleware/services/wifi ) @@ -97,6 +103,8 @@ set(PRIVATE_DEFINES set(PUBLIC_DEFINES LWIP_CONFIG_FILE=\"lwip/lwipopts_default.h\" + MBEDTLD_USE_LWIP + MBEDTLS_NET_C ) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/ethernetif.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/ethernetif.c index 5b12ef602..b4b169441 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/ethernetif.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/ethernetif.c @@ -199,8 +199,10 @@ err_t ethernetif_init(struct netif *netif) return ERR_OK; } +#if LWIP_ARP static void arp_timer(void *arg) { etharp_tmr(); sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); } +#endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h index 10022b9cd..9488949a9 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h @@ -1032,7 +1032,7 @@ extern "C" { #endif #ifndef LWIP_COMPAT_SOCKETS -#define LWIP_COMPAT_SOCKETS 2 +#define LWIP_COMPAT_SOCKETS 1 #define LWIP_POSIX_SOCKETS_IO_NAMES 0 #endif @@ -1502,6 +1502,11 @@ extern unsigned int g_lwip_num_sockets; #define TCP_TTL 255 #endif +#define LWIP_ETHERNET 1 +#ifndef LWIP_ARP +#define LWIP_ARP 1 +#endif + /** * Defines the mailbox size for the tcpip thread messages * The queue size value itself is platform-dependent, but is passed to diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/sockets.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/sockets.h new file mode 100644 index 000000000..d3bda525b --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/sockets.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_SOCKETS_H_ +#define _LWIP_PORTING_SOCKETS_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include_next + +#ifdef __cplusplus +extern "C" { +#endif + +#if FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) +#error "external FD_SETSIZE too small for number of sockets" +#else +#define LWIP_SELECT_MAXNFDS FD_SETSIZE +#endif + +#if IOV_MAX > 0xFFFF +#error "IOV_MAX larger than supported by LwIP" +#endif + +#if LWIP_UDP && LWIP_UDPLITE +#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ +#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ +#endif + +// For BSD 4.4 socket sa_len compatibility +#define DF_NADDR(addr) +#define SA_LEN(addr, _) (IP_IS_V4_VAL(addr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) +#define sa_len sa_data[0] * 0 + SA_LEN(naddr, _) +#define sin_len sin_zero[0] +#define sin6_len sin6_addr.s6_addr[0] + +// for sockets.c, TCP_KEEPALIVE is not supported currently +#define TCP_KEEPALIVE 0xFF +#define SIN_ZERO_LEN 8 + +int closesocket(int sockfd); +int ioctlsocket(int s, long cmd, void *argp); + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_SOCKETS_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.c new file mode 100644 index 000000000..bc845a7bf --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.c @@ -0,0 +1,240 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#include "lwip_driver_adapter.h" +#include "lwip/tcpip.h" +#include "lwip/netifapi.h" +#include "lwip/arch.h" +#ifdef SUPPORT_BREDR +#include "bts_pan.h" +#include "bts_br_gap.h" +#endif + +#ifdef SUPPORT_BREDR +static struct netif *bt_pan_netif = NULL; +#endif +static err_t lwip_driver_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr); + +static err_t lwip_netif_linkout(struct netif *netif, struct pbuf *p) +{ + if (p == NULL || p->payload == NULL) { + return ERR_ARG; + } + unsigned char *payload = (unsigned char *)p->payload; + if (p->len > SIZEOF_ETH_HDR) { /* delete arp packet ethernet header */ + payload += SIZEOF_ETH_HDR; + p->len -= SIZEOF_ETH_HDR; + } +#ifdef SUPPORT_BREDR + pan_service_write_data(payload, p->len, PAN_NETWORK_PROTOCOL_ARP, PAN_PACKET_TYPE_DEST_ONLY_UNICAST); +#endif + return ERR_OK; +} + +static err_t lwip_driver_init_fn(struct netif *netif_p) +{ + netif_p->output = lwip_driver_output; + netif_p->linkoutput = lwip_netif_linkout; + + netifapi_netif_set_up(netif_p); + netifapi_netif_set_link_up(netif_p); + netif_p->mtu = 1000; /* 1000: mtu */ + + return ERR_OK; +} + +/* 网络设备初始化 驱动初始化时调用 + 参数 name:网络设备名称 2bytes + */ +static struct netif *lwip_driver_init_netif(const char *name, const unsigned char *hw_addr) +{ + struct netif *netif = (struct netif *)malloc(sizeof(struct netif)); +#if LWIP_IPV4 + ip4_addr_t ipaddr, netmask, gw; + + IP4_ADDR(&gw, 192, 168, 44, 1); /* 192 168 44 1 : default gw addr */ + IP4_ADDR(&ipaddr, 192, 168, 44, 66); /* 192 168 44 66 : default ip addr */ + IP4_ADDR(&netmask, 255, 255, 255, 0); /* 255 0 : default netmask */ +#endif + + if (netif == NULL) { + return NULL; + } + memset_s(netif, sizeof(struct netif), 0, sizeof(struct netif)); + strncpy_s(netif->name, sizeof(netif->name), name, strlen(name)); + if (memcpy_s(netif->hwaddr, NETIF_MAX_HWADDR_LEN, hw_addr, NETIF_MAX_HWADDR_LEN) != EOK) { + free(netif); + return NULL; + } + netif->hwaddr_len = NETIF_MAX_HWADDR_LEN; + netifapi_netif_add(netif, +#if LWIP_IPV4 + &ipaddr, + &netmask, + &gw, +#endif + NULL, + lwip_driver_init_fn, + tcpip_input); + netif_set_default(netif); + return netif; +} + +/* 收包入口 + 参数 data:报文数据区指针 以ip开始 + len:数据长度 + netif:网络设备指针 +*/ +static err_t lwip_driver_input(u8_t *data, u16_t len, struct netif *netif) +{ + struct pbuf *p = NULL; + + if ((data == NULL) || (netif == NULL)) { + return ERR_ARG; + } + p = pbuf_alloc(PBUF_RAW, (len + ETH_PAD_SIZE), PBUF_RAM); + if (p == NULL) { + return ERR_BUF; + } + if (memcpy_s(p->payload, len, data, len) != EOK) { + return ERR_MEM; + } + p->len = len; + netif->input(p, netif); + return ERR_OK; +} +/* 发包函数 + 参数 netif:网络设备指针 + p:pbuf指针 + ipaddr:不使用 + */ +static err_t lwip_driver_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) +{ + if (netif == NULL || p == NULL || ipaddr == NULL) { + return ERR_ARG; + } +#ifdef SUPPORT_BREDR + if (ip4_addr_isbroadcast(ipaddr, netif)) { + pan_service_write_data(p->payload, p->len, PAN_NETWORK_PROTOCOL_IPV4, PAN_PACKET_TYPE_DEST_ONLY_BORADCAST); + } else { + pan_service_write_data(p->payload, p->len, PAN_NETWORK_PROTOCOL_IPV4, PAN_PACKET_TYPE_DEST_ONLY_UNICAST); + } +#endif + return ERR_OK; +} + +#ifdef SUPPORT_BREDR +static void sample_pan_net_state_callback(uint8_t net_state) +{ + printf("sample pan net_state=%u\n", net_state); + if (net_state == 1) { +#if defined(LWIP_DHCP) && LWIP_DHCP + netifapi_dhcp_start(bt_pan_netif); + printf("dhcp start\n"); +#endif + } +} + +#if defined(LWIP_IPV4) && LWIP_IPV4 && defined(LWIP_ARP) && LWIP_ARP +static int lwip_input_arp(u8_t *data, u16_t len, struct netif *netif) +{ + struct pbuf *p = NULL; + + if ((data == NULL) || (netif == NULL)) { + return ERR_ARG; + } + p = pbuf_alloc(PBUF_RAW, (len + ETH_PAD_SIZE), PBUF_RAM); + if (p == NULL) { + return ERR_BUF; + } + if (memcpy_s(p->payload, len, data, len) != EOK) { + return ERR_MEM; + } + p->len = len; + etharp_input(p, netif); + return ERR_OK; +} +#endif + +static void sample_pan_rpt_ethernet(uint8_t *packet, uint16_t packet_length, uint16_t network_protocol) +{ + int ret = ERR_OK; + if (network_protocol == PAN_NETWORK_PROTOCOL_ARP) { +#if defined(LWIP_IPV4) && LWIP_IPV4 && defined(LWIP_ARP) && LWIP_ARP + ret = lwip_input_arp(packet, packet_length, bt_pan_netif); +#endif + } else if (network_protocol == PAN_NETWORK_PROTOCOL_IPV4) { + ret = lwip_driver_input(packet, packet_length, bt_pan_netif); + } else { + return; + } + if (ret != 0) { + printf("pan receive packet fail, ret=0x%x\n", ret); + } +} + +static pan_callbacks_t g_sample_pan_callbacks_t = {sample_pan_net_state_callback, sample_pan_rpt_ethernet}; + +/* mac addr to big-endian */ +static void mac_addr_hton(uint8_t *data) +{ + uint8_t temp; + + temp = data[0]; + data[0] = data[5]; /* 5 : byte index */ + data[5] = temp; /* 5 : byte index */ + + temp = data[1]; /* 1 : byte index */ + data[1] = data[4]; /* 1 4 : byte index */ + data[4] = temp; /* 4 : byte index */ + + temp = data[2]; /* 2 : byte index */ + data[2] = data[3]; /* 2 3 : byte index */ + data[3] = temp; /* 3 : byte index */ +} + +static void lwip_register_bt_netif(void) +{ + unsigned char local_addr[6]; /* 6: mac addr length */ + bluetooth_get_local_addr(local_addr, 6); /* 6: mac addr length */ + mac_addr_hton(local_addr); + if (bt_pan_netif != NULL) { + return; + } + bt_pan_netif = lwip_driver_init_netif("bt", local_addr); + if (bt_pan_netif == NULL) { + printf("sample pan init lwip fail\n"); + } +} + +void bt_pan_open(void) +{ + int result; + bool ret; + gap_paired_device_info_t dev_info[1] = {0}; + int number = 1; + lwip_register_bt_netif(); + ret = gap_get_paired_devices_list(dev_info, &number); + if (ret) { + printf("get bt dev info ok\n"); + } else { + printf("get bt dev info fail\n"); + return; + } + result = pan_register_callbacks(&g_sample_pan_callbacks_t); + if (result == 0) { + printf("pan register callbacks ok\n"); + } else { + printf("pan register fail\n"); + return; + } + + result = pan_service_open(&dev_info[0].addr); + if (result == 0) { + printf("pan_service_open ok\n"); + } else { + printf("pan_service_open fail\n"); + } +} +#endif /* SUPPORT_BREDR */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.h new file mode 100644 index 000000000..00869f86b --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter/lwip_driver_adapter.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ + +#ifndef LWIP_DRIVER_ADAPTER_H +#define LWIP_DRIVER_ADAPTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SUPPORT_BREDR +void bt_pan_open(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/netdb.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/netdb.c index ee7829786..aa71ee903 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/netdb.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/netdb.c @@ -351,7 +351,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, } } - total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage); + total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + LWIP_SOCKET_ADDR_ALIGNMENT; if (nodename != NULL) { namelen = strlen(nodename); if (namelen > DNS_MAX_NAME_LENGTH) { @@ -371,6 +371,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, memset(ai, 0, total_size); /* cast through void* to get rid of alignment warnings */ sa = (struct sockaddr_storage *)(void *)((u8_t *)ai + sizeof(struct addrinfo)); + sa = LWIP_SOCKET_ADDR_ALIGN(sa); if (IP_IS_V6_VAL(addr)) { #if LWIP_IPV6 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/sockets.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/sockets.c index 30594879b..faf10d96c 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/sockets.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/sockets.c @@ -2562,8 +2562,15 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) has_sendevent = sock->sendevent != 0; has_errevent = sock->errevent != 0; SYS_ARCH_UNPROTECT(lev); +#if LWIP_TCPIP_CORE_LOCKING + /* Protect the select_cb_list */ + LWIP_SOCKET_SELECT_PROTECT(lev); +#endif /* !LWIP_TCPIP_CORE_LOCKING */ /* Check any select calls waiting on this socket */ select_check_waiters(s, has_recvevent, has_sendevent, has_errevent); +#if LWIP_TCPIP_CORE_LOCKING + LWIP_SOCKET_SELECT_UNPROTECT(lev); +#endif /* !LWIP_TCPIP_CORE_LOCKING */ } else { SYS_ARCH_UNPROTECT(lev); } diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/dns.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/dns.c index ca38e0563..b63a09999 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/dns.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/core/dns.c @@ -307,6 +307,10 @@ const ip_addr_t dns_mquery_v4group = DNS_MQUERY_IPV4_GROUP_INIT; const ip_addr_t dns_mquery_v6group = DNS_MQUERY_IPV6_GROUP_INIT; #endif /* LWIP_IPV6 */ +#ifndef DNS_SERVER_ADDRESS +#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ip_2_ip4(ipaddr), ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */ +#endif + /** * Initialize the resolver: set up the UDP pcb and configure the default server * (if DNS_SERVER_ADDRESS is set). @@ -316,7 +320,7 @@ dns_init(void) { #ifdef DNS_SERVER_ADDRESS /* initialize default DNS server address */ - ip_addr_t dnsserver; + ip_addr_t dnsserver = {0}; DNS_SERVER_ADDRESS(&dnsserver); dns_setserver(0, &dnsserver); #endif /* DNS_SERVER_ADDRESS */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/lwip/netdb.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/lwip/netdb.h index d3d15dfac..b501648ac 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/lwip/netdb.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include/lwip/netdb.h @@ -112,7 +112,14 @@ struct addrinfo { }; #endif /* LWIP_DNS_API_DECLARE_STRUCTS */ -#define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1) +#define LWIP_SOCKET_ADDR_ALIGNMENT 4 +#ifndef LWIP_SOCKET_ADDR_ALIGN +#define LWIP_SOCKET_ADDR_ALIGN(addr) \ + ((void *)(((uintptr_t)(addr) + LWIP_SOCKET_ADDR_ALIGNMENT - 1) & ~(uintptr_t)(LWIP_SOCKET_ADDR_ALIGNMENT - 1))) +#endif + +#define NETDB_ELEM_SIZE \ + (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + LWIP_SOCKET_ADDR_ALIGNMENT + 1) #if LWIP_DNS_API_DECLARE_H_ERRNO /* application accessible error code set by the DNS API functions */