From 6e97995595a04cb95ba4d3fc14d96dbcce0b7670 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 21 Aug 2023 14:59:43 +0800 Subject: [PATCH 01/28] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E4=BE=9D=E8=B5=96core=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- bundle.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle.json b/bundle.json index be90aac..f37affa 100644 --- a/bundle.json +++ b/bundle.json @@ -22,7 +22,6 @@ "ram": "50KB", "deps": { "components": [ - "core_service", "hisysevent", "hilog", "napi", -- Gitee From 99dc06b90b892954a674a14e78a5ed232e15a822 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Sat, 23 Sep 2023 16:56:04 +0800 Subject: [PATCH 02/28] =?UTF-8?q?fix=20begetutilsexported=5Fheader=5Ffiles?= =?UTF-8?q?=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhongning5 Change-Id: I3ab5787d9ccd00529e3d1703c2052e98787cba43 --- frameworks/config_policy/BUILD.gn | 2 +- test/unittest/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/config_policy/BUILD.gn b/frameworks/config_policy/BUILD.gn index cd9a8bb..7aea350 100644 --- a/frameworks/config_policy/BUILD.gn +++ b/frameworks/config_policy/BUILD.gn @@ -23,7 +23,7 @@ config("config_policy_config") { include_dirs = [ "../../interfaces/inner_api/include", "//third_party/bounds_checking_function/include", - "$STARTUP_INIT_ROOT_DIR/services/include/param", + "$STARTUP_INIT_ROOT_DIR/interfaces/innerkits/include/param", "$TEL_CORESERVICE_ROOT_DIR/utils/common/include", ] } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index d5285a3..fc2f408 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -22,7 +22,7 @@ if (defined(ohos_lite)) { config_policy_sources = [ "config_policy_utils_test.cpp" ] config_policy_include_dirs = [ "../../interfaces/inner_api/include", - "$STARTUP_INIT_ROOT_DIR/services/include/param", + "$STARTUP_INIT_ROOT_DIR/interfaces/innerkits/include/param", "$TEL_CORESERVICE_ROOT_DIR/utils/common/include", ] config_policy_deps = [ "../../frameworks/config_policy:configpolicy_util" ] -- Gitee From 0854de0c6d97bdf4f802935e918cd57b254a5740 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Sat, 7 Oct 2023 18:57:21 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E9=9A=8FX=20js=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../kits/js/include/config_policy_napi.h | 13 +- interfaces/kits/js/src/config_policy_napi.cpp | 188 +++++++++++++++++- 2 files changed, 196 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index edc0f9e..38248ff 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,6 +33,8 @@ struct ConfigAsyncContext { CreateNapiValue createValueFunc_; std::string relPath_; + int32_t followMode_; + std::string extra_; std::string pathValue_; std::vector paths_; }; @@ -46,18 +48,27 @@ public: private: static napi_value NAPIGetOneCfgFile(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgFiles(napi_env env, napi_callback_info info); + static napi_value NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info); + static napi_value NAPIGetCfgFilesEx(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirList(napi_env env, napi_callback_info info); static napi_value CreateUndefined(napi_env env); static std::string GetStringFromNAPI(napi_env env, napi_value value); static napi_value HandleAsyncWork(napi_env env, ConfigAsyncContext *context, std::string workName, napi_async_execute_callback execute, napi_async_complete_callback complete); + static napi_value GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, + const std::string &workName, napi_async_execute_callback execute); static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType); static void NativeGetOneCfgFile(napi_env env, void *data); static void NativeGetCfgFiles(napi_env env, void *data); + static void NativeGetOneCfgFileEx(napi_env env, void *data); + static void NativeGetCfgFilesEx(napi_env env, void *data); static void NativeGetCfgDirList(napi_env env, void *data); static void NativeCallbackComplete(napi_env env, napi_status status, void *data); static napi_value ParseRelPath(napi_env env, std::string ¶m, napi_value args); + static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args); + static napi_value ParseExtra(napi_env env, std::string ¶m, napi_value args); static void CreateArraysValueFunc(ConfigAsyncContext &context); + static void CreateFollowXModeObject(napi_env env, napi_value value); static napi_value ThrowNapiError(napi_env env, int32_t errCode, const std::string &errMessage); }; } // namespace ConfigPolicy diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 60b371c..ce53d02 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,8 +28,12 @@ using namespace OHOS::HiviewDFX; static constexpr size_t ARGS_SIZE_ONE = 1; static constexpr size_t ARGS_SIZE_TWO = 2; +static constexpr size_t ARGS_SIZE_THREE = 3; +static constexpr size_t ARGS_SIZE_FOUR = 4; static constexpr int32_t ARR_INDEX_ZERO = 0; static constexpr int32_t ARR_INDEX_ONE = 1; +static constexpr int32_t ARR_INDEX_TWO = 2; +static constexpr int32_t ARR_INDEX_THREE = 3; static constexpr int32_t NAPI_RETURN_ZERO = 0; static constexpr int32_t NAPI_RETURN_ONE = 1; // Param Error Code @@ -38,15 +42,47 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "ConfigPolicyJs" }; napi_value ConfigPolicyNapi::Init(napi_env env, napi_value exports) { + napi_value nFollowXMode = nullptr; + NAPI_CALL(env, napi_create_object(env, &nFollowXMode)); + CreateFollowXModeObject(env, nFollowXMode); + napi_property_descriptor property[] = { DECLARE_NAPI_FUNCTION("getOneCfgFile", ConfigPolicyNapi::NAPIGetOneCfgFile), DECLARE_NAPI_FUNCTION("getCfgFiles", ConfigPolicyNapi::NAPIGetCfgFiles), - DECLARE_NAPI_FUNCTION("getCfgDirList", ConfigPolicyNapi::NAPIGetCfgDirList) + DECLARE_NAPI_FUNCTION("getOneCfgFileEx", ConfigPolicyNapi::NAPIGetOneCfgFileEx), + DECLARE_NAPI_FUNCTION("getCfgFilesEx", ConfigPolicyNapi::NAPIGetCfgFilesEx), + DECLARE_NAPI_FUNCTION("getCfgDirList", ConfigPolicyNapi::NAPIGetCfgDirList), + + DECLARE_NAPI_PROPERTY("FollowXMode", nFollowXMode) }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(property) / sizeof(property[0]), property)); return exports; } +void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) +{ + napi_value nDefaultMode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_DEFAULT), &nDefaultMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "DEFAULT", nDefaultMode)); + napi_value nNoFollowMode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_NO_FOLLOW), &nNoFollowMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "NO_FOLLOW", nNoFollowMode)); + napi_value nSimDefaultMode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_DEFAULT), + &nSimDefaultMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "SIM_DEFAULT", nSimDefaultMode)); + napi_value nSim1Mode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_1), &nSim1Mode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "SIM_1", nSim1Mode)); + napi_value nSim2Mode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_2), &nSim2Mode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "SIM_2", nSim2Mode)); + napi_value nUserDefineMode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_USER_DEFINE), + &nUserDefineMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "USER_DEFINE", nUserDefineMode)); +} + napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info info) { size_t argc = ARGS_SIZE_TWO; @@ -59,7 +95,9 @@ napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info } auto asyncContext = std::make_unique(); - ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]); + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { + return nullptr; + } if (argc == ARGS_SIZE_TWO) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); if (!matchFlag) { @@ -71,6 +109,61 @@ napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info NativeCallbackComplete); } +napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, + const std::string &workName, napi_async_execute_callback execute) +{ + size_t argc = ARGS_SIZE_FOUR; + napi_value argv[ARGS_SIZE_FOUR] = {nullptr}; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (argc < ARGS_SIZE_TWO) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); + } + + auto asyncContext = std::make_unique(); + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr || + ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + return nullptr; + } + if (argc == ARGS_SIZE_TWO) { + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINE) { + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The followMode is USER_DEFINE, extra must be set."); + } + } + if (argc == ARGS_SIZE_THREE) { + bool matchFlag = MatchValueType(env, argv[ARR_INDEX_TWO], napi_function); + if (matchFlag) { + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINE) { + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The followMode is USER_DEFINE, extra must be set."); + } + napi_create_reference(env, argv[ARR_INDEX_TWO], NAPI_RETURN_ONE, &asyncContext->callbackRef_); + } + if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { + return nullptr; + } + } + if (argc >= ARGS_SIZE_FOUR) { + if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { + return nullptr; + } + bool matchFlag = MatchValueType(env, argv[ARR_INDEX_THREE], napi_function); + if (!matchFlag) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The fourth parameter must be Callback."); + } + napi_create_reference(env, argv[ARR_INDEX_THREE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); + } + + return HandleAsyncWork(env, asyncContext.release(), workName, execute, NativeCallbackComplete); +} + +napi_value ConfigPolicyNapi::NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info) +{ + return GetOneCfgFileOrAllCfgFilesEx(env, info, "NAPIGetOneCfgFileEx", NativeGetOneCfgFileEx); +} + napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) { size_t argc = ARGS_SIZE_TWO; @@ -83,7 +176,9 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info in } auto asyncContext = std::make_unique(); - ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]); + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { + return nullptr; + } if (argc == ARGS_SIZE_TWO) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); if (!matchFlag) { @@ -94,6 +189,11 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info in return HandleAsyncWork(env, asyncContext.release(), "NAPIGetCfgFiles", NativeGetCfgFiles, NativeCallbackComplete); } +napi_value ConfigPolicyNapi::NAPIGetCfgFilesEx(napi_env env, napi_callback_info info) +{ + return GetOneCfgFileOrAllCfgFilesEx(env, info, "NAPIGetCfgFilesEx", NativeGetCfgFilesEx); +} + napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) { size_t argc = ARGS_SIZE_ONE; @@ -187,6 +287,25 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) }; } +void ConfigPolicyNapi::NativeGetOneCfgFileEx(napi_env env, void *data) +{ + if (data == nullptr) { + HiLog::Error(LABEL, "data is nullptr"); + return; + } + ConfigAsyncContext *asyncCallbackInfo = static_cast(data); + char outBuf[MAX_PATH_LEN] = {0}; + GetOneCfgFileEx(asyncCallbackInfo->relPath_.c_str(), outBuf, MAX_PATH_LEN, + asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); + asyncCallbackInfo->pathValue_ = std::string(outBuf); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileEx", ""); + asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { + napi_value result; + NAPI_CALL(env, napi_create_string_utf8(env, context.pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); + return result; + }; +} + void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) { if (data == nullptr) { @@ -206,6 +325,26 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); } +void ConfigPolicyNapi::NativeGetCfgFilesEx(napi_env env, void *data) +{ + if (data == nullptr) { + HiLog::Error(LABEL, "data is nullptr"); + return; + } + + ConfigAsyncContext *asyncCallbackInfo = static_cast(data); + CfgFiles *cfgFiles = GetCfgFilesEx(asyncCallbackInfo->relPath_.c_str(), + asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { + asyncCallbackInfo->paths_.push_back(cfgFiles->paths[i]); + } + } + FreeCfgFiles(cfgFiles); + CreateArraysValueFunc(*asyncCallbackInfo); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesEx", ""); +} + void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) { if (data == nullptr) { @@ -281,6 +420,47 @@ napi_value ConfigPolicyNapi::ParseRelPath(napi_env env, std::string ¶m, napi return result; } +napi_value ConfigPolicyNapi::ParseExtra(napi_env env, std::string ¶m, napi_value args) +{ + bool matchFlag = MatchValueType(env, args, napi_string); + if (!matchFlag) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The type of extra must be string."); + } + param = GetStringFromNAPI(env, args); + napi_value result = nullptr; + NAPI_CALL(env, napi_create_int32(env, NAPI_RETURN_ONE, &result)); + return result; +} + +napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_value args) +{ + bool matchFlag = MatchValueType(env, args, napi_number); + if (!matchFlag) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The type of followXMode must be number."); + } + if (napi_get_value_int32(env, args, ¶m) != napi_ok) { + HiLog::Error(LABEL, "can not get int32 value."); + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. Get the value of followXMode failed."); + } + + switch (param) { + case FOLLOWX_MODE_DEFAULT: + case FOLLOWX_MODE_NO_FOLLOW: + case FOLLOWX_MODE_SIM_DEFAULT: + case FOLLOWX_MODE_SIM_1: + case FOLLOWX_MODE_SIM_2: + case FOLLOWX_MODE_USER_DEFINE: + break; + default: + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The value of followXMode should be in the enumeration value of FollowXMode."); + } + + napi_value result = nullptr; + NAPI_CALL(env, napi_create_int32(env, NAPI_RETURN_ONE, &result)); + return result; +} + napi_value ConfigPolicyNapi::ThrowNapiError(napi_env env, int32_t errCode, const std::string &errMessage) { napi_throw_error(env, std::to_string(errCode).c_str(), errMessage.c_str()); -- Gitee From 5ca1b740ef286fd66e0e25a2ef753deae61e7bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=87=AF=E6=98=8E?= Date: Sat, 7 Oct 2023 11:15:18 +0000 Subject: [PATCH 04/28] =?UTF-8?q?inner=20api=20=E7=BA=B3=E5=85=A5SASDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谢凯明 --- frameworks/config_policy/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/config_policy/BUILD.gn b/frameworks/config_policy/BUILD.gn index cd9a8bb..978fed6 100644 --- a/frameworks/config_policy/BUILD.gn +++ b/frameworks/config_policy/BUILD.gn @@ -62,6 +62,7 @@ if (defined(ohos_lite) && ohos_kernel_type == "liteos_m") { innerapi_tags = [ "chipsetsdk", "platformsdk", + "sasdk", ] subsystem_name = "customization" part_name = "config_policy" -- Gitee From 1fc71ced3fd5a22eb1abef4cd2d877db975f3b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=87=AF=E6=98=8E?= Date: Sun, 8 Oct 2023 09:07:39 +0000 Subject: [PATCH 05/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9napi=20error=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谢凯明 --- interfaces/kits/js/src/config_policy_napi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index ce53d02..3c9d20a 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -436,11 +436,11 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ { bool matchFlag = MatchValueType(env, args, napi_number); if (!matchFlag) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The type of followXMode must be number."); + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The type of followMode must be number."); } if (napi_get_value_int32(env, args, ¶m) != napi_ok) { HiLog::Error(LABEL, "can not get int32 value."); - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. Get the value of followXMode failed."); + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. Get the value of followMode failed."); } switch (param) { @@ -453,7 +453,7 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ break; default: return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The value of followXMode should be in the enumeration value of FollowXMode."); + "Parameter error. The value of followMode should be in the enumeration value of FollowXMode."); } napi_value result = nullptr; -- Gitee From 1e14795f3d809b72c65de27da764febfc24aa045 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 9 Oct 2023 10:44:23 +0800 Subject: [PATCH 06/28] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 3c9d20a..4b3c876 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -445,10 +445,15 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ switch (param) { case FOLLOWX_MODE_DEFAULT: + [[fallthrough]]; case FOLLOWX_MODE_NO_FOLLOW: + [[fallthrough]]; case FOLLOWX_MODE_SIM_DEFAULT: + [[fallthrough]]; case FOLLOWX_MODE_SIM_1: + [[fallthrough]]; case FOLLOWX_MODE_SIM_2: + [[fallthrough]]; case FOLLOWX_MODE_USER_DEFINE: break; default: -- Gitee From d5c5f74a0b1411505f9bc8ae667f964f5ae2d541 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Wed, 11 Oct 2023 09:49:59 +0800 Subject: [PATCH 07/28] =?UTF-8?q?=E9=9A=8FX=E8=A7=84=E5=88=99=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../config_policy/src/config_policy_utils.c | 6 +++--- .../inner_api/include/config_policy_utils.h | 6 +++--- interfaces/kits/js/src/config_policy_napi.cpp | 16 ++++++++-------- test/unittest/config_policy_utils_test.cpp | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index c75626a..06c4187 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -213,7 +213,7 @@ static char *GetFollowXRule(const char *relPath, int *mode) modeStr++; *mode = atoi(modeStr); } - if (*mode == FOLLOWX_MODE_USER_DEFINE && modeStr) { + if (*mode == FOLLOWX_MODE_USER_DEFINED && modeStr) { addPath = strchr(modeStr, SEP_FOR_X_PARAM); if (addPath) { addPath++; // skip ',' get extra info @@ -234,7 +234,7 @@ static SplitedStr *GetFollowXPathByMode(const char *relPath, int followMode, con const char *extraPath = extra; if (followMode == FOLLOWX_MODE_DEFAULT) { modePathFromCfg = GetFollowXRule(relPath, &followMode); - if (followMode == FOLLOWX_MODE_USER_DEFINE && modePathFromCfg && *modePathFromCfg) { + if (followMode == FOLLOWX_MODE_USER_DEFINED && modePathFromCfg && *modePathFromCfg) { extraPath = modePathFromCfg; } } @@ -249,7 +249,7 @@ static SplitedStr *GetFollowXPathByMode(const char *relPath, int followMode, con case FOLLOWX_MODE_SIM_2: followXPath = GetOpkeyPath(FOLLOWX_MODE_SIM_2); break; - case FOLLOWX_MODE_USER_DEFINE: + case FOLLOWX_MODE_USER_DEFINED: followXPath = (extraPath && *extraPath) ? strdup(extraPath) : NULL; break; default: diff --git a/interfaces/inner_api/include/config_policy_utils.h b/interfaces/inner_api/include/config_policy_utils.h index ec6fcb5..30c4c5f 100644 --- a/interfaces/inner_api/include/config_policy_utils.h +++ b/interfaces/inner_api/include/config_policy_utils.h @@ -42,8 +42,8 @@ extern "C" { // follow_rule,etc/xml/config2.xml,100,etc/carrier/${keyname:-value} // Follow rule in followx_file_list.cfg, which stored in param variant #define FOLLOWX_MODE_DEFAULT 0 -// Not use any follow rule, even exsit followx_file_list.cfg -#define FOLLOWX_MODE_NO_FOLLOW 1 +// Not use any follow rule, even exist followx_file_list.cfg +#define FOLLOWX_MODE_NO_RULE_FOLLOWED 1 // Follow rule by default slot #define FOLLOWX_MODE_SIM_DEFAULT 10 // Follow rule by slot 1 @@ -52,7 +52,7 @@ extern "C" { #define FOLLOWX_MODE_SIM_2 12 // User defined follow rule, get follow_rule_add_path from @param extra // Notice: Follow rule in followx_file_list.cfg will be ignored. -#define FOLLOWX_MODE_USER_DEFINE 100 +#define FOLLOWX_MODE_USER_DEFINED 100 // Config Files struct CfgFiles { diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 4b3c876..a9483f6 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -65,8 +65,8 @@ void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_DEFAULT), &nDefaultMode)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "DEFAULT", nDefaultMode)); napi_value nNoFollowMode; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_NO_FOLLOW), &nNoFollowMode)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "NO_FOLLOW", nNoFollowMode)); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_NO_RULE_FOLLOWED), &nNoFollowMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "NO_RULE_FOLLOWED", nNoFollowMode)); napi_value nSimDefaultMode; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_DEFAULT), &nSimDefaultMode)); @@ -78,9 +78,9 @@ void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_2), &nSim2Mode)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "SIM_2", nSim2Mode)); napi_value nUserDefineMode; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_USER_DEFINE), + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_USER_DEFINED), &nUserDefineMode)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "USER_DEFINE", nUserDefineMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "USER_DEFINED", nUserDefineMode)); } napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info info) @@ -127,7 +127,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_cal return nullptr; } if (argc == ARGS_SIZE_TWO) { - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINE) { + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The followMode is USER_DEFINE, extra must be set."); } @@ -135,7 +135,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_cal if (argc == ARGS_SIZE_THREE) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_TWO], napi_function); if (matchFlag) { - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINE) { + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The followMode is USER_DEFINE, extra must be set."); } @@ -446,7 +446,7 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ switch (param) { case FOLLOWX_MODE_DEFAULT: [[fallthrough]]; - case FOLLOWX_MODE_NO_FOLLOW: + case FOLLOWX_MODE_NO_RULE_FOLLOWED: [[fallthrough]]; case FOLLOWX_MODE_SIM_DEFAULT: [[fallthrough]]; @@ -454,7 +454,7 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ [[fallthrough]]; case FOLLOWX_MODE_SIM_2: [[fallthrough]]; - case FOLLOWX_MODE_USER_DEFINE: + case FOLLOWX_MODE_USER_DEFINED: break; default: return ThrowNapiError(env, PARAM_ERROR, diff --git a/test/unittest/config_policy_utils_test.cpp b/test/unittest/config_policy_utils_test.cpp index f5aa2a9..f38d113 100644 --- a/test/unittest/config_policy_utils_test.cpp +++ b/test/unittest/config_policy_utils_test.cpp @@ -70,7 +70,7 @@ bool TestGetCfgFile(const char *testPathSuffix, int type, const char *extra) HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest001, TestSize.Level1) { const char *testPathSuffix = "etc/custxmltest/none.xml"; - EXPECT_FALSE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL)); + EXPECT_FALSE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_RULE_FOLLOWED, NULL)); } /** @@ -82,7 +82,7 @@ HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest001, TestSize.Level1) HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest002, TestSize.Level1) { const char *testPathSuffix = "etc/custxmltest/system.xml"; - EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL)); + EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_RULE_FOLLOWED, NULL)); } /** @@ -94,7 +94,7 @@ HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest002, TestSize.Level1) HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest003, TestSize.Level1) { const char *testPathSuffix = "etc/custxmltest/user.xml"; - EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL)); + EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_RULE_FOLLOWED, NULL)); } /** @@ -106,7 +106,7 @@ HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest003, TestSize.Level1) HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest004, TestSize.Level1) { const char *testPathSuffix = "etc/custxmltest/both.xml"; - EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL)); + EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_RULE_FOLLOWED, NULL)); } /** @@ -191,7 +191,7 @@ HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest010, TestSize.Level1) extraString.append("etc/carrier/${").append(CUST_OPKEY1).append(":-46060},etc/carrier/${") .append(CUST_OPKEY0).append("}/etc/${testkey:-custxmltest}"); std::cout << "extra: " << extraString << std::endl; - EXPECT_TRUE(TestGetCfgFile("etc/custxmltest/user.xml", FOLLOWX_MODE_USER_DEFINE, extraString.c_str())); - EXPECT_TRUE(TestGetCfgFile("etc/custxmltest/both.xml", FOLLOWX_MODE_USER_DEFINE, extraString.c_str())); + EXPECT_TRUE(TestGetCfgFile("etc/custxmltest/user.xml", FOLLOWX_MODE_USER_DEFINED, extraString.c_str())); + EXPECT_TRUE(TestGetCfgFile("etc/custxmltest/both.xml", FOLLOWX_MODE_USER_DEFINED, extraString.c_str())); } } // namespace OHOS -- Gitee From 4218e36ba7df8409d4e3f68c6eeb74c9e5e39dfb Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Wed, 11 Oct 2023 11:49:38 +0800 Subject: [PATCH 08/28] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=8C=E5=AE=BD?= =?UTF-8?q?=E8=B6=85=E5=87=BA120=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index a9483f6..7968a04 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -65,7 +65,8 @@ void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_DEFAULT), &nDefaultMode)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "DEFAULT", nDefaultMode)); napi_value nNoFollowMode; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_NO_RULE_FOLLOWED), &nNoFollowMode)); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_NO_RULE_FOLLOWED), + &nNoFollowMode)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "NO_RULE_FOLLOWED", nNoFollowMode)); napi_value nSimDefaultMode; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, static_cast(FOLLOWX_MODE_SIM_DEFAULT), -- Gitee From 6b5e585dd3ad4b0cdb39bf7ed7e5b76ce82d6a51 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Fri, 13 Oct 2023 17:29:40 +0800 Subject: [PATCH 09/28] =?UTF-8?q?=E9=9A=8FX=E6=8E=A5=E5=8F=A3=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E4=B8=BA=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E6=97=A7=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../kits/js/include/config_policy_napi.h | 20 +- interfaces/kits/js/src/config_policy_napi.cpp | 184 ++++++++++++------ 2 files changed, 138 insertions(+), 66 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index 38248ff..73bb17b 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -46,27 +46,35 @@ public: static napi_value Init(napi_env env, napi_value exports); private: + typedef napi_value (*NapiFunction)(napi_env env, std::shared_ptr context); + static napi_value NAPIGetOneCfgFile(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgFiles(napi_env env, napi_callback_info info); - static napi_value NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info); - static napi_value NAPIGetCfgFilesEx(napi_env env, napi_callback_info info); + static napi_value NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info); + static napi_value NAPIGetCfgFilesSync(napi_env env, napi_callback_info info); + static napi_value NAPIGetOneCfgFileExSync(napi_env env, napi_callback_info info); + static napi_value NAPIGetCfgFilesExSync(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirList(napi_env env, napi_callback_info info); + static napi_value NAPIGetCfgDirListSync(napi_env env, napi_callback_info info); static napi_value CreateUndefined(napi_env env); static std::string GetStringFromNAPI(napi_env env, napi_value value); static napi_value HandleAsyncWork(napi_env env, ConfigAsyncContext *context, std::string workName, napi_async_execute_callback execute, napi_async_complete_callback complete); - static napi_value GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, - const std::string &workName, napi_async_execute_callback execute); + static napi_value GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, NapiFunction func); static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType); static void NativeGetOneCfgFile(napi_env env, void *data); static void NativeGetCfgFiles(napi_env env, void *data); - static void NativeGetOneCfgFileEx(napi_env env, void *data); - static void NativeGetCfgFilesEx(napi_env env, void *data); static void NativeGetCfgDirList(napi_env env, void *data); + static napi_value NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context); + static napi_value NativeGetCfgFilesSync(napi_env env, std::shared_ptr context); + static napi_value NativeGetCfgDirListSync(napi_env env, std::shared_ptr context); + static napi_value NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context); + static napi_value NativeGetCfgFilesExSync(napi_env env, std::shared_ptr context); static void NativeCallbackComplete(napi_env env, napi_status status, void *data); static napi_value ParseRelPath(napi_env env, std::string ¶m, napi_value args); static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args); static napi_value ParseExtra(napi_env env, std::string ¶m, napi_value args); + static napi_value CreateArraysValue(napi_env env, std::shared_ptr context); static void CreateArraysValueFunc(ConfigAsyncContext &context); static void CreateFollowXModeObject(napi_env env, napi_value value); static napi_value ThrowNapiError(napi_env env, int32_t errCode, const std::string &errMessage); diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 7968a04..9aaf346 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -29,11 +29,9 @@ using namespace OHOS::HiviewDFX; static constexpr size_t ARGS_SIZE_ONE = 1; static constexpr size_t ARGS_SIZE_TWO = 2; static constexpr size_t ARGS_SIZE_THREE = 3; -static constexpr size_t ARGS_SIZE_FOUR = 4; static constexpr int32_t ARR_INDEX_ZERO = 0; static constexpr int32_t ARR_INDEX_ONE = 1; static constexpr int32_t ARR_INDEX_TWO = 2; -static constexpr int32_t ARR_INDEX_THREE = 3; static constexpr int32_t NAPI_RETURN_ZERO = 0; static constexpr int32_t NAPI_RETURN_ONE = 1; // Param Error Code @@ -48,10 +46,13 @@ napi_value ConfigPolicyNapi::Init(napi_env env, napi_value exports) napi_property_descriptor property[] = { DECLARE_NAPI_FUNCTION("getOneCfgFile", ConfigPolicyNapi::NAPIGetOneCfgFile), + DECLARE_NAPI_FUNCTION("getOneCfgFileSync", ConfigPolicyNapi::NAPIGetOneCfgFileSync), + DECLARE_NAPI_FUNCTION("getOneCfgFileExSync", ConfigPolicyNapi::NAPIGetOneCfgFileExSync), DECLARE_NAPI_FUNCTION("getCfgFiles", ConfigPolicyNapi::NAPIGetCfgFiles), - DECLARE_NAPI_FUNCTION("getOneCfgFileEx", ConfigPolicyNapi::NAPIGetOneCfgFileEx), - DECLARE_NAPI_FUNCTION("getCfgFilesEx", ConfigPolicyNapi::NAPIGetCfgFilesEx), + DECLARE_NAPI_FUNCTION("getCfgFilesSync", ConfigPolicyNapi::NAPIGetCfgFilesSync), + DECLARE_NAPI_FUNCTION("getCfgFilesExSync", ConfigPolicyNapi::NAPIGetCfgFilesExSync), DECLARE_NAPI_FUNCTION("getCfgDirList", ConfigPolicyNapi::NAPIGetCfgDirList), + DECLARE_NAPI_FUNCTION("getCfgDirListSync", ConfigPolicyNapi::NAPIGetCfgDirListSync), DECLARE_NAPI_PROPERTY("FollowXMode", nFollowXMode) }; @@ -110,11 +111,27 @@ napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info NativeCallbackComplete); } -napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, - const std::string &workName, napi_async_execute_callback execute) +napi_value ConfigPolicyNapi::NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info) { - size_t argc = ARGS_SIZE_FOUR; - napi_value argv[ARGS_SIZE_FOUR] = {nullptr}; + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {nullptr}; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (argc < ARGS_SIZE_ONE) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); + } + auto asyncContext = std::make_shared(); + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { + return nullptr; + } + return NativeGetOneCfgFileSync(env, asyncContext); +} + +napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, NapiFunction func) +{ + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; napi_value thisVar = nullptr; void *data = nullptr; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); @@ -122,7 +139,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_cal return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); } - auto asyncContext = std::make_unique(); + auto asyncContext = std::make_shared(); if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr || ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { return nullptr; @@ -130,39 +147,20 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_cal if (argc == ARGS_SIZE_TWO) { if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The followMode is USER_DEFINE, extra must be set."); + "Parameter error. The followMode is USER_DEFINED, extra must be set."); } } - if (argc == ARGS_SIZE_THREE) { - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_TWO], napi_function); - if (matchFlag) { - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { - return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The followMode is USER_DEFINE, extra must be set."); - } - napi_create_reference(env, argv[ARR_INDEX_TWO], NAPI_RETURN_ONE, &asyncContext->callbackRef_); - } + if (argc >= ARGS_SIZE_THREE) { if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } } - if (argc >= ARGS_SIZE_FOUR) { - if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { - return nullptr; - } - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_THREE], napi_function); - if (!matchFlag) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The fourth parameter must be Callback."); - } - napi_create_reference(env, argv[ARR_INDEX_THREE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); - } - - return HandleAsyncWork(env, asyncContext.release(), workName, execute, NativeCallbackComplete); + return func(env, asyncContext); } -napi_value ConfigPolicyNapi::NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetOneCfgFileExSync(napi_env env, napi_callback_info info) { - return GetOneCfgFileOrAllCfgFilesEx(env, info, "NAPIGetOneCfgFileEx", NativeGetOneCfgFileEx); + return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetOneCfgFileExSync); } napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) @@ -190,9 +188,26 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info in return HandleAsyncWork(env, asyncContext.release(), "NAPIGetCfgFiles", NativeGetCfgFiles, NativeCallbackComplete); } -napi_value ConfigPolicyNapi::NAPIGetCfgFilesEx(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_info info) { - return GetOneCfgFileOrAllCfgFilesEx(env, info, "NAPIGetCfgFilesEx", NativeGetCfgFilesEx); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {nullptr}; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (argc < ARGS_SIZE_ONE) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); + } + auto asyncContext = std::make_shared(); + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { + return nullptr; + } + return NativeGetCfgFilesSync(env, asyncContext); +} + +napi_value ConfigPolicyNapi::NAPIGetCfgFilesExSync(napi_env env, napi_callback_info info) +{ + return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetCfgFilesExSync); } napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) @@ -215,6 +230,12 @@ napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info NativeCallbackComplete); } +napi_value ConfigPolicyNapi::NAPIGetCfgDirListSync(napi_env env, napi_callback_info info) +{ + auto asyncContext = std::make_shared(); + return NativeGetCfgDirListSync(env, asyncContext); +} + napi_value ConfigPolicyNapi::CreateUndefined(napi_env env) { napi_value result = nullptr; @@ -288,23 +309,27 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) }; } -void ConfigPolicyNapi::NativeGetOneCfgFileEx(napi_env env, void *data) +napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context) { - if (data == nullptr) { - HiLog::Error(LABEL, "data is nullptr"); - return; - } - ConfigAsyncContext *asyncCallbackInfo = static_cast(data); char outBuf[MAX_PATH_LEN] = {0}; - GetOneCfgFileEx(asyncCallbackInfo->relPath_.c_str(), outBuf, MAX_PATH_LEN, - asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); - asyncCallbackInfo->pathValue_ = std::string(outBuf); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileEx", ""); - asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { - napi_value result; - NAPI_CALL(env, napi_create_string_utf8(env, context.pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); - return result; - }; + GetOneCfgFile(context->relPath_.c_str(), outBuf, MAX_PATH_LEN); + context->pathValue_ = std::string(outBuf); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); + napi_value result = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); + return result; +} + +napi_value ConfigPolicyNapi::NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context) +{ + char outBuf[MAX_PATH_LEN] = {0}; + GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, + context->followMode_, context->extra_.c_str()); + context->pathValue_ = std::string(outBuf); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileExSync", ""); + napi_value result = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); + return result; } void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) @@ -326,24 +351,38 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); } -void ConfigPolicyNapi::NativeGetCfgFilesEx(napi_env env, void *data) +napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) { - if (data == nullptr) { - HiLog::Error(LABEL, "data is nullptr"); - return; + CfgFiles *cfgFiles = GetCfgFiles(context->relPath_.c_str()); + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { + context->paths_.push_back(cfgFiles->paths[i]); + } } + FreeCfgFiles(cfgFiles); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesSync", ""); + return CreateArraysValue(env, context); +} - ConfigAsyncContext *asyncCallbackInfo = static_cast(data); - CfgFiles *cfgFiles = GetCfgFilesEx(asyncCallbackInfo->relPath_.c_str(), - asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); +napi_value ConfigPolicyNapi::NativeGetCfgFilesExSync(napi_env env, std::shared_ptr context) +{ + CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), + context->followMode_, context->extra_.c_str()); for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { - asyncCallbackInfo->paths_.push_back(cfgFiles->paths[i]); + context->paths_.push_back(cfgFiles->paths[i]); } } FreeCfgFiles(cfgFiles); - CreateArraysValueFunc(*asyncCallbackInfo); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesEx", ""); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesExSync", ""); + napi_value result = nullptr; + NAPI_CALL(env, napi_create_array_with_length(env, context->paths_.size(), &result)); + for (size_t i = 0; i < context->paths_.size(); i++) { + napi_value element = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, context->paths_[i].c_str(), NAPI_AUTO_LENGTH, &element)); + NAPI_CALL(env, napi_set_element(env, result, i, element)); + } + return result; } void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) @@ -365,6 +404,31 @@ void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirList", ""); } +napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_ptr context) +{ + CfgDir *cfgDir = GetCfgDirList(); + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgDir != nullptr && cfgDir->paths[i] != nullptr) { + context->paths_.push_back(cfgDir->paths[i]); + } + } + FreeCfgDirList(cfgDir); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirListSync", ""); + return CreateArraysValue(env, context); +} + +napi_value ConfigPolicyNapi::CreateArraysValue(napi_env env, std::shared_ptr context) +{ + napi_value result = nullptr; + NAPI_CALL(env, napi_create_array_with_length(env, context->paths_.size(), &result)); + for (size_t i = 0; i < context->paths_.size(); i++) { + napi_value element = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, context->paths_[i].c_str(), NAPI_AUTO_LENGTH, &element)); + NAPI_CALL(env, napi_set_element(env, result, i, element)); + } + return result; +} + void ConfigPolicyNapi::CreateArraysValueFunc(ConfigAsyncContext &asyncCallbackInfo) { asyncCallbackInfo.createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { -- Gitee From 43de31ab6dd1095a0514ad8ac3aa3a6b96f4f635 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Wed, 18 Oct 2023 14:51:44 +0800 Subject: [PATCH 10/28] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 9aaf346..d881ff9 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -323,8 +323,7 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p napi_value ConfigPolicyNapi::NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context) { char outBuf[MAX_PATH_LEN] = {0}; - GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, - context->followMode_, context->extra_.c_str()); + GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, context->extra_.c_str()); context->pathValue_ = std::string(outBuf); ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileExSync", ""); napi_value result = nullptr; @@ -354,9 +353,11 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) { CfgFiles *cfgFiles = GetCfgFiles(context->relPath_.c_str()); - for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { - if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { - context->paths_.push_back(cfgFiles->paths[i]); + if (cfgFiles != nullptr) { + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgFiles->paths[i] != nullptr) { + context->paths_.push_back(cfgFiles->paths[i]); + } } } FreeCfgFiles(cfgFiles); @@ -366,23 +367,17 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr napi_value ConfigPolicyNapi::NativeGetCfgFilesExSync(napi_env env, std::shared_ptr context) { - CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), - context->followMode_, context->extra_.c_str()); - for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { - if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { - context->paths_.push_back(cfgFiles->paths[i]); + CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, context->extra_.c_str()); + if (cfgFiles != nullptr) { + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgFiles->paths[i] != nullptr) { + context->paths_.push_back(cfgFiles->paths[i]); + } } } FreeCfgFiles(cfgFiles); ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesExSync", ""); - napi_value result = nullptr; - NAPI_CALL(env, napi_create_array_with_length(env, context->paths_.size(), &result)); - for (size_t i = 0; i < context->paths_.size(); i++) { - napi_value element = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, context->paths_[i].c_str(), NAPI_AUTO_LENGTH, &element)); - NAPI_CALL(env, napi_set_element(env, result, i, element)); - } - return result; + return CreateArraysValue(env, context); } void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) @@ -407,9 +402,11 @@ void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_ptr context) { CfgDir *cfgDir = GetCfgDirList(); - for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { - if (cfgDir != nullptr && cfgDir->paths[i] != nullptr) { - context->paths_.push_back(cfgDir->paths[i]); + if (cfgDir != nullptr) { + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgDir->paths[i] != nullptr) { + context->paths_.push_back(cfgDir->paths[i]); + } } } FreeCfgDirList(cfgDir); -- Gitee From e28dfcb152f21a7643aad1c9269148f820e65300 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Wed, 18 Oct 2023 15:51:26 +0800 Subject: [PATCH 11/28] =?UTF-8?q?=E5=AF=B9GetOneCfgFile=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=81=9A=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index d881ff9..d9d579a 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -312,8 +312,12 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context) { char outBuf[MAX_PATH_LEN] = {0}; - GetOneCfgFile(context->relPath_.c_str(), outBuf, MAX_PATH_LEN); - context->pathValue_ = std::string(outBuf); + char *filePath = GetOneCfgFile(context->relPath_.c_str(), outBuf, MAX_PATH_LEN); + if (filePath == nullptr) { + HiLog::Info(LABEL, "GetOneCfgFile result is nullptr."); + } else { + context->pathValue_ = std::string(filePath); + } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); napi_value result = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); @@ -323,8 +327,13 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p napi_value ConfigPolicyNapi::NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context) { char outBuf[MAX_PATH_LEN] = {0}; - GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, context->extra_.c_str()); - context->pathValue_ = std::string(outBuf); + char *filePath = GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, + context->extra_.c_str()); + if (filePath == nullptr) { + HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); + } else { + context->pathValue_ = std::string(filePath); + } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileExSync", ""); napi_value result = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); @@ -359,8 +368,8 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context->paths_.push_back(cfgFiles->paths[i]); } } + FreeCfgFiles(cfgFiles); } - FreeCfgFiles(cfgFiles); ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesSync", ""); return CreateArraysValue(env, context); } @@ -374,8 +383,8 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesExSync(napi_env env, std::shared_p context->paths_.push_back(cfgFiles->paths[i]); } } + FreeCfgFiles(cfgFiles); } - FreeCfgFiles(cfgFiles); ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesExSync", ""); return CreateArraysValue(env, context); } @@ -408,8 +417,8 @@ napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_p context->paths_.push_back(cfgDir->paths[i]); } } + FreeCfgDirList(cfgDir); } - FreeCfgDirList(cfgDir); ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirListSync", ""); return CreateArraysValue(env, context); } -- Gitee From f5c794ccc938a626c9afa8a961f1ed486b31be7b Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 19 Oct 2023 16:39:38 +0800 Subject: [PATCH 12/28] =?UTF-8?q?=E6=97=A0=E5=BC=82=E6=AD=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E4=BB=A5Sync=E7=BB=93=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../kits/js/include/config_policy_napi.h | 8 ++++---- interfaces/kits/js/src/config_policy_napi.cpp | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index 73bb17b..aba39fe 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -52,8 +52,8 @@ private: static napi_value NAPIGetCfgFiles(napi_env env, napi_callback_info info); static napi_value NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgFilesSync(napi_env env, napi_callback_info info); - static napi_value NAPIGetOneCfgFileExSync(napi_env env, napi_callback_info info); - static napi_value NAPIGetCfgFilesExSync(napi_env env, napi_callback_info info); + static napi_value NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info); + static napi_value NAPIGetCfgFilesEx(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirList(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirListSync(napi_env env, napi_callback_info info); static napi_value CreateUndefined(napi_env env); @@ -68,8 +68,8 @@ private: static napi_value NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context); static napi_value NativeGetCfgFilesSync(napi_env env, std::shared_ptr context); static napi_value NativeGetCfgDirListSync(napi_env env, std::shared_ptr context); - static napi_value NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context); - static napi_value NativeGetCfgFilesExSync(napi_env env, std::shared_ptr context); + static napi_value NativeGetOneCfgFileEx(napi_env env, std::shared_ptr context); + static napi_value NativeGetCfgFilesEx(napi_env env, std::shared_ptr context); static void NativeCallbackComplete(napi_env env, napi_status status, void *data); static napi_value ParseRelPath(napi_env env, std::string ¶m, napi_value args); static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args); diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index d9d579a..192b1b3 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -47,10 +47,10 @@ napi_value ConfigPolicyNapi::Init(napi_env env, napi_value exports) napi_property_descriptor property[] = { DECLARE_NAPI_FUNCTION("getOneCfgFile", ConfigPolicyNapi::NAPIGetOneCfgFile), DECLARE_NAPI_FUNCTION("getOneCfgFileSync", ConfigPolicyNapi::NAPIGetOneCfgFileSync), - DECLARE_NAPI_FUNCTION("getOneCfgFileExSync", ConfigPolicyNapi::NAPIGetOneCfgFileExSync), + DECLARE_NAPI_FUNCTION("getOneCfgFileEx", ConfigPolicyNapi::NAPIGetOneCfgFileEx), DECLARE_NAPI_FUNCTION("getCfgFiles", ConfigPolicyNapi::NAPIGetCfgFiles), DECLARE_NAPI_FUNCTION("getCfgFilesSync", ConfigPolicyNapi::NAPIGetCfgFilesSync), - DECLARE_NAPI_FUNCTION("getCfgFilesExSync", ConfigPolicyNapi::NAPIGetCfgFilesExSync), + DECLARE_NAPI_FUNCTION("getCfgFilesEx", ConfigPolicyNapi::NAPIGetCfgFilesEx), DECLARE_NAPI_FUNCTION("getCfgDirList", ConfigPolicyNapi::NAPIGetCfgDirList), DECLARE_NAPI_FUNCTION("getCfgDirListSync", ConfigPolicyNapi::NAPIGetCfgDirListSync), @@ -158,9 +158,9 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_cal return func(env, asyncContext); } -napi_value ConfigPolicyNapi::NAPIGetOneCfgFileExSync(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info) { - return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetOneCfgFileExSync); + return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetOneCfgFileEx); } napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) @@ -205,9 +205,9 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_inf return NativeGetCfgFilesSync(env, asyncContext); } -napi_value ConfigPolicyNapi::NAPIGetCfgFilesExSync(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetCfgFilesEx(napi_env env, napi_callback_info info) { - return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetCfgFilesExSync); + return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetCfgFilesEx); } napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) @@ -324,7 +324,7 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p return result; } -napi_value ConfigPolicyNapi::NativeGetOneCfgFileExSync(napi_env env, std::shared_ptr context) +napi_value ConfigPolicyNapi::NativeGetOneCfgFileEx(napi_env env, std::shared_ptr context) { char outBuf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, @@ -334,7 +334,7 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileExSync(napi_env env, std::shared } else { context->pathValue_ = std::string(filePath); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileExSync", ""); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileEx", ""); napi_value result = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); return result; @@ -374,7 +374,7 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr return CreateArraysValue(env, context); } -napi_value ConfigPolicyNapi::NativeGetCfgFilesExSync(napi_env env, std::shared_ptr context) +napi_value ConfigPolicyNapi::NativeGetCfgFilesEx(napi_env env, std::shared_ptr context) { CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, context->extra_.c_str()); if (cfgFiles != nullptr) { @@ -385,7 +385,7 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesExSync(napi_env env, std::shared_p } FreeCfgFiles(cfgFiles); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesExSync", ""); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesEx", ""); return CreateArraysValue(env, context); } -- Gitee From e772e38382c663b3282ba51364ee87c9df697fdf Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Fri, 20 Oct 2023 16:12:03 +0800 Subject: [PATCH 13/28] =?UTF-8?q?=E9=9A=8FX=E8=83=BD=E5=8A=9B=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=99=AE=E9=80=9A=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E5=8F=82=E6=95=B0=E8=BF=9B=E8=A1=8C=E6=89=A9?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../kits/js/include/config_policy_napi.h | 8 +- interfaces/kits/js/src/config_policy_napi.cpp | 189 ++++++++---------- 2 files changed, 84 insertions(+), 113 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index aba39fe..fb414ec 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -52,15 +52,15 @@ private: static napi_value NAPIGetCfgFiles(napi_env env, napi_callback_info info); static napi_value NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgFilesSync(napi_env env, napi_callback_info info); - static napi_value NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info); - static napi_value NAPIGetCfgFilesEx(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirList(napi_env env, napi_callback_info info); static napi_value NAPIGetCfgDirListSync(napi_env env, napi_callback_info info); static napi_value CreateUndefined(napi_env env); static std::string GetStringFromNAPI(napi_env env, napi_value value); static napi_value HandleAsyncWork(napi_env env, ConfigAsyncContext *context, std::string workName, napi_async_execute_callback execute, napi_async_complete_callback complete); - static napi_value GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, NapiFunction func); + static napi_value GetOneCfgFileOrAllCfgFilesSync(napi_env env, napi_callback_info info, NapiFunction func); + static napi_value GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, + const std::string &workName, napi_async_execute_callback execute); static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType); static void NativeGetOneCfgFile(napi_env env, void *data); static void NativeGetCfgFiles(napi_env env, void *data); @@ -68,8 +68,6 @@ private: static napi_value NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context); static napi_value NativeGetCfgFilesSync(napi_env env, std::shared_ptr context); static napi_value NativeGetCfgDirListSync(napi_env env, std::shared_ptr context); - static napi_value NativeGetOneCfgFileEx(napi_env env, std::shared_ptr context); - static napi_value NativeGetCfgFilesEx(napi_env env, std::shared_ptr context); static void NativeCallbackComplete(napi_env env, napi_status status, void *data); static napi_value ParseRelPath(napi_env env, std::string ¶m, napi_value args); static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args); diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 192b1b3..9235fe2 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -29,9 +29,11 @@ using namespace OHOS::HiviewDFX; static constexpr size_t ARGS_SIZE_ONE = 1; static constexpr size_t ARGS_SIZE_TWO = 2; static constexpr size_t ARGS_SIZE_THREE = 3; +static constexpr size_t ARGS_SIZE_FOUR = 4; static constexpr int32_t ARR_INDEX_ZERO = 0; static constexpr int32_t ARR_INDEX_ONE = 1; static constexpr int32_t ARR_INDEX_TWO = 2; +static constexpr int32_t ARR_INDEX_THREE = 3; static constexpr int32_t NAPI_RETURN_ZERO = 0; static constexpr int32_t NAPI_RETURN_ONE = 1; // Param Error Code @@ -47,10 +49,8 @@ napi_value ConfigPolicyNapi::Init(napi_env env, napi_value exports) napi_property_descriptor property[] = { DECLARE_NAPI_FUNCTION("getOneCfgFile", ConfigPolicyNapi::NAPIGetOneCfgFile), DECLARE_NAPI_FUNCTION("getOneCfgFileSync", ConfigPolicyNapi::NAPIGetOneCfgFileSync), - DECLARE_NAPI_FUNCTION("getOneCfgFileEx", ConfigPolicyNapi::NAPIGetOneCfgFileEx), DECLARE_NAPI_FUNCTION("getCfgFiles", ConfigPolicyNapi::NAPIGetCfgFiles), DECLARE_NAPI_FUNCTION("getCfgFilesSync", ConfigPolicyNapi::NAPIGetCfgFilesSync), - DECLARE_NAPI_FUNCTION("getCfgFilesEx", ConfigPolicyNapi::NAPIGetCfgFilesEx), DECLARE_NAPI_FUNCTION("getCfgDirList", ConfigPolicyNapi::NAPIGetCfgDirList), DECLARE_NAPI_FUNCTION("getCfgDirListSync", ConfigPolicyNapi::NAPIGetCfgDirListSync), @@ -87,86 +87,54 @@ void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info info) { - size_t argc = ARGS_SIZE_TWO; - napi_value argv[ARGS_SIZE_TWO] = {nullptr}; - napi_value thisVar = nullptr; - void *data = nullptr; - napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - if (argc < ARGS_SIZE_ONE) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); - } - - auto asyncContext = std::make_unique(); - if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { - return nullptr; - } - if (argc == ARGS_SIZE_TWO) { - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); - if (!matchFlag) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The second parameter must be Callback."); - } - napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); - } - return HandleAsyncWork(env, asyncContext.release(), "NAPIGetOneCfgFile", NativeGetOneCfgFile, - NativeCallbackComplete); + return GetOneCfgFileOrAllCfgFiles(env, info, "NAPIGetOneCfgFile", NativeGetOneCfgFile); } napi_value ConfigPolicyNapi::NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info) { - size_t argc = ARGS_SIZE_ONE; - napi_value argv[ARGS_SIZE_ONE] = {nullptr}; - napi_value thisVar = nullptr; - void *data = nullptr; - napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - if (argc < ARGS_SIZE_ONE) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); - } - auto asyncContext = std::make_shared(); - if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { - return nullptr; - } - return NativeGetOneCfgFileSync(env, asyncContext); + return GetOneCfgFileOrAllCfgFilesSync(env, info, NativeGetOneCfgFileSync); } -napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesEx(napi_env env, napi_callback_info info, NapiFunction func) +napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesSync(napi_env env, napi_callback_info info, NapiFunction func) { size_t argc = ARGS_SIZE_THREE; napi_value argv[ARGS_SIZE_THREE] = {nullptr}; napi_value thisVar = nullptr; void *data = nullptr; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - if (argc < ARGS_SIZE_TWO) { + if (argc < ARGS_SIZE_ONE) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); } auto asyncContext = std::make_shared(); - if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr || - ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + asyncContext->followMode_ = FOLLOWX_MODE_DEFAULT; + if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { return nullptr; } + if (argc == ARGS_SIZE_TWO) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + return nullptr; + } if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The followMode is USER_DEFINED, extra must be set."); } } if (argc >= ARGS_SIZE_THREE) { - if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr || + ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } } return func(env, asyncContext); } -napi_value ConfigPolicyNapi::NAPIGetOneCfgFileEx(napi_env env, napi_callback_info info) -{ - return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetOneCfgFileEx); -} - -napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, + const std::string &workName, napi_async_execute_callback execute) { - size_t argc = ARGS_SIZE_TWO; - napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + size_t argc = ARGS_SIZE_FOUR; + napi_value argv[ARGS_SIZE_FOUR] = {nullptr}; napi_value thisVar = nullptr; void *data = nullptr; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); @@ -175,39 +143,65 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info in } auto asyncContext = std::make_unique(); + asyncContext->followMode_ = FOLLOWX_MODE_DEFAULT; if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { return nullptr; } if (argc == ARGS_SIZE_TWO) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); + if (matchFlag) { + napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); + } else { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + return nullptr; + } + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The followMode is USER_DEFINED, extra must be set."); + } + } + } + + if (argc == ARGS_SIZE_THREE) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + return nullptr; + } + bool matchFlag = MatchValueType(env, argv[ARR_INDEX_TWO], napi_function); + if (matchFlag) { + if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The followMode is USER_DEFINED, extra must be set."); + } + napi_create_reference(env, argv[ARR_INDEX_TWO], NAPI_RETURN_ONE, &asyncContext->callbackRef_); + } else { + if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { + return nullptr; + } + } + } + + if (argc == ARGS_SIZE_FOUR) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr || + ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { + return nullptr; + } + bool matchFlag = MatchValueType(env, argv[ARR_INDEX_THREE], napi_function); if (!matchFlag) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The second parameter must be Callback."); } - napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); + napi_create_reference(env, argv[ARR_INDEX_THREE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); } - return HandleAsyncWork(env, asyncContext.release(), "NAPIGetCfgFiles", NativeGetCfgFiles, NativeCallbackComplete); + return HandleAsyncWork(env, asyncContext.release(), workName, execute, NativeCallbackComplete); } -napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) { - size_t argc = ARGS_SIZE_ONE; - napi_value argv[ARGS_SIZE_ONE] = {nullptr}; - napi_value thisVar = nullptr; - void *data = nullptr; - napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - if (argc < ARGS_SIZE_ONE) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The number of parameters is incorrect."); - } - auto asyncContext = std::make_shared(); - if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { - return nullptr; - } - return NativeGetCfgFilesSync(env, asyncContext); + return GetOneCfgFileOrAllCfgFiles(env, info, "NAPIGetCfgFiles", NativeGetCfgFiles); } -napi_value ConfigPolicyNapi::NAPIGetCfgFilesEx(napi_env env, napi_callback_info info) +napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_info info) { - return GetOneCfgFileOrAllCfgFilesEx(env, info, NativeGetCfgFilesEx); + return GetOneCfgFileOrAllCfgFilesSync(env, info, NativeGetCfgFilesSync); } napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) @@ -299,8 +293,13 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) } ConfigAsyncContext *asyncCallbackInfo = static_cast(data); char outBuf[MAX_PATH_LEN] = {0}; - GetOneCfgFile(asyncCallbackInfo->relPath_.c_str(), outBuf, MAX_PATH_LEN); - asyncCallbackInfo->pathValue_ = std::string(outBuf); + char *filePath = GetOneCfgFileEx(asyncCallbackInfo->relPath_.c_str(), outBuf, MAX_PATH_LEN, + asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); + if (filePath == nullptr) { + HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); + } else { + asyncCallbackInfo->pathValue_ = std::string(filePath); + } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { napi_value result; @@ -312,29 +311,14 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context) { char outBuf[MAX_PATH_LEN] = {0}; - char *filePath = GetOneCfgFile(context->relPath_.c_str(), outBuf, MAX_PATH_LEN); - if (filePath == nullptr) { - HiLog::Info(LABEL, "GetOneCfgFile result is nullptr."); - } else { - context->pathValue_ = std::string(filePath); - } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); - napi_value result = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); - return result; -} - -napi_value ConfigPolicyNapi::NativeGetOneCfgFileEx(napi_env env, std::shared_ptr context) -{ - char outBuf[MAX_PATH_LEN] = {0}; - char *filePath = GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, - context->extra_.c_str()); + char *filePath = GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, + context->followMode_, context->extra_.c_str()); if (filePath == nullptr) { HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); } else { context->pathValue_ = std::string(filePath); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileEx", ""); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); napi_value result = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); return result; @@ -348,35 +332,24 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) } ConfigAsyncContext *asyncCallbackInfo = static_cast(data); - CfgFiles *cfgFiles = GetCfgFiles(asyncCallbackInfo->relPath_.c_str()); - for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { - if (cfgFiles != nullptr && cfgFiles->paths[i] != nullptr) { - asyncCallbackInfo->paths_.push_back(cfgFiles->paths[i]); - } - } - FreeCfgFiles(cfgFiles); - CreateArraysValueFunc(*asyncCallbackInfo); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); -} - -napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) -{ - CfgFiles *cfgFiles = GetCfgFiles(context->relPath_.c_str()); + CfgFiles *cfgFiles = GetCfgFilesEx(asyncCallbackInfo->relPath_.c_str(), asyncCallbackInfo->followMode_, + asyncCallbackInfo->extra_.c_str()); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { - context->paths_.push_back(cfgFiles->paths[i]); + asyncCallbackInfo->paths_.push_back(cfgFiles->paths[i]); } } FreeCfgFiles(cfgFiles); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesSync", ""); - return CreateArraysValue(env, context); + CreateArraysValueFunc(*asyncCallbackInfo); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); } -napi_value ConfigPolicyNapi::NativeGetCfgFilesEx(napi_env env, std::shared_ptr context) +napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) { - CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, context->extra_.c_str()); + CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, + context->extra_.c_str()); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { @@ -385,7 +358,7 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesEx(napi_env env, std::shared_ptr Date: Fri, 20 Oct 2023 17:11:57 +0800 Subject: [PATCH 14/28] =?UTF-8?q?=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 9235fe2..f423d9e 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -130,7 +130,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesSync(napi_env env, napi_c return func(env, asyncContext); } -napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, +napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, const std::string &workName, napi_async_execute_callback execute) { size_t argc = ARGS_SIZE_FOUR; @@ -148,8 +148,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb return nullptr; } if (argc == ARGS_SIZE_TWO) { - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); - if (matchFlag) { + if (MatchValueType(env, argv[ARR_INDEX_ONE], napi_function)) { napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); } else { if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { @@ -166,8 +165,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { return nullptr; } - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_TWO], napi_function); - if (matchFlag) { + if (MatchValueType(env, argv[ARR_INDEX_TWO], napi_function)) { if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The followMode is USER_DEFINED, extra must be set."); @@ -185,9 +183,8 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } - bool matchFlag = MatchValueType(env, argv[ARR_INDEX_THREE], napi_function); - if (!matchFlag) { - return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The second parameter must be Callback."); + if (!MatchValueType(env, argv[ARR_INDEX_THREE], napi_function)) { + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The fourth parameter must be Callback."); } napi_create_reference(env, argv[ARR_INDEX_THREE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); } -- Gitee From 0a60ce6fea3038648711671f2153b9f52d5c0cd5 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Fri, 20 Oct 2023 18:17:50 +0800 Subject: [PATCH 15/28] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/include/config_policy_napi.h | 2 +- interfaces/kits/js/src/config_policy_napi.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index fb414ec..cf7d81b 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -59,7 +59,7 @@ private: static napi_value HandleAsyncWork(napi_env env, ConfigAsyncContext *context, std::string workName, napi_async_execute_callback execute, napi_async_complete_callback complete); static napi_value GetOneCfgFileOrAllCfgFilesSync(napi_env env, napi_callback_info info, NapiFunction func); - static napi_value GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, + static napi_value GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callback_info info, const std::string &workName, napi_async_execute_callback execute); static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType); static void NativeGetOneCfgFile(napi_env env, void *data); diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index f423d9e..6865155 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -155,7 +155,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb return nullptr; } if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { - return ThrowNapiError(env, PARAM_ERROR, + return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The followMode is USER_DEFINED, extra must be set."); } } -- Gitee From 21962afd33f9ac897e30bfc1f7d039e837aab6da Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Sat, 21 Oct 2023 14:52:10 +0800 Subject: [PATCH 16/28] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BD=93=E8=B6=85=E5=A4=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- .../kits/js/include/config_policy_napi.h | 2 +- interfaces/kits/js/src/config_policy_napi.cpp | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/interfaces/kits/js/include/config_policy_napi.h b/interfaces/kits/js/include/config_policy_napi.h index cf7d81b..458f1ff 100644 --- a/interfaces/kits/js/include/config_policy_napi.h +++ b/interfaces/kits/js/include/config_policy_napi.h @@ -70,7 +70,7 @@ private: static napi_value NativeGetCfgDirListSync(napi_env env, std::shared_ptr context); static void NativeCallbackComplete(napi_env env, napi_status status, void *data); static napi_value ParseRelPath(napi_env env, std::string ¶m, napi_value args); - static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args); + static napi_value ParseFollowMode(napi_env env, int32_t ¶m, napi_value args, bool hasExtra); static napi_value ParseExtra(napi_env env, std::string ¶m, napi_value args); static napi_value CreateArraysValue(napi_env env, std::shared_ptr context); static void CreateArraysValueFunc(ConfigAsyncContext &context); diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 6865155..1e1c9aa 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -108,21 +108,19 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFilesSync(napi_env env, napi_c auto asyncContext = std::make_shared(); asyncContext->followMode_ = FOLLOWX_MODE_DEFAULT; + bool hasExtra = false; if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { return nullptr; } if (argc == ARGS_SIZE_TWO) { - if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE], hasExtra) == nullptr) { return nullptr; } - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { - return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The followMode is USER_DEFINED, extra must be set."); - } } if (argc >= ARGS_SIZE_THREE) { - if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr || + hasExtra = true; + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE], hasExtra) == nullptr || ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } @@ -144,6 +142,7 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb auto asyncContext = std::make_unique(); asyncContext->followMode_ = FOLLOWX_MODE_DEFAULT; + bool hasExtra = false; if (ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]) == nullptr) { return nullptr; } @@ -151,35 +150,29 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb if (MatchValueType(env, argv[ARR_INDEX_ONE], napi_function)) { napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncContext->callbackRef_); } else { - if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE], hasExtra) == nullptr) { return nullptr; } - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { - return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The followMode is USER_DEFINED, extra must be set."); - } } } if (argc == ARGS_SIZE_THREE) { - if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr) { - return nullptr; - } if (MatchValueType(env, argv[ARR_INDEX_TWO], napi_function)) { - if (asyncContext->followMode_ == FOLLOWX_MODE_USER_DEFINED) { - return ThrowNapiError(env, PARAM_ERROR, - "Parameter error. The followMode is USER_DEFINED, extra must be set."); - } napi_create_reference(env, argv[ARR_INDEX_TWO], NAPI_RETURN_ONE, &asyncContext->callbackRef_); } else { if (ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } + hasExtra = true; + } + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE], hasExtra) == nullptr) { + return nullptr; } } if (argc == ARGS_SIZE_FOUR) { - if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE]) == nullptr || + hasExtra = true; + if (ParseFollowMode(env, asyncContext->followMode_, argv[ARR_INDEX_ONE], hasExtra) == nullptr || ParseExtra(env, asyncContext->extra_, argv[ARR_INDEX_TWO]) == nullptr) { return nullptr; } @@ -473,7 +466,7 @@ napi_value ConfigPolicyNapi::ParseExtra(napi_env env, std::string ¶m, napi_v return result; } -napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_value args) +napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_value args, bool hasExtra) { bool matchFlag = MatchValueType(env, args, napi_number); if (!matchFlag) { @@ -494,8 +487,12 @@ napi_value ConfigPolicyNapi::ParseFollowMode(napi_env env, int32_t ¶m, napi_ case FOLLOWX_MODE_SIM_1: [[fallthrough]]; case FOLLOWX_MODE_SIM_2: - [[fallthrough]]; + break; case FOLLOWX_MODE_USER_DEFINED: + if (!hasExtra) { + return ThrowNapiError(env, PARAM_ERROR, + "Parameter error. The followMode is USER_DEFINED, extra must be set."); + } break; default: return ThrowNapiError(env, PARAM_ERROR, -- Gitee From 35c00287326dd83584ec09cdefd56565749beed8 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Sat, 25 Nov 2023 17:08:39 +0800 Subject: [PATCH 17/28] =?UTF-8?q?=E6=96=B0=E5=A2=9Efuzz=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- bundle.json | 3 +- common/config/BUILD.gn | 24 ++++++++++ test/fuzztest/BUILD.gn | 22 +++++++++ test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 44 +++++++++++++++++ test/fuzztest/getcfgfiles_fuzzer/corpus/init | 14 ++++++ .../getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp | 45 ++++++++++++++++++ test/fuzztest/getcfgfiles_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../fuzztest/getcfgfilesex_fuzzer/corpus/init | 14 ++++++ .../getcfgfilesex_fuzzer.cpp | 47 +++++++++++++++++++ .../fuzztest/getcfgfilesex_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../fuzztest/getonecfgfile_fuzzer/corpus/init | 14 ++++++ .../getonecfgfile_fuzzer.cpp | 44 +++++++++++++++++ .../fuzztest/getonecfgfile_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../getonecfgfileex_fuzzer/corpus/init | 14 ++++++ .../getonecfgfileex_fuzzer.cpp | 47 +++++++++++++++++++ .../getonecfgfileex_fuzzer/project.xml | 25 ++++++++++ test/unittest/BUILD.gn | 2 +- test/{ => unittest}/resource/ohos_test.xml | 0 21 files changed, 564 insertions(+), 2 deletions(-) create mode 100644 common/config/BUILD.gn create mode 100644 test/fuzztest/BUILD.gn create mode 100644 test/fuzztest/getcfgfiles_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getcfgfiles_fuzzer/corpus/init create mode 100644 test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp create mode 100644 test/fuzztest/getcfgfiles_fuzzer/project.xml create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/corpus/init create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/project.xml create mode 100644 test/fuzztest/getonecfgfile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getonecfgfile_fuzzer/corpus/init create mode 100644 test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp create mode 100644 test/fuzztest/getonecfgfile_fuzzer/project.xml create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/corpus/init create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/project.xml rename test/{ => unittest}/resource/ohos_test.xml (100%) diff --git a/bundle.json b/bundle.json index f37affa..cf2c993 100644 --- a/bundle.json +++ b/bundle.json @@ -47,7 +47,8 @@ } ], "test": [ - "//base/customization/config_policy/test/unittest:ConfigPolicyUtilsTest" + "//base/customization/config_policy/test/unittest:ConfigPolicyUtilsTest", + "//base/customization/config_policy/test/fuzztest:fuzztest" ] } } diff --git a/common/config/BUILD.gn b/common/config/BUILD.gn new file mode 100644 index 0000000..b8f1b88 --- /dev/null +++ b/common/config/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 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. + +declare_args() { + config_policy_feature_coverage = false +} + +config("coverage_flags") { + if (config_policy_feature_coverage) { + cflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000..f47317e --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("fuzztest") { + testonly = true + deps = [ + "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", + "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", + "getcfgfiles_fuzzer:GetCfgFilesFuzzTest", + "getcfgfilesex_fuzzer:GetCfgFilesExFuzzTest", + ] +} diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn new file mode 100644 index 0000000..680cd36 --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetCfgFilesFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getcfgfiles_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getcfgfiles_fuzzer/corpus/init b/test/fuzztest/getcfgfiles_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp new file mode 100644 index 0000000..89e024f --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getcfgfiles_fuzzer" + + +namespace OHOS { + bool fuzzGetCfgFiles(const uint8_t* data, size_t size) + { + std::string cfgPath((const char*) data, size); + CfgFiles *cfgFiles = GetCfgFiles(cfgPath.c_str()); + bool result = cfgFiles != nullptr; + FreeCfgFiles(cfgFiles); + return result; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetCfgFiles(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getcfgfiles_fuzzer/project.xml b/test/fuzztest/getcfgfiles_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn new file mode 100644 index 0000000..a51cc64 --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetCfgFilesExFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getcfgfilesex_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp new file mode 100644 index 0000000..36cf6ea --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getcfgfilesex_fuzzer" + + +namespace OHOS { + bool fuzzGetCfgFilesEx(const uint8_t* data, size_t size) + { + std::string cfgPath((const char*) data, size / 2); + std::string extra((const char*) data + size / 2, size / 2); + int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + CfgFiles *cfgFiles = GetCfgFilesEx(cfgPath.c_str(), followMode, extra.c_str()); + bool result = cfgFiles != nullptr; + FreeCfgFiles(cfgFiles); + return result; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetCfgFilesEx(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getcfgfilesex_fuzzer/project.xml b/test/fuzztest/getcfgfilesex_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn new file mode 100644 index 0000000..3eca152 --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetOneCfgFileFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getonecfgfile_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getonecfgfile_fuzzer/corpus/init b/test/fuzztest/getonecfgfile_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp new file mode 100644 index 0000000..d5c974f --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getonecfgfile_fuzzer" + + +namespace OHOS { + bool fuzzGetOneCfgFile(const uint8_t* data, size_t size) + { + std::string userPath((const char*) data, size); + char buf[MAX_PATH_LEN] = {0}; + char *filePath = GetOneCfgFile(userPath.c_str(), buf, MAX_PATH_LEN); + return filePath != nullptr; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetOneCfgFile(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getonecfgfile_fuzzer/project.xml b/test/fuzztest/getonecfgfile_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn new file mode 100644 index 0000000..0b1d0e3 --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetOneCfgFileExFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getonecfgfileex_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp new file mode 100644 index 0000000..ba5839e --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getonecfgfileex_fuzzer" + +constexpr size_t MIN_SIZE = 4; + +namespace OHOS { + bool fuzzGetOneCfgFileEx(const uint8_t* data, size_t size) + { + std::string userPath((const char*) data, size / 2); + std::string extra((const char*) data + size / 2, size / 2); + int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + char buf[MAX_PATH_LEN] = {0}; + char *filePath = GetOneCfgFileEx(userPath.c_str(), buf, MAX_PATH_LEN, followMode, extra.c_str()); + return filePath != nullptr; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < MIN_SIZE) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetOneCfgFileEx(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getonecfgfileex_fuzzer/project.xml b/test/fuzztest/getonecfgfileex_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index fc2f408..10642ea 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -44,6 +44,6 @@ if (defined(ohos_lite)) { include_dirs = config_policy_include_dirs deps = config_policy_deps external_deps = [ "init:libbegetutil" ] - resource_config_file = "../resource/ohos_test.xml" + resource_config_file = "./resource/ohos_test.xml" } } diff --git a/test/resource/ohos_test.xml b/test/unittest/resource/ohos_test.xml similarity index 100% rename from test/resource/ohos_test.xml rename to test/unittest/resource/ohos_test.xml -- Gitee From 6b79c9d9ababe062e317342cd8240b1b8ae8f36c Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 27 Nov 2023 18:49:17 +0800 Subject: [PATCH 18/28] =?UTF-8?q?FUZZ=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/BUILD.gn | 4 ++-- test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp | 4 ++-- .../getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp | 9 +++++---- .../getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp | 4 ++-- .../getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp | 6 +++--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index f47317e..76cc189 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -14,9 +14,9 @@ group("fuzztest") { testonly = true deps = [ - "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", - "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", "getcfgfiles_fuzzer:GetCfgFilesFuzzTest", "getcfgfilesex_fuzzer:GetCfgFilesExFuzzTest", + "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", + "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", ] } diff --git a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp index 89e024f..3d7f621 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp +++ b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp @@ -23,7 +23,7 @@ namespace OHOS { - bool fuzzGetCfgFiles(const uint8_t* data, size_t size) + bool FuzzGetCfgFiles(const uint8_t* data, size_t size) { std::string cfgPath((const char*) data, size); CfgFiles *cfgFiles = GetCfgFiles(cfgPath.c_str()); @@ -40,6 +40,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetCfgFiles(data, size); + OHOS::FuzzGetCfgFiles(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp index 36cf6ea..7679a21 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp +++ b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp @@ -21,12 +21,13 @@ #define FUZZ_PROJECT_NAME "getcfgfilesex_fuzzer" +constexpr size_t MIN_SIZE = 4; namespace OHOS { - bool fuzzGetCfgFilesEx(const uint8_t* data, size_t size) + bool FuzzGetCfgFilesEx(const uint8_t* data, size_t size) { std::string cfgPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size / 2); + std::string extra((const char*) data + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; CfgFiles *cfgFiles = GetCfgFilesEx(cfgPath.c_str(), followMode, extra.c_str()); bool result = cfgFiles != nullptr; @@ -38,10 +39,10 @@ namespace OHOS { // Fuzzer entry point. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - if (data == nullptr) { + if (data == nullptr || size < MIN_SIZE) { return 0; } // Run your code on data. - OHOS::fuzzGetCfgFilesEx(data, size); + OHOS::FuzzGetCfgFilesEx(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp index d5c974f..1d6d43f 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp +++ b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp @@ -23,7 +23,7 @@ namespace OHOS { - bool fuzzGetOneCfgFile(const uint8_t* data, size_t size) + bool FuzzGetOneCfgFile(const uint8_t* data, size_t size) { std::string userPath((const char*) data, size); char buf[MAX_PATH_LEN] = {0}; @@ -39,6 +39,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetOneCfgFile(data, size); + OHOS::FuzzGetOneCfgFile(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp index ba5839e..5224a37 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp +++ b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp @@ -24,10 +24,10 @@ constexpr size_t MIN_SIZE = 4; namespace OHOS { - bool fuzzGetOneCfgFileEx(const uint8_t* data, size_t size) + bool FuzzGetOneCfgFileEx(const uint8_t* data, size_t size) { std::string userPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size / 2); + std::string extra((const char*) data + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFileEx(userPath.c_str(), buf, MAX_PATH_LEN, followMode, extra.c_str()); @@ -42,6 +42,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetOneCfgFileEx(data, size); + OHOS::FuzzGetOneCfgFileEx(data, size); return 0; } \ No newline at end of file -- Gitee From 0e6b07b67852f3c6a79f24f60b38d64d42e2818d Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 27 Nov 2023 19:45:25 +0800 Subject: [PATCH 19/28] =?UTF-8?q?FUZZ=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getcfgfiles_fuzzer/corpus/init | 2 +- test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getcfgfilesex_fuzzer/corpus/init | 2 +- test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getonecfgfile_fuzzer/corpus/init | 2 +- test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getonecfgfileex_fuzzer/corpus/init | 2 +- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn index 680cd36..913b590 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetCfgFilesFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfiles_fuzzer/corpus/init b/test/fuzztest/getcfgfiles_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/corpus/init +++ b/test/fuzztest/getcfgfiles_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn index a51cc64..d1d041a 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetCfgFilesExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init +++ b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn index 3eca152..7c3b188 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetOneCfgFileFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfile_fuzzer/corpus/init b/test/fuzztest/getonecfgfile_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/corpus/init +++ b/test/fuzztest/getonecfgfile_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn index 0b1d0e3..33dd1eb 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetOneCfgFileExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init +++ b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -- Gitee From 768cd9ac66e7a8a21de96d98d3c0382a61158cbe Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Tue, 28 Nov 2023 09:17:19 +0800 Subject: [PATCH 20/28] =?UTF-8?q?FUZZ=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 2 +- test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 2 +- test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 2 +- test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn index 913b590..8ba4aa4 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetCfgFilesFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn index d1d041a..abe72f3 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetCfgFilesExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn index 7c3b188..0582d5f 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetOneCfgFileFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn index 33dd1eb..df69bd4 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetOneCfgFileExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" -- Gitee From eefd8c60b253bd3c8fef895636c22beaf807277a Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Wed, 29 Nov 2023 16:35:29 +0800 Subject: [PATCH 21/28] =?UTF-8?q?=E4=BD=BF=E7=94=A8reinterpret=5Fcast?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=B1=BB=E5=9E=8B=E5=BC=BA=E5=88=B6=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp | 2 +- test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp | 4 ++-- test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp | 2 +- .../getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp index 3d7f621..f238cc1 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp +++ b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp @@ -25,7 +25,7 @@ namespace OHOS { bool FuzzGetCfgFiles(const uint8_t* data, size_t size) { - std::string cfgPath((const char*) data, size); + std::string cfgPath(reinterpret_cast(data), size); CfgFiles *cfgFiles = GetCfgFiles(cfgPath.c_str()); bool result = cfgFiles != nullptr; FreeCfgFiles(cfgFiles); diff --git a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp index 7679a21..7a7cc16 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp +++ b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp @@ -26,8 +26,8 @@ constexpr size_t MIN_SIZE = 4; namespace OHOS { bool FuzzGetCfgFilesEx(const uint8_t* data, size_t size) { - std::string cfgPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size - size / 2); + std::string cfgPath(reinterpret_cast(data), size / 2); + std::string extra(reinterpret_cast(data) + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; CfgFiles *cfgFiles = GetCfgFilesEx(cfgPath.c_str(), followMode, extra.c_str()); bool result = cfgFiles != nullptr; diff --git a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp index 1d6d43f..47b94c2 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp +++ b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp @@ -25,7 +25,7 @@ namespace OHOS { bool FuzzGetOneCfgFile(const uint8_t* data, size_t size) { - std::string userPath((const char*) data, size); + std::string userPath(reinterpret_cast(data), size); char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFile(userPath.c_str(), buf, MAX_PATH_LEN); return filePath != nullptr; diff --git a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp index 5224a37..2439cd7 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp +++ b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp @@ -26,8 +26,8 @@ constexpr size_t MIN_SIZE = 4; namespace OHOS { bool FuzzGetOneCfgFileEx(const uint8_t* data, size_t size) { - std::string userPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size - size / 2); + std::string userPath(reinterpret_cast(data), size / 2); + std::string extra(reinterpret_cast(data) + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFileEx(userPath.c_str(), buf, MAX_PATH_LEN, followMode, extra.c_str()); -- Gitee From eb4de27dbdd5a7d72d3ccccfe5da5fa356dc48e7 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Tue, 5 Dec 2023 09:29:01 +0800 Subject: [PATCH 22/28] =?UTF-8?q?index=E4=B8=8B=E6=A0=87=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- frameworks/config_policy/src/config_policy_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index 06c4187..54d8ca3 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -490,7 +490,7 @@ CfgFiles *GetCfgFilesEx(const char *pathSuffix, int followMode, const char *extr access(buf, F_OK) == 0) { files->paths[index++] = strdup(buf); } - for (int j = 0; result && j < result->segCount; j++) { + for (int j = 0; result && j < result->segCount && index < MAX_CFG_POLICY_DIRS_CNT; j++) { if (result->segs[j] && snprintf_s(buf, MAX_PATH_LEN, MAX_PATH_LEN - 1, "%s/%s/%s", dirs->paths[i], result->segs[j], pathSuffix) > 0 && -- Gitee From bf14fe198d232aec15a0ebb4dea9d4e6f4fdea56 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 4 Jan 2024 14:25:23 +0800 Subject: [PATCH 23/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9max=20filepath=20length?= =?UTF-8?q?=E4=B8=BA256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/inner_api/include/config_policy_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/include/config_policy_utils.h b/interfaces/inner_api/include/config_policy_utils.h index 30c4c5f..8d16fca 100644 --- a/interfaces/inner_api/include/config_policy_utils.h +++ b/interfaces/inner_api/include/config_policy_utils.h @@ -23,7 +23,7 @@ extern "C" { #endif // __cplusplus #define MAX_CFG_POLICY_DIRS_CNT 32 // max number of directories -#define MAX_PATH_LEN 128 // max length of a filepath +#define MAX_PATH_LEN 256 // max length of a filepath // follow X(carrier/network/PLMN/...) usage // 1. etc/cust/followx_file_list.cfg can be in any layer, except follow x dir -- Gitee From 7109fd1ec05a2c794e9d49a2a80928ad03712b8f Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 22 Jan 2024 14:53:10 +0800 Subject: [PATCH 24/28] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 1e1c9aa..c35262e 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -87,11 +87,13 @@ void ConfigPolicyNapi::CreateFollowXModeObject(napi_env env, napi_value value) napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetOneCfgFile start."); return GetOneCfgFileOrAllCfgFiles(env, info, "NAPIGetOneCfgFile", NativeGetOneCfgFile); } napi_value ConfigPolicyNapi::NAPIGetOneCfgFileSync(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetOneCfgFileSync start."); return GetOneCfgFileOrAllCfgFilesSync(env, info, NativeGetOneCfgFileSync); } @@ -186,16 +188,19 @@ napi_value ConfigPolicyNapi::GetOneCfgFileOrAllCfgFiles(napi_env env, napi_callb napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetCfgFiles start."); return GetOneCfgFileOrAllCfgFiles(env, info, "NAPIGetCfgFiles", NativeGetCfgFiles); } napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetCfgFilesSync start."); return GetOneCfgFileOrAllCfgFilesSync(env, info, NativeGetCfgFilesSync); } napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetCfgDirList start."); size_t argc = ARGS_SIZE_ONE; napi_value argv[ARGS_SIZE_ONE] = {nullptr}; napi_value thisVar = nullptr; @@ -216,6 +221,7 @@ napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info napi_value ConfigPolicyNapi::NAPIGetCfgDirListSync(napi_env env, napi_callback_info info) { + HiLog::Debug(LABEL, "NAPIGetCfgDirListSync start."); auto asyncContext = std::make_shared(); return NativeGetCfgDirListSync(env, asyncContext); } @@ -248,6 +254,7 @@ std::string ConfigPolicyNapi::GetStringFromNAPI(napi_env env, napi_value value) napi_value ConfigPolicyNapi::HandleAsyncWork(napi_env env, ConfigAsyncContext *context, std::string workName, napi_async_execute_callback execute, napi_async_complete_callback complete) { + HiLog::Debug(LABEL, "HandleAsyncWork start."); if (context == nullptr) { HiLog::Error(LABEL, "context is nullptr"); return nullptr; @@ -265,6 +272,7 @@ napi_value ConfigPolicyNapi::HandleAsyncWork(napi_env env, ConfigAsyncContext *c napi_create_async_work(env, resource, resourceName, execute, complete, static_cast(context), &context->work_); napi_queue_async_work_with_qos(env, context->work_, napi_qos_default); + HiLog::Debug(LABEL, "HandleAsyncWork end."); return result; } @@ -277,6 +285,7 @@ bool ConfigPolicyNapi::MatchValueType(napi_env env, napi_value value, napi_value void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) { + HiLog::Debug(LABEL, "NativeGetOneCfgFile start."); if (data == nullptr) { HiLog::Error(LABEL, "data is nullptr"); return; @@ -289,6 +298,7 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); } else { asyncCallbackInfo->pathValue_ = std::string(filePath); + HiLog::Debug(LABEL, "GetOneCfgFileEx native success."); } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { @@ -300,6 +310,7 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_ptr context) { + HiLog::Debug(LABEL, "NativeGetOneCfgFileSync start."); char outBuf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFileEx(context->relPath_.c_str(), outBuf, MAX_PATH_LEN, context->followMode_, context->extra_.c_str()); @@ -307,6 +318,7 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); } else { context->pathValue_ = std::string(filePath); + HiLog::Debug(LABEL, "GetOneCfgFileEx native success."); } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); napi_value result = nullptr; @@ -316,6 +328,7 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) { + HiLog::Debug(LABEL, "NativeGetCfgFiles start."); if (data == nullptr) { HiLog::Error(LABEL, "data is nullptr"); return; @@ -324,6 +337,7 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) ConfigAsyncContext *asyncCallbackInfo = static_cast(data); CfgFiles *cfgFiles = GetCfgFilesEx(asyncCallbackInfo->relPath_.c_str(), asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); + HiLog::Debug(LABEL, "GetCfgFilesEx native success."); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { @@ -338,8 +352,10 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) { + HiLog::Debug(LABEL, "NativeGetCfgFiles start."); CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, context->extra_.c_str()); + HiLog::Debug(LABEL, "GetCfgFilesEx native success."); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { @@ -354,6 +370,7 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) { + HiLog::Debug(LABEL, "NativeGetCfgDirList start."); if (data == nullptr) { HiLog::Error(LABEL, "data is nullptr."); return; @@ -373,6 +390,7 @@ void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_ptr context) { + HiLog::Debug(LABEL, "NativeGetCfgDirListSync start."); CfgDir *cfgDir = GetCfgDirList(); if (cfgDir != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { @@ -414,6 +432,7 @@ void ConfigPolicyNapi::CreateArraysValueFunc(ConfigAsyncContext &asyncCallbackIn void ConfigPolicyNapi::NativeCallbackComplete(napi_env env, napi_status status, void *data) { + HiLog::Debug(LABEL, "NativeCallbackComplete start."); if (data == nullptr) { HiLog::Error(LABEL, "data is nullptr"); return; @@ -440,6 +459,7 @@ void ConfigPolicyNapi::NativeCallbackComplete(napi_env env, napi_status status, } napi_delete_async_work(env, asyncContext->work_); delete asyncContext; + HiLog::Debug(LABEL, "NativeCallbackComplete end."); } napi_value ConfigPolicyNapi::ParseRelPath(napi_env env, std::string ¶m, napi_value args) -- Gitee From da9b41a64244f7f07cb0653ea65be34e818e54a4 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 22 Jan 2024 17:26:17 +0800 Subject: [PATCH 25/28] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index c35262e..d7df3ca 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -200,7 +200,6 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFilesSync(napi_env env, napi_callback_inf napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info info) { - HiLog::Debug(LABEL, "NAPIGetCfgDirList start."); size_t argc = ARGS_SIZE_ONE; napi_value argv[ARGS_SIZE_ONE] = {nullptr}; napi_value thisVar = nullptr; @@ -221,7 +220,6 @@ napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info napi_value ConfigPolicyNapi::NAPIGetCfgDirListSync(napi_env env, napi_callback_info info) { - HiLog::Debug(LABEL, "NAPIGetCfgDirListSync start."); auto asyncContext = std::make_shared(); return NativeGetCfgDirListSync(env, asyncContext); } @@ -298,7 +296,6 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); } else { asyncCallbackInfo->pathValue_ = std::string(filePath); - HiLog::Debug(LABEL, "GetOneCfgFileEx native success."); } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { @@ -318,7 +315,6 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p HiLog::Info(LABEL, "GetOneCfgFileEx result is nullptr."); } else { context->pathValue_ = std::string(filePath); - HiLog::Debug(LABEL, "GetOneCfgFileEx native success."); } ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); napi_value result = nullptr; @@ -337,7 +333,6 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) ConfigAsyncContext *asyncCallbackInfo = static_cast(data); CfgFiles *cfgFiles = GetCfgFilesEx(asyncCallbackInfo->relPath_.c_str(), asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); - HiLog::Debug(LABEL, "GetCfgFilesEx native success."); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { @@ -355,7 +350,6 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr HiLog::Debug(LABEL, "NativeGetCfgFiles start."); CfgFiles *cfgFiles = GetCfgFilesEx(context->relPath_.c_str(), context->followMode_, context->extra_.c_str()); - HiLog::Debug(LABEL, "GetCfgFilesEx native success."); if (cfgFiles != nullptr) { for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { if (cfgFiles->paths[i] != nullptr) { -- Gitee From f48a920b23cbbb745d65735fd853de0838d765d0 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 25 Jan 2024 20:41:46 +0800 Subject: [PATCH 26/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1=E7=9A=84QOS=E7=BA=A7?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- interfaces/kits/js/src/config_policy_napi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index d7df3ca..b2710b7 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -269,7 +269,7 @@ napi_value ConfigPolicyNapi::HandleAsyncWork(napi_env env, ConfigAsyncContext *c napi_create_string_utf8(env, workName.data(), NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, resource, resourceName, execute, complete, static_cast(context), &context->work_); - napi_queue_async_work_with_qos(env, context->work_, napi_qos_default); + napi_queue_async_work_with_qos(env, context->work_, napi_qos_user_initiated); HiLog::Debug(LABEL, "HandleAsyncWork end."); return result; } -- Gitee From a19c61a9b7fcd8f58b8e862f8a3f7ccf11ffdcc5 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 7 Mar 2024 11:16:13 +0800 Subject: [PATCH 27/28] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- frameworks/config_policy/src/config_policy_utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index 54d8ca3..c618837 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -97,7 +97,7 @@ static char *CustGetSystemParam(const char *name) char *value = NULL; unsigned int len = 0; - if (SystemGetParameter(name, NULL, &len) != 0 || len == 0) { + if (SystemGetParameter(name, NULL, &len) != 0 || len <= 0 || len > PARAM_CONST_VALUE_LEN_MAX) { return NULL; } value = (char *)calloc(len, sizeof(char)); @@ -290,8 +290,11 @@ static char *TrimInplace(char *str, bool moveToStart) static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) { + if (holder == NULL || s == NULL) { + return false; + } if (holder->size < leastSize) { - size_t allocSize = Max(leastSize * 2, MIN_APPEND_LEN); + size_t allocSize = Min(Max(leastSize * 2, MIN_APPEND_LEN), PARAM_CONST_VALUE_LEN_MAX); char *newPtr = (char *)calloc(allocSize, sizeof(char)); if (newPtr == NULL) { allocSize = leastSize; @@ -313,6 +316,9 @@ static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) static bool AppendStr(StringHolder *holder, const char *s) { + if (holder == NULL || s == NULL) { + return false; + } size_t leastSize = holder->strLen + strlen(s) + 1; if (!EnsureHolderSpace(holder, leastSize)) { return false; -- Gitee From 475ee2950cc30e3947d7cca15b26db8cdd640a22 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 7 Mar 2024 11:36:50 +0800 Subject: [PATCH 28/28] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- frameworks/config_policy/src/config_policy_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index c618837..6f14f82 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -290,7 +290,7 @@ static char *TrimInplace(char *str, bool moveToStart) static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) { - if (holder == NULL || s == NULL) { + if (holder == NULL) { return false; } if (holder->size < leastSize) { -- Gitee