${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
${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
${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
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
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);
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;
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);
}
/**
return ret;
}
+JSValue Component::GetX(const JSValue func, const JSValue dom, const JSValue args[], const jerry_length_t size)
+{
+ UIView *view = reinterpret_cast<UIView *>(ComponentUtils::GetViewFromBindingObject(dom));
+ if (view == nullptr) {
+ HILOG_ERROR(HILOG_MODULE_ACE, "failed to get globalX. view is nullptr");
+ return -1;
+ }
+ double x = static_cast<double>(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<UIView *>(ComponentUtils::GetViewFromBindingObject(dom));
+ if (view == nullptr) {
+ HILOG_ERROR(HILOG_MODULE_ACE, "failed to get globalY. view is nullptr");
+ return -1;
+ }
+ double y = static_cast<double>(view->GetOrigRect().GetY());
+ return jerry_create_number(y);
+}
+
} // namespace ACELite
} // namespace OHOS
*/
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
*/
Dimension marginLeft_;
Dimension marginRight_;
Dimension marginBottom_;
+ static const char * const FUNC_GETX;
+ static const char * const FUNC_GETY;
};
} // namespace ACELite
} // namespace OHOS
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)
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;
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)
}
bool ViewOnTouchCancelListener::OnCancel(UIView &view, const CancelEvent &event)
{
- return CallBaseEvent(fn_, event, id_);
+ return CallBaseEvent(fn_, event, id_, view);
}
#endif // JS_TOUCH_EVENT_SUPPORT
textSelected_(0),
pTextArray_(nullptr),
textArraySize_(0),
+ overflowMode_(UILabel::LINE_BREAK_CLIP),
textPickerListener_(nullptr),
#ifdef FEATURE_COMPONENT_DATE_PICKER
dateSelected_(nullptr),
textPicker->SetHighlightFont(selectedFontFamily_, selectedFontSize_);
textPicker->SetTextColor(color_, selectedColor_);
textPicker->SetItemHeight(pickerItemHeight_);
+ textPicker->SetTextLineBreakMode(overflowMode_);
break;
}
case PickerType::TIME: {
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);
pickerItemHeight_ = fontSize_ + PICKER_ITEM_HEIGHT_GAP;
}
break;
+ case K_TEXT_OVERFLOW:
+ SetTextOverflow(styleItem);
+ break;
case K_FONT_FAMILY:
CopyFontFamily(fontFamily_, GetStyleStrValue(styleItem));
break;
#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();
char* selectedFontFamily_;
uint16_t pickerItemHeight_;
bool loopState_;
+ uint8_t overflowMode_;
// text picker-view attributes
uint16_t textSelected_;
#define OHOS_ACELITE_CONFIG_H
// some features depend on the low layer configuration
-#include "graphic_config.h"
+#define ENABLE_ROTATE_INPUT 1
/**
* ================================================================================================
*/
#define JS_TOUCH_EVENT_SUPPORT
+/**
+ * support cipher module
+ */
+#define ENABLE_MODULE_CIPHER
+
#endif // OHOS_ACELITE_CONFIG_H
#include "product_adapter.h"
#include "abilityms_slite_client.h"
#include "NativeAbility.h"
-#include "SetDesktopModel.h"
+#include "settings/SetDesktopModel.h"
namespace OHOS {
namespace ACELite {
#include "media_log.h"\r
#include "global.h"\r
#include "screen.h"\r
+#include "parameter.h"\r
\r
namespace OHOS {\r
namespace ACELite {\r
const char * const DeviceModule::DEVICE_SCREEN_DENSITY_NAME = "screenDensity";\r
const char * const DeviceModule::DEVICE_SCREEN_SHAPE = "screenShape";\r
const uint32_t DeviceModule::DEVICE_SCREEN_DENSITY = 326;\r
-const uint8_t DeviceModule::DEVICE_API_VERSION = 4;\r
const char * const DeviceModule::DEVICE_TYPE = "deviceType";\r
const char * const DeviceModule::DEVICE_API_VERSION_NAME = "apiVersion";\r
-\r
+const char * const DeviceModule::DEVICE_MACADDRESS = "macAddress";\r
bool DeviceModule::GetBrand(JSIValue result)\r
{ bool ret = true;\r
const char *brand = DEVICE_BRAND;\r
return ret;\r
}\r
\r
+bool DeviceModule::GetMac(JSIValue result)\r
+{\r
+ int ret = true;\r
+ char macAddress[18];\r
+ ret = GetMacAddress(macAddress, sizeof(macAddress));\r
+ if (ret != 0) {\r
+ return false;\r
+ } else {\r
+ JSI::SetStringProperty(result, DEVICE_MACADDRESS, macAddress);\r
+ }\r
+ return true;\r
+}\r
+\r
bool DeviceModule::GetScreenInfo(JSIValue result)\r
{\r
Screen &screen = Screen::GetInstance();\r
bool DeviceModule::GetApiVersion(JSIValue result)\r
{\r
bool ret = true;\r
- uint8_t apiVersion = DEVICE_API_VERSION;\r
+ uint8_t apiVersion = GetSdkApiVersion();\r
JSI::SetNumberProperty(result, DEVICE_API_VERSION_NAME, apiVersion);\r
return ret;\r
}\r
\r
if (GetBrand(result) && GetManufacturer(result) && GetModel(result) && GetProduct(result)\r
&& GetLanguage(result) && GetRegion(result) && GetScreenInfo(result) &&\r
- GetApiVersion(result) && GetDeviceType(result)) \r
+ GetApiVersion(result) && GetDeviceType(result) && GetMac(result))\r
{\r
SuccessCallBack(thisVal, args, result);\r
} else {\r
static const char * const DEVICE_PRODUCT;\r
static const char * const DEVICE_LANGUAGE;\r
static const char * const DEVICE_REGION;\r
+ static const char * const DEVICE_MACADDRESS;\r
static const char * const DEVICE_WINDOW_WIDTH_NAME;\r
static const char * const DEVICE_WINDOW_HEIGHT_NAME;\r
static const char * const DEVICE_SCREEN_DENSITY_NAME;\r
static const char * const DEVICE_SCREEN_SHAPE;\r
static const uint32_t DEVICE_SCREEN_DENSITY;\r
- static const uint8_t DEVICE_API_VERSION;\r
static const char * const DEVICE_TYPE;\r
static const char * const DEVICE_API_VERSION_NAME;\r
static JSIValue GetInfo(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);\r
static bool GetScreenInfo(JSIValue result);\r
static bool GetDeviceType(JSIValue result);\r
static bool GetApiVersion(JSIValue result);\r
+ static bool GetMac(JSIValue result);\r
static const char* translateText(char* input);\r
\r
private:\r
#include "product_adapter.h"\r
#include <securec.h>\r
#include "geolocation_module.h"\r
-#include "media_log.h"\r
#include "global.h"\r
\r
namespace OHOS {\r
\r
JSIValue LocationModule::GetSupportCoordTypes(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)\r
{\r
+#if defined(ENABLE_LOCATION)\r
std::vector<LocationCoordinateSystemType> coordinateSystemTypes;\r
LocationErrCode errCode = Locator::GetInstance().QuerySupportCoordinateSystemType(coordinateSystemTypes);\r
if (errCode != ERRCODE_SUCCESS) {\r
}\r
}\r
return rltArray;\r
+#else\r
+ HILOG_INFO(HILOG_MODULE_ACE, "not support!");\r
+ return JSI::CreateUndefined();\r
+#endif\r
}\r
\r
JSIValue LocationModule::Unsubscribe(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)\r
{\r
+#if defined(ENABLE_LOCATION)\r
ExecuteUnsubscribe();\r
+#endif\r
return JSI::CreateUndefined();\r
}\r
\r
JSIValue LocationModule::Subscribe(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)\r
{\r
+#if defined(ENABLE_LOCATION)\r
return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribe);\r
+#else\r
+ HILOG_INFO(HILOG_MODULE_ACE, "not support!");\r
+ return JSI::CreateUndefined();\r
+#endif\r
}\r
\r
JSIValue LocationModule::GetLocationType(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)\r
{\r
+#if defined(ENABLE_LOCATION)\r
return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetLocationType);\r
+#else\r
+ HILOG_INFO(HILOG_MODULE_ACE, "not support!");\r
+ return JSI::CreateUndefined();\r
+#endif\r
}\r
\r
JSIValue LocationModule::GetLocation(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)\r
{\r
+#if defined(ENABLE_LOCATION)\r
return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetLocation);\r
+#else\r
+ HILOG_INFO(HILOG_MODULE_ACE, "not support!");\r
+ return JSI::CreateUndefined();\r
+#endif\r
}\r
\r
JSIValue LocationModule::ExecuteAsyncWork(\r
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*\r
+ * Copyright (c) 2020 Huawei Device Co., Ltd.\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <string>\r
+#include <new>\r
+#include "global.h"\r
+#include "parameter.h"\r
+// #include "sysversion.h"\r
+#include "ace_log.h"\r
+#include "js_app_context.h"\r
+#include "js_async_work.h"\r
+#include "jsi.h"\r
+static constexpr int MAX_BUFFER = 65;\r
+namespace OHOS {\r
+namespace ACELite {\r
+ \r
+JSIValue JSGetDeviceType(void)\r
+{\r
+ const char *value = GetDeviceType();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue deviceType = JSI::CreateString(value);\r
+ return deviceType;\r
+}\r
+\r
+JSIValue JSGetManufacture(void)\r
+{\r
+ const char *value = GetManufacture();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue manfactureName = JSI::CreateString(value);\r
+ return manfactureName;\r
+}\r
+\r
+JSIValue JSGetBrand(void)\r
+{\r
+ const char *value = GetBrand();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue productBrand = JSI::CreateString(value);\r
+ return productBrand;\r
+}\r
+\r
+JSIValue JSGetMarketName(void)\r
+{\r
+ const char *value = GetMarketName();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue marketName = JSI::CreateString(value);\r
+ return marketName;\r
+}\r
+\r
+JSIValue JSGetProductSeries(void)\r
+{\r
+ const char *value = GetProductSeries();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue productSeries = JSI::CreateString(value);\r
+ return productSeries;\r
+}\r
+\r
+JSIValue JSGetProductModel(void)\r
+{\r
+ const char *value = GetProductModel();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue productModel = JSI::CreateString(value);\r
+ return productModel;\r
+}\r
+\r
+JSIValue JSGetSoftwareModel(void)\r
+{\r
+ const char *value = GetSoftwareModel();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue softwareModel = JSI::CreateString(value);\r
+ return softwareModel;\r
+}\r
+\r
+JSIValue JSGetHardwareModel(void)\r
+{\r
+ const char *value = GetHardwareModel();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue hardwareModel = JSI::CreateString(value);\r
+ return hardwareModel;\r
+}\r
+\r
+JSIValue JSGetHardwareProfile(void)\r
+{\r
+ const char *value = GetHardwareProfile();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue hardwareProfile = JSI::CreateString(value);\r
+ return hardwareProfile;\r
+}\r
+\r
+JSIValue JSGetSerial(void)\r
+{\r
+ const char *value = GetSerial();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue serialNumber = JSI::CreateString(value);\r
+ return serialNumber;\r
+}\r
+\r
+JSIValue JSGetBootloaderVersion(void)\r
+{\r
+ const char *value = GetBootloaderVersion();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue bootloaderVersion = JSI::CreateString(value);\r
+ return bootloaderVersion;\r
+}\r
+\r
+JSIValue JSGetAbiList(void)\r
+{\r
+ const char *value = GetAbiList();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue abiList = JSI::CreateString(value);\r
+ return abiList;\r
+}\r
+\r
+JSIValue JSGetSecurityPatchTag(void)\r
+{\r
+ const char *value = GetSecurityPatchTag();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue securityPatchTag = JSI::CreateString(value);\r
+ return securityPatchTag;\r
+}\r
+\r
+JSIValue JSGetDisplayVersion(void)\r
+{\r
+ const char *value = GetDisplayVersion();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue productVersion = JSI::CreateString(value);\r
+ return productVersion;\r
+}\r
+\r
+JSIValue JSGetIncrementalVersion(void)\r
+{\r
+ const char *value = GetIncrementalVersion();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue incrementalVersion = JSI::CreateString(value);\r
+ return incrementalVersion;\r
+}\r
+\r
+JSIValue JSGetOsReleaseType(void)\r
+{\r
+ const char *value = GetOsReleaseType();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue osReleaseType = JSI::CreateString(value);\r
+ return osReleaseType;\r
+}\r
+\r
+JSIValue JSGetOSFullName(void)\r
+{\r
+ const char *value = GetOSFullName();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+ JSIValue osVersion = JSI::CreateString(value);\r
+ return osVersion;\r
+}\r
+\r
+JSIValue JSGetMajorVersion(void)\r
+{\r
+ int value = GetMajorVersion();\r
+ JSIValue majorVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return majorVersion;\r
+ }\r
+\r
+ majorVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return majorVersion;\r
+}\r
+\r
+JSIValue JSGetSeniorVersion(void)\r
+{\r
+ int value = GetSeniorVersion();\r
+ JSIValue seniorVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return seniorVersion;\r
+ }\r
+\r
+ seniorVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return seniorVersion;\r
+}\r
+\r
+JSIValue JSGetFeatureVersion(void)\r
+{\r
+ int value = GetFeatureVersion();\r
+ JSIValue featureVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return featureVersion;\r
+ }\r
+\r
+ featureVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return featureVersion;\r
+}\r
+\r
+JSIValue JSGetBuildVersion(void)\r
+{\r
+ int value = GetBuildVersion();\r
+ JSIValue buildVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return buildVersion;\r
+ }\r
+\r
+ buildVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return buildVersion;\r
+}\r
+\r
+JSIValue JSGetSdkApiVersion(void)\r
+{\r
+ int value = GetSdkApiVersion();\r
+ JSIValue sdkApiVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return sdkApiVersion;\r
+ }\r
+\r
+ sdkApiVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return sdkApiVersion;\r
+}\r
+\r
+JSIValue JSGetFirstApiVersion(void)\r
+{\r
+ int value = GetFirstApiVersion();\r
+ JSIValue firstApiVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return firstApiVersion;\r
+ }\r
+\r
+ firstApiVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return firstApiVersion;\r
+}\r
+\r
+JSIValue JSGetVersionId(void)\r
+{\r
+ const char *value = GetVersionId();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue versionId = JSI::CreateString(value);\r
+ return versionId;\r
+}\r
+\r
+JSIValue JSGetBuildType(void)\r
+{\r
+ const char *value = GetBuildType();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue buildType = JSI::CreateString(value);\r
+ return buildType;\r
+}\r
+\r
+JSIValue JSGetBuildUser(void)\r
+{\r
+ const char *value = GetBuildUser();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue buildUser = JSI::CreateString(value);\r
+ return buildUser;\r
+}\r
+\r
+JSIValue JSGetBuildHost(void)\r
+{\r
+ const char *value = GetBuildHost();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue buildHost = JSI::CreateString(value);\r
+ return buildHost;\r
+}\r
+\r
+JSIValue JSGetBuildTime(void)\r
+{\r
+ const char *value = GetBuildTime();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue buildTime = JSI::CreateString(value);\r
+ return buildTime;\r
+}\r
+\r
+JSIValue JSGetBuildRootHash(void)\r
+{\r
+ const char *value = GetBuildRootHash();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+\r
+ JSIValue buildRootHash = JSI::CreateString(value);\r
+ return buildRootHash;\r
+}\r
+\r
+JSIValue JSGetDevUdid(void)\r
+{\r
+ char udid[MAX_BUFFER] = { 0 };\r
+ int ret = GetDevUdid(udid, sizeof(udid));\r
+ if (ret < 0) {\r
+ return JSI::CreateUndefined();\r
+ }\r
+ return JSI::CreateString(udid);\r
+}\r
+\r
+JSIValue JSGetDistributionOSName(void)\r
+{\r
+ const char *value = GetDistributionOSName();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+ JSIValue distributionOSName = JSI::CreateString(value);\r
+ return distributionOSName;\r
+}\r
+\r
+JSIValue JSGetDistributionOSVersion(void)\r
+{\r
+ const char *value = GetDistributionOSVersion();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+ JSIValue distributionOSVersion = JSI::CreateString(value);\r
+ return distributionOSVersion;\r
+}\r
+\r
+JSIValue JSGetDistributionOSApiVersion(void)\r
+{\r
+ int value = GetDistributionOSApiVersion();\r
+ JSIValue distributionOSApiVersion = JSI::CreateUndefined();\r
+ if (value < 0) {\r
+ return distributionOSApiVersion;\r
+ }\r
+\r
+ distributionOSApiVersion = JSI::CreateString(std::to_string(value).c_str());\r
+ return distributionOSApiVersion;\r
+}\r
+\r
+JSIValue JSGetDistributionOSReleaseType(void)\r
+{\r
+ const char *value = GetDistributionOSReleaseType();\r
+ if (value == nullptr) {\r
+ value = "";\r
+ }\r
+ JSIValue distributionOSReleaseType = JSI::CreateString(value);\r
+ return distributionOSReleaseType;\r
+}\r
+\r
+void InitDeviceInfoModule(JSIValue exports)\r
+{\r
+ JSI::SetNamedProperty(exports, "deviceType", JSGetDeviceType());\r
+ JSI::SetNamedProperty(exports, "manufacture", JSGetManufacture());\r
+ JSI::SetNamedProperty(exports, "brand", JSGetBrand());\r
+ JSI::SetNamedProperty(exports, "marketName", JSGetMarketName());\r
+ JSI::SetNamedProperty(exports, "productSeries", JSGetProductSeries());\r
+ JSI::SetNamedProperty(exports, "productModel", JSGetProductModel());\r
+ JSI::SetNamedProperty(exports, "softwareModel", JSGetSoftwareModel());\r
+ JSI::SetNamedProperty(exports, "hardwareModel", JSGetHardwareModel());\r
+ JSI::SetNamedProperty(exports, "hardwareProfile", JSGetHardwareProfile());\r
+ JSI::SetNamedProperty(exports, "serial", JSGetSerial());\r
+ JSI::SetNamedProperty(exports, "bootloaderVersion", JSGetBootloaderVersion());\r
+ JSI::SetNamedProperty(exports, "abiList", JSGetAbiList());\r
+ JSI::SetNamedProperty(exports, "securityPatchTag", JSGetSecurityPatchTag());\r
+ JSI::SetNamedProperty(exports, "displayVersion", JSGetDisplayVersion());\r
+ JSI::SetNamedProperty(exports, "incrementalVersion", JSGetIncrementalVersion());\r
+ JSI::SetNamedProperty(exports, "osReleaseType", JSGetOsReleaseType());\r
+ JSI::SetNamedProperty(exports, "osFullName", JSGetOSFullName());\r
+ JSI::SetNamedProperty(exports, "majorVersion", JSGetMajorVersion());\r
+ JSI::SetNamedProperty(exports, "seniorVersion", JSGetSeniorVersion());\r
+ JSI::SetNamedProperty(exports, "featureVersion", JSGetFeatureVersion());\r
+ JSI::SetNamedProperty(exports, "buildVersion", JSGetBuildVersion());\r
+ JSI::SetNamedProperty(exports, "sdkApiVersion", JSGetSdkApiVersion());\r
+ JSI::SetNamedProperty(exports, "firstApiVersion", JSGetFirstApiVersion());\r
+ JSI::SetNamedProperty(exports, "versionId", JSGetVersionId());\r
+ JSI::SetNamedProperty(exports, "buildType", JSGetBuildType());\r
+ JSI::SetNamedProperty(exports, "buildUser", JSGetBuildUser());\r
+ JSI::SetNamedProperty(exports, "buildHost", JSGetBuildHost());\r
+ JSI::SetNamedProperty(exports, "buildTime", JSGetBuildTime());\r
+ JSI::SetNamedProperty(exports, "buildRootHash", JSGetBuildRootHash());\r
+ JSI::SetNamedProperty(exports, "udid", JSGetDevUdid());\r
+ JSI::SetNamedProperty(exports, "distributionOSName", JSGetDistributionOSName());\r
+ JSI::SetNamedProperty(exports, "distributionOSVersion", JSGetDistributionOSVersion());\r
+ JSI::SetNamedProperty(exports, "distributionOSApiVersion", JSGetDistributionOSApiVersion());\r
+ JSI::SetNamedProperty(exports, "distributionOSReleaseType", JSGetDistributionOSReleaseType());\r
+}\r
+} // ACELite\r
+} // OHOS\r
--- /dev/null
+/*\r
+ * Copyright (c) CompanyNameMagicTag. 2024-2025. All rights reserved.\r
+ * Description: http control interfaces\r
+ * Author: Software Group\r
+ * Create: 2025-03-28\r
+ */\r
+\r
+#ifndef HTTP_CLIENT_MODULE_H\r
+#define HTTP_CLIENT_MODULE_H\r
+\r
+#include <stdint.h>\r
+#include "jsi.h"\r
+#include <map>\r
+#include <cstring>\r
+#include "httpclient.h"\r
+\r
+namespace OHOS {\r
+namespace ACELite {\r
+\r
+struct EventCallback {\r
+ JSIValue callback;\r
+ JSIValue context;\r
+ bool isOnce;\r
+};\r
+\r
+struct ThreadNewObj {\r
+ JSIValue thisVal;\r
+ HttpClient *newHttpClient;\r
+ HttpClientData *newHttpClientData;\r
+ char *method;\r
+ char *url;\r
+ JSIValue header;\r
+ JSIValue callback;\r
+};\r
+\r
+// httpClient\r
+constexpr char METHOD[] = "method";\r
+constexpr char HTTP_CLIENT[] = "httpClient";\r
+constexpr char URL[] = "url";\r
+constexpr char HEADER[] = "header";\r
+constexpr char CLIENT_CERT[] = "clientCert";\r
+\r
+// httpClientData\r
+constexpr char HTTP_CLIENT_DATA[] = "httpClientData";\r
+constexpr char POST_BUF[] = "postBuf";\r
+constexpr char EXTRA_DATA[] = "extraData";\r
+\r
+// subscriptions\r
+char* DATA_RECEIVE = "dataReceive";\r
+char* DATA_END = "dataEnd";\r
+char* DATA_RECEIVE_PROGRESS = "dataReceiveProgress";\r
+char* DATA_SEND_PROGRESS = "dataSendProgress";\r
+\r
+class HttpModule final : public MemoryHeap {\r
+public:\r
+ HttpModule() = default;\r
+ ~HttpModule() = default;\r
+ static HttpClient *CreateHttpClient(const JSIValue *args);\r
+ static HttpClientData *CreateHttpClientData(const JSIValue *args);\r
+ static char *HeaderJsonToString(char* headerJson);\r
+ static JSIValue Request(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue RequestInStream(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue CreateHttp(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Once(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Destroy(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static std::map<std::string, EventCallback *> eventCallbacks;\r
+ static std::map<JSIValue, HttpClient *> httpClientInstances;\r
+ static std::map<JSIValue, HttpClientData *> httpClientDataInstances;\r
+ static void OnTerminate();\r
+ static void CheckSubscription(char *type, JSIValue value);\r
+ static int GetErrorCode(int8_t errorCode);\r
+};\r
+void InitHttpModule(JSIValue exports);\r
+\r
+} // namespace ACELite\r
+} // namespace OHOS\r
+\r
+#endif // HTTP_CLIENT_MODULE_H
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef HTTPCLIENT_H
+#define HTTPCLIENT_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef NET_WEBSOCKET_H
+#define NET_WEBSOCKET_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef __NET_WEBSOCKET_DEBUG_H__
+#define __NET_WEBSOCKET_DEBUG_H__
+
+#include <stdio.h>
+
+#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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef _WS_FRAME_H__
+#define _WS_FRAME_H__
+
+#include "net_websocket.h"
+#include <stdint.h>
+
+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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef __WS_LIST_H__
+#define __WS_LIST_H__
+
+#include <stdio.h>
+
+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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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 <lwip/netdb.h>
+#include <unistd.h>
+#include <errno.h>
+
+#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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+#ifndef __RWS_STRING_H__
+#define __RWS_STRING_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *WsStringCopy(const char *str);
+
+char *WsStringCopyLen(const char *str, const size_t len);
+
+void WsStringDelete(char *str);
+
+void WsStringDeleteClean(char **str);
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef __RWS_THREAD_H__
+#define __RWS_THREAD_H__
+
+#include <stdio.h>
+#include <pthread.h>
+
+#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
--- /dev/null
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
+ */
+
+#ifndef NET_WEBSOCKET_TYPE_H
+#define NET_WEBSOCKET_TYPE_H
+
+#include <stdlib.h>
+#include <stdbool.h>
+/**
+ * @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 <b>open</b> message is received.
+ *
+ * @param client WebSocket client fd.
+ * @param openResult Content of the <b>open</b> 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 <b>close</b> 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
#include <securec.h>\r
#include <unistd.h>\r
#include "network_module.h"\r
-#include "BluetoothModel.h"\r
+#include "bluetooth/BluetoothModel.h"\r
#include "msg_center_protocol.h"\r
#include "bts_le_gap.h"\r
#include "network_listener.h"\r
#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
#ifdef FEATURE_MODULE_DEVICE
extern void InitDeviceModule(JSIValue exports);
+extern void InitDeviceInfoModule(JSIValue exports);
#endif
#ifdef FEATURE_MODULE_GEO
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
{"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
#endif
#ifdef FEATURE_MODULE_DEVICE
{"device", InitDeviceModule},
+ {"deviceInfo", InitDeviceInfoModule},
#endif
#ifdef FEATURE_MODULE_GEO
{"geolocation", InitLocationModule},
#ifdef FEATURE_MODULE_BRIGHTNESS
{"brightness", InitBrightnessModule},
#endif
+#ifdef FEATURE_MODULE_HTTP
+ {"net.http", InitHttpClientModule},
+#endif
#ifdef FEATURE_MODULE_BATTERY
{"battery", InitBatteryModule},
#endif
// #ifdef FEATURE_ACELITE_SYSTEM_CAPABILITY
// {"capability", InitCapabilityModule},
// #endif
+#ifdef FEATURE_MODULE_WEBSOCKET
+ {"net.webSocket", InitWebsocketClientModule},
+#endif
#ifdef FEATURE_MODULE_NFC
{"nfc.cardEmulation", NfcHceInitModule},
#endif
// 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)) {
--- /dev/null
+/*\r
+ * Copyright (c) 2025 Huawei Device Co., Ltd.\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <string>\r
+#include "websocket_module.h"\r
+#include "net_websocket.h"\r
+#include <string.h>\r
+#include "ace_log.h"\r
+#include "errcode.h"\r
+#include "cmsis_os2.h"\r
+\r
+namespace OHOS {\r
+namespace ACELite {\r
+\r
+JSIValue ws;\r
+JSIValue close;\r
+JSIValue on;\r
+JSIValue off;\r
+JSIValue send;\r
+JSIValue connect;\r
+\r
+std::map<std::string, EventCallback *> WebsocketModule::eventCallbacks;\r
+\r
+JSIValue WebsocketModule::CreateWebsocket(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ ws = JSI::CreateObject();\r
+ connect = JSI::CreateFunction(WebsocketModule::Connect);\r
+ send = JSI::CreateFunction(WebsocketModule::Send);\r
+ on = JSI::CreateFunction(WebsocketModule::On);\r
+ off = JSI::CreateFunction(WebsocketModule::Off);\r
+ close = JSI::CreateFunction(WebsocketModule::Close);\r
+ JSI::SetNamedProperty(ws, "send", send);\r
+ JSI::SetNamedProperty(ws, "connect", connect);\r
+ JSI::SetNamedProperty(ws, "on", on);\r
+ JSI::SetNamedProperty(ws, "off", off);\r
+ JSI::SetNamedProperty(ws, "close", close);\r
+ return ws;\r
+}\r
+\r
+static void OnOpen(int client)\r
+{\r
+ auto it = WebsocketModule::eventCallbacks.find(std::string("open"));\r
+ if (it == WebsocketModule::eventCallbacks.end()) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnOpen Callback!");\r
+ }\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+ JSIValue err = JSI::CreateBoolean(false);\r
+ JSIValue argv[2] = {err, value};\r
+ if (it != WebsocketModule::eventCallbacks.end()) {\r
+ JSI::CallFunction(it->second->callback, it->second->context, argv, 2);\r
+ }\r
+ JSI::ReleaseValueList(value, err);\r
+}\r
+\r
+static void OnMessage(int client, const char *data, size_t length, bool isFinished)\r
+{\r
+ auto it = WebsocketModule::eventCallbacks.find(std::string("message"));\r
+ if (it == WebsocketModule::eventCallbacks.end()) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnMessage Callback!");\r
+ }\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "length", length);\r
+ JSI::SetStringProperty(value, "data", data);\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+ JSIValue err = JSI::CreateBoolean(false);\r
+ JSIValue argv[2] = {err, value};\r
+ if (it != WebsocketModule::eventCallbacks.end()) {\r
+ JSI::CallFunction(it->second->callback, it->second->context, argv, 2);\r
+ }\r
+ JSI::ReleaseValueList(value, err);\r
+}\r
+\r
+static void OnError(int client, struct WebSocketErrorResult errorResult)\r
+{\r
+ auto it = WebsocketModule::eventCallbacks.find(std::string("error"));\r
+ if (it == WebsocketModule::eventCallbacks.end()) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnError Callback!");\r
+ }\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+ JSIValue err = JSI::CreateBoolean(false);\r
+ JSIValue argv[2] = {err, value};\r
+ if (it != WebsocketModule::eventCallbacks.end()) {\r
+ JSI::CallFunction(it->second->callback, it->second->context, argv, 2);\r
+ }\r
+ JSI::ReleaseValueList(value, err);\r
+}\r
+\r
+static void OnClose(int client)\r
+{\r
+ auto it = WebsocketModule::eventCallbacks.find(std::string("open"));\r
+ if (it == WebsocketModule::eventCallbacks.end()) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Can not find OnError Callback!");\r
+ }\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+ JSIValue err = JSI::CreateBoolean(false);\r
+ JSIValue argv[2] = {err, value};\r
+ if (it != WebsocketModule::eventCallbacks.end()) {\r
+ JSI::CallFunction(it->second->callback, it->second->context, argv, 2);\r
+ }\r
+ JSI::ReleaseValueList(value, err);\r
+}\r
+\r
+JSIValue WebsocketModule::Send(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ int client = JSI::ValueToNumber(JSI::AcquireValue(args[1]));\r
+ char *message = JSI::ValueToString(JSI::AcquireValue(args[0]));\r
+\r
+ size_t length = strlen(message);\r
+ int ret = WebSocketClientSendText(client, message, length);\r
+\r
+ JSIValue isError;\r
+ isError = JSI::CreateBoolean(ret == 0 ? false : true);\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+\r
+ JSIValue callback = JSI::AcquireValue(args[2]);\r
+ JSIValue argv[ARGC_TWO] = {isError, value};\r
+ JSI::CallFunction(callback, thisVal, argv, ARGC_TWO);\r
+ JSI::ReleaseValueList(value, callback);\r
+ JSI::ReleaseString(message);\r
+ return JSI::CreateUndefined();\r
+}\r
+\r
+JSIValue WebsocketModule::Connect(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ char *url = JSI::ValueToString(JSI::AcquireValue(args[0]));\r
+ int client = WebSocketClientConstructor(OnOpen, OnMessage, OnError, OnClose);\r
+ if (client < 0) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConstructor fail!");\r
+ return JSI::CreateUndefined();\r
+ }\r
+\r
+ int ret = WebSocketClientConnect(client, url);\r
+ if (ret != 0) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConnect fail!");\r
+ return JSI::CreateUndefined();\r
+ }\r
+\r
+ JSIValue isError;\r
+ isError = JSI::CreateBoolean(ret == 0 ? false : true);\r
+\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+\r
+ JSIValue callback = JSI::AcquireValue(args[1]);\r
+ JSIValue argv[ARGC_TWO] = {isError, value};\r
+ JSI::CallFunction(callback, thisVal, argv, ARGC_TWO);\r
+ JSI::ReleaseValueList(value, callback, isError);\r
+ JSI::ReleaseString(url);\r
+ return JSI::CreateUndefined();\r
+}\r
+\r
+JSIValue WebsocketModule::Close(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ int client = JSI::ValueToNumber(JSI::AcquireValue(args[0]));\r
+ int ret = WebSocketClientClose(client);\r
+ if (ret != 0) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "WebSocketClientConnect fail!");\r
+ }\r
+ JSIValue isError;\r
+ isError = JSI::CreateBoolean(ret == 0 ? false : true);\r
+ JSIValue value = JSI::CreateObject();\r
+ if (value != nullptr) {\r
+ JSI::SetNumberProperty(value, "client", client);\r
+ }\r
+\r
+ JSIValue callback = JSI::AcquireValue(args[1]);\r
+ JSIValue argv[ARGC_TWO] = {isError, value};\r
+ JSI::CallFunction(callback, thisVal, argv, ARGC_TWO);\r
+ JSI::ReleaseValueList(isError, value, callback);\r
+ return JSI::CreateUndefined();\r
+}\r
+\r
+void WebsocketModule::Destroy()\r
+{\r
+ for (auto it = eventCallbacks.begin(); it != eventCallbacks.end();) {\r
+ auto currentIt = it;\r
+ ++it;\r
+ EventCallback *ec = currentIt->second;\r
+ JSI::ReleaseValue(ec->context);\r
+ JSI::ReleaseValue(ec->callback);\r
+ delete ec;\r
+ eventCallbacks.erase(currentIt);\r
+ }\r
+ eventCallbacks.clear();\r
+\r
+ JSI::ReleaseValue(on);\r
+ JSI::ReleaseValue(off);\r
+ JSI::ReleaseValue(connect);\r
+ JSI::ReleaseValue(close);\r
+ JSI::ReleaseValue(send);\r
+ JSI::ReleaseValue(ws);\r
+}\r
+\r
+JSIValue WebsocketModule::On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ if (argsSize < 2) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Function parameters are not enough!");\r
+ return JSI::CreateBoolean(false);\r
+ }\r
+\r
+ char *eventName = JSI::ValueToString(JSI::AcquireValue(args[0]));\r
+\r
+ auto it = eventCallbacks.find(eventName);\r
+ if (it != eventCallbacks.end()) {\r
+ EventCallback *oldEc = it->second;\r
+ JSI::ReleaseValue(oldEc->callback);\r
+ JSI::ReleaseValue(oldEc->context);\r
+ delete oldEc;\r
+ eventCallbacks.erase(it);\r
+ }\r
+\r
+ JSIValue callback = JSI::AcquireValue(args[1]);\r
+\r
+ EventCallback *ec = new EventCallback;\r
+ if (ec != nullptr) {\r
+ ec->callback = JSI::AcquireValue(callback);\r
+ ec->context = JSI::AcquireValue(thisVal);\r
+ eventCallbacks[eventName] = ec;\r
+ JSI::ReleaseString(eventName);\r
+ JSI::ReleaseValue(callback);\r
+ return JSI::CreateBoolean(true);\r
+ } else {\r
+ JSI::ReleaseString(eventName);\r
+ JSI::ReleaseValue(callback);\r
+ }\r
+\r
+ return JSI::CreateBoolean(false);\r
+}\r
+\r
+JSIValue WebsocketModule::Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)\r
+{\r
+ if (argsSize < 1) {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Function parameters are not enough!");\r
+ return JSI::CreateBoolean(false);\r
+ }\r
+\r
+ char *eventName = JSI::ValueToString(JSI::AcquireValue(args[0]));\r
+\r
+ auto it = eventCallbacks.find(eventName);\r
+ if (it != eventCallbacks.end()) {\r
+ JSI::ReleaseValue(it->second->callback);\r
+ JSI::ReleaseValue(it->second->context);\r
+ delete it->second;\r
+ eventCallbacks.erase(it);\r
+ JSI::ReleaseString(eventName);\r
+ return JSI::CreateBoolean(true);\r
+ }else {\r
+ HILOG_ERROR(HILOG_MODULE_ACE, "Off failed, target not found!");\r
+ JSI::ReleaseString(eventName);\r
+ }\r
+ return JSI::CreateBoolean(false);\r
+}\r
+\r
+void InitWebsocketClientModule(JSIValue exports)\r
+{\r
+ JSI::SetModuleAPI(exports, "createWebsocket", WebsocketModule::CreateWebsocket);\r
+ JSI::SetOnTerminate(exports, WebsocketModule::OnTerminate);\r
+}\r
+\r
+void WebsocketModule::OnTerminate()\r
+{\r
+ WebsocketModule::Destroy();\r
+}\r
+} // namespace ACELite\r
+} // namespace OHOS
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) CompanyNameMagicTag. 2024-2025. All rights reserved.\r
+ * Description: http control interfaces\r
+ * Author: Software Group\r
+ * Create: 2025-06-06\r
+ */\r
+\r
+#ifndef WEBSOCKET_CLIENT_MODULE_H\r
+#define WEBSOCKET_CLIENT_MODULE_H\r
+\r
+#include <stdint.h>\r
+#include "jsi.h"\r
+#include <map>\r
+#include <cstring>\r
+\r
+namespace OHOS {\r
+namespace ACELite {\r
+\r
+struct EventCallback {\r
+ JSIValue callback;\r
+ JSIValue context;\r
+};\r
+\r
+class WebsocketModule final : public MemoryHeap {\r
+public:\r
+ WebsocketModule() = default;\r
+ ~WebsocketModule() = default;\r
+ static JSIValue CreateWebsocket(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Connect(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Send(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Close(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue On(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static JSIValue Off(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
+ static std::map<std::string, EventCallback *> eventCallbacks;\r
+ static void Destroy();\r
+ static void OnTerminate();\r
+};\r
+void InitWebsocketModule(JSIValue exports);\r
+\r
+} // namespace ACELite\r
+} // namespace OHOS\r
+\r
+#endif // WEBSOCKET_CLIENT_MODULE_H
\ No newline at end of file
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);
handle exception\r
*/\r
static void ExceptionStop(void);\r
+\r
+ /**\r
+ * Cancel\r
+ */\r
+ static JSIValue Cancel(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);\r
};\r
\r
void InitAudioCapturerModule(JSIValue exports);\r
${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
)
set(PUBLIC_DEFINES
LWIP_CONFIG_FILE=\"lwip/lwipopts_default.h\"
+ MBEDTLD_USE_LWIP
+ MBEDTLS_NET_C
)
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
#endif
#ifndef LWIP_COMPAT_SOCKETS
-#define LWIP_COMPAT_SOCKETS 2
+#define LWIP_COMPAT_SOCKETS 1
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#endif
#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
--- /dev/null
+/*
+ * 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 <sys/socket.h>
+#include <poll.h>
+#include <netinet/tcp.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <limits.h>
+#include <fcntl.h>
+#include_next <lwip/sockets.h>
+
+#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_ */
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
}
}
- 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) {
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;
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);
}
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).
{
#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 */
};
#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 */