From d91860d3506cb3ffb78a3850ce0355f657d6a771 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Tue, 23 May 2023 12:06:18 +0800 Subject: [PATCH 1/5] codestyle mod Signed-off-by: genglingxia --- framework/common/tlv_util.h | 4 ++-- framework/innerkitsimpl/test/unittest/udmf_client_test.cpp | 7 ++++--- framework/jskitsimpl/common/napi_error_utils.cpp | 2 +- framework/manager/permission/checker_manager.cpp | 2 +- framework/manager/permission/checker_manager.h | 2 +- framework/manager/permission/data_checker.cpp | 3 ++- framework/manager/permission/data_checker.h | 2 +- framework/manager/store/runtime_store.cpp | 2 +- framework/manager/store/runtime_store.h | 2 +- interfaces/innerkits/common/unified_types.h | 6 +++--- interfaces/jskits/common/napi_error_utils.h | 2 +- 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/framework/common/tlv_util.h b/framework/common/tlv_util.h index 1f90001..5e5f6bd 100755 --- a/framework/common/tlv_util.h +++ b/framework/common/tlv_util.h @@ -231,7 +231,7 @@ bool CountBufferSize(const Runtime &input, TLVObject &data) { data.Count(input.key); data.Count(input.isPrivate); - int32_t size = input.privileges.size(); + uint32_t size = input.privileges.size(); data.Count(size); for (int i = 0; i < size; ++i) { data.Count(input.privileges[i]); @@ -1206,7 +1206,7 @@ bool Writing(const Runtime &input, TLVObject &data) if (!Writing(input.isPrivate, data)) { return false; } - int32_t size = input.privileges.size(); + uint32_t size = input.privileges.size(); if (!Writing(size, data)) { return false; } diff --git a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp index abab11d..d437dc2 100755 --- a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp +++ b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp @@ -41,7 +41,7 @@ using namespace testing::ext; using namespace OHOS::Security::AccessToken; using namespace OHOS::UDMF; using namespace OHOS; - +namespace OHOS::Test { class UdmfClientTest : public testing::Test { public: static void SetUpTestCase(); @@ -176,7 +176,7 @@ void UdmfClientTest::AddPrivilege(QueryOption &option) void UdmfClientTest::CompareDetails(const UDDetails &details) { - for (auto &detail : details) { + for (const auto &detail : details) { auto key = detail.first; EXPECT_EQ(key, "udmf_key"); auto value = detail.second; @@ -1246,4 +1246,5 @@ HWTEST_F(UdmfClientTest, GetSelfData002, TestSize.Level1) GetEmptyData(option2); LOG_INFO(UDMF_TEST, "GetSelfData002 end."); -} \ No newline at end of file +} +} // OHOS::Test \ No newline at end of file diff --git a/framework/jskitsimpl/common/napi_error_utils.cpp b/framework/jskitsimpl/common/napi_error_utils.cpp index 37c74a9..ac4e673 100644 --- a/framework/jskitsimpl/common/napi_error_utils.cpp +++ b/framework/jskitsimpl/common/napi_error_utils.cpp @@ -64,7 +64,7 @@ Status GenerateNapiError(Status error, int32_t &errCode, std::string &errMessage return error; } -void ThrowNapiError(napi_env env, int32_t status, std::string errMessage, bool isParamsCheck) +void ThrowNapiError(napi_env env, int32_t status, const std::string errMessage, bool isParamsCheck) { LOG_INFO(UDMF_KITS_NAPI, "ThrowNapiError message: %{public}s", errMessage.c_str()); if (status == Status::E_OK) { diff --git a/framework/manager/permission/checker_manager.cpp b/framework/manager/permission/checker_manager.cpp index 78f3634..09c5d74 100755 --- a/framework/manager/permission/checker_manager.cpp +++ b/framework/manager/permission/checker_manager.cpp @@ -33,7 +33,7 @@ void CheckerManager::RegisterChecker(const std::string &checker, std::functioncheckers_.find(key) != this->checkers_.end()) { return false; } diff --git a/framework/manager/permission/checker_manager.h b/framework/manager/permission/checker_manager.h index e1d09a0..7c14745 100755 --- a/framework/manager/permission/checker_manager.h +++ b/framework/manager/permission/checker_manager.h @@ -27,7 +27,7 @@ class CheckerManager { public: struct CheckInfo { uint32_t tokenId; - uint32_t pid; + int32_t pid; }; class Checker { diff --git a/framework/manager/permission/data_checker.cpp b/framework/manager/permission/data_checker.cpp index 7b4c376..3cdba20 100755 --- a/framework/manager/permission/data_checker.cpp +++ b/framework/manager/permission/data_checker.cpp @@ -31,13 +31,14 @@ DataChecker::~DataChecker() { } -bool DataChecker::IsValid(std::vector &privileges, const CheckerManager::CheckInfo &info) +bool DataChecker::IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) { for (const auto privilege : privileges) { if (privilege.tokenId == info.tokenId || privilege.pid == info.pid) { return true; } } + LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters, %{public}s, %{public}s", Anonymous::Change(std::to_string(info.tokenId)).c_str(), Anonymous::Change(std::to_string(info.pid)).c_str()); diff --git a/framework/manager/permission/data_checker.h b/framework/manager/permission/data_checker.h index 1c2ac0f..5aec008 100755 --- a/framework/manager/permission/data_checker.h +++ b/framework/manager/permission/data_checker.h @@ -25,7 +25,7 @@ public: DataChecker() noexcept; ~DataChecker(); - bool IsValid(std::vector &privileges, const CheckerManager::CheckInfo &info) override; + bool IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) override; private: static DataChecker instance_; diff --git a/framework/manager/store/runtime_store.cpp b/framework/manager/store/runtime_store.cpp index e8a2bca..5f17f9a 100755 --- a/framework/manager/store/runtime_store.cpp +++ b/framework/manager/store/runtime_store.cpp @@ -30,7 +30,7 @@ const std::string RuntimeStore::DATA_PREFIX = "udmf://"; const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/distributeddata"; const std::int32_t RuntimeStore::SLASH_COUNT_IN_KEY = 4; -RuntimeStore::RuntimeStore(std::string storeId) : storeId_({ storeId }) +RuntimeStore::RuntimeStore(const std::string &storeId) : storeId_({ storeId }) { LOG_INFO(UDMF_SERVICE, "Construct runtimeStore: %{public}s.", storeId_.storeId.c_str()); } diff --git a/framework/manager/store/runtime_store.h b/framework/manager/store/runtime_store.h index dde13c3..32d0b91 100755 --- a/framework/manager/store/runtime_store.h +++ b/framework/manager/store/runtime_store.h @@ -24,7 +24,7 @@ namespace OHOS { namespace UDMF { class RuntimeStore final : public Store { public: - explicit RuntimeStore(std::string storeId); + explicit RuntimeStore(const std::string &storeId); ~RuntimeStore(); Status Put(const UnifiedData &unifiedData) override; Status Get(const std::string &key, UnifiedData &unifiedData) override; diff --git a/interfaces/innerkits/common/unified_types.h b/interfaces/innerkits/common/unified_types.h index 1db8358..0f9b7d4 100755 --- a/interfaces/innerkits/common/unified_types.h +++ b/interfaces/innerkits/common/unified_types.h @@ -37,7 +37,7 @@ struct Summary { }; struct Privilege { - int32_t tokenId; + uint32_t tokenId; int32_t pid; std::string readPermission; std::string writePermission; @@ -68,7 +68,7 @@ struct Runtime { */ struct CustomOption { Intention intention{}; - int32_t tokenId{}; + uint32_t tokenId{}; }; /* @@ -76,7 +76,7 @@ struct CustomOption { */ struct QueryOption { std::string key; - int32_t tokenId{}; + uint32_t tokenId{}; int32_t pid{}; }; } // namespace UDMF diff --git a/interfaces/jskits/common/napi_error_utils.h b/interfaces/jskits/common/napi_error_utils.h index b030e5b..85a4180 100644 --- a/interfaces/jskits/common/napi_error_utils.h +++ b/interfaces/jskits/common/napi_error_utils.h @@ -37,7 +37,7 @@ struct NapiErrorCode { const std::optional GetErrorCode(int32_t errorCode); Status GenerateNapiError(Status error, int32_t &errCode, std::string &errMessage); -void ThrowNapiError(napi_env env, int32_t errCode, std::string errMessage, bool isParamsCheck = true); +void ThrowNapiError(napi_env env, int32_t errCode, const std::string errMessage, bool isParamsCheck = true); napi_value GenerateErrorMsg(napi_env env, NapiErrorCode jsInfo); #define ASSERT_ERR(env, assertion, errorcode, message) \ -- Gitee From 9d3495ad35f514f53cba26478c014b7f5d014a2c Mon Sep 17 00:00:00 2001 From: genglingxia Date: Tue, 23 May 2023 17:11:38 +0800 Subject: [PATCH 2/5] fix reviex opinions Signed-off-by: genglingxia --- framework/jskitsimpl/common/napi_error_utils.cpp | 2 +- interfaces/jskits/common/napi_error_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/jskitsimpl/common/napi_error_utils.cpp b/framework/jskitsimpl/common/napi_error_utils.cpp index ac4e673..7f18ae9 100644 --- a/framework/jskitsimpl/common/napi_error_utils.cpp +++ b/framework/jskitsimpl/common/napi_error_utils.cpp @@ -64,7 +64,7 @@ Status GenerateNapiError(Status error, int32_t &errCode, std::string &errMessage return error; } -void ThrowNapiError(napi_env env, int32_t status, const std::string errMessage, bool isParamsCheck) +void ThrowNapiError(napi_env env, int32_t status, const std::string &errMessage, bool isParamsCheck) { LOG_INFO(UDMF_KITS_NAPI, "ThrowNapiError message: %{public}s", errMessage.c_str()); if (status == Status::E_OK) { diff --git a/interfaces/jskits/common/napi_error_utils.h b/interfaces/jskits/common/napi_error_utils.h index 85a4180..58eec69 100644 --- a/interfaces/jskits/common/napi_error_utils.h +++ b/interfaces/jskits/common/napi_error_utils.h @@ -37,7 +37,7 @@ struct NapiErrorCode { const std::optional GetErrorCode(int32_t errorCode); Status GenerateNapiError(Status error, int32_t &errCode, std::string &errMessage); -void ThrowNapiError(napi_env env, int32_t errCode, const std::string errMessage, bool isParamsCheck = true); +void ThrowNapiError(napi_env env, int32_t errCode, const std::string &errMessage, bool isParamsCheck = true); napi_value GenerateErrorMsg(napi_env env, NapiErrorCode jsInfo); #define ASSERT_ERR(env, assertion, errorcode, message) \ -- Gitee From 175394d8203dc052ebd37df620d955b9a5b5decd Mon Sep 17 00:00:00 2001 From: genglingxia Date: Wed, 24 May 2023 15:02:19 +0800 Subject: [PATCH 3/5] review fix Signed-off-by: genglingxia --- framework/common/tlv_object.h | 6 ++++++ framework/common/tlv_util.h | 16 +++++++++++----- framework/manager/permission/checker_manager.cpp | 2 +- framework/manager/permission/checker_manager.h | 4 ++-- framework/manager/permission/data_checker.cpp | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/framework/common/tlv_object.h b/framework/common/tlv_object.h index 6d42d34..bb70810 100755 --- a/framework/common/tlv_object.h +++ b/framework/common/tlv_object.h @@ -34,6 +34,7 @@ enum TAG : uint16_t { TAG_VECTOR, TAG_MAP, TAG_BUTT, + TAG_SIZE_T, }; #pragma pack(1) @@ -65,6 +66,11 @@ public: return *buffer_; } + void Count(const size_t value) + { + total_ += sizeof(value) + sizeof(TLVHead); + } + void Count(const int32_t value) { total_ += sizeof(value) + sizeof(TLVHead); diff --git a/framework/common/tlv_util.h b/framework/common/tlv_util.h index 5e5f6bd..fba8ec3 100755 --- a/framework/common/tlv_util.h +++ b/framework/common/tlv_util.h @@ -231,9 +231,9 @@ bool CountBufferSize(const Runtime &input, TLVObject &data) { data.Count(input.key); data.Count(input.isPrivate); - uint32_t size = input.privileges.size(); + size_t size = input.privileges.size(); data.Count(size); - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { data.Count(input.privileges[i]); } data.Count(static_cast(input.createTime)); @@ -258,6 +258,12 @@ bool Writing(const int32_t &input, TLVObject &data) return data.WriteBasic(TAG_INT32, input); } +template<> +bool Writing(const size_t &input, TLVObject &data) +{ + return data.WriteBasic(TAG_SIZE_T, input); +} + template<> bool Reading(int32_t &output, TLVObject &data) { @@ -1151,7 +1157,7 @@ bool Writing(const Privilege &input, TLVObject &data) template<> bool Reading(Privilege &output, TLVObject &data) { - int32_t tokenId; + uint32_t tokenId; int32_t pid; std::string readPermission; std::string writePermission; @@ -1206,11 +1212,11 @@ bool Writing(const Runtime &input, TLVObject &data) if (!Writing(input.isPrivate, data)) { return false; } - uint32_t size = input.privileges.size(); + size_t size = input.privileges.size(); if (!Writing(size, data)) { return false; } - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { if (!Writing(input.privileges[i], data)) { return false; } diff --git a/framework/manager/permission/checker_manager.cpp b/framework/manager/permission/checker_manager.cpp index 09c5d74..1e92539 100755 --- a/framework/manager/permission/checker_manager.cpp +++ b/framework/manager/permission/checker_manager.cpp @@ -46,7 +46,7 @@ void CheckerManager::LoadCheckers() }); } -bool CheckerManager::IsValid(std::vector &privileges, const CheckInfo &info) +bool CheckerManager::IsValid(const std::vector &privileges, const CheckInfo &info) { auto it = checkers_.find(DATA_CHECKER); if (it == checkers_.end()) { diff --git a/framework/manager/permission/checker_manager.h b/framework/manager/permission/checker_manager.h index 7c14745..c368b15 100755 --- a/framework/manager/permission/checker_manager.h +++ b/framework/manager/permission/checker_manager.h @@ -32,7 +32,7 @@ public: class Checker { public: - virtual bool IsValid(std::vector &privileges, const CheckInfo &info) = 0; + virtual bool IsValid(const std::vector &privileges, const CheckInfo &info) = 0; protected: ~Checker() = default; }; @@ -41,7 +41,7 @@ public: void RegisterChecker(const std::string &checker, std::function getter); void LoadCheckers(); - bool IsValid(std::vector &privileges, const CheckInfo &info); + bool IsValid(const std::vector &privileges, const CheckInfo &info); private: std::map checkers_; diff --git a/framework/manager/permission/data_checker.cpp b/framework/manager/permission/data_checker.cpp index 3cdba20..804e1d0 100755 --- a/framework/manager/permission/data_checker.cpp +++ b/framework/manager/permission/data_checker.cpp @@ -33,7 +33,7 @@ DataChecker::~DataChecker() bool DataChecker::IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) { - for (const auto privilege : privileges) { + for (const auto &privilege : privileges) { if (privilege.tokenId == info.tokenId || privilege.pid == info.pid) { return true; } -- Gitee From 537989f2002e78d630e62959a7341b0899c31056 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Wed, 24 May 2023 18:23:27 +0800 Subject: [PATCH 4/5] fix conflict Signed-off-by: genglingxia --- framework/common/tlv_util.cpp | 22 +++++++++++++++++----- framework/common/tlv_util.h | 7 +++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/framework/common/tlv_util.cpp b/framework/common/tlv_util.cpp index 6bab0b1..0402808 100644 --- a/framework/common/tlv_util.cpp +++ b/framework/common/tlv_util.cpp @@ -217,9 +217,9 @@ bool CountBufferSize(const Runtime &input, TLVObject &data) { data.Count(input.key); data.Count(input.isPrivate); - int32_t size = input.privileges.size(); + size_t size = input.privileges.size(); data.Count(size); - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { data.Count(input.privileges[i]); } data.Count(static_cast(input.createTime)); @@ -244,6 +244,12 @@ bool Writing(const int32_t &input, TLVObject &data) return data.WriteBasic(TAG_INT32, input); } +template<> +bool Writing(const size_t &input, TLVObject &data) +{ + return data.WriteBasic(TAG_SIZE_T, input); +} + template<> bool Reading(int32_t &output, TLVObject &data) { @@ -262,6 +268,12 @@ bool Reading(int64_t &output, TLVObject &data) return data.ReadBasic(output); } +template<> +bool Reading(size_t &output, TLVObject &data) +{ + return data.ReadBasic(output); +} + template<> bool Writing(const bool &input, TLVObject &data) { @@ -1186,7 +1198,7 @@ bool Writing(const Privilege &input, TLVObject &data) template<> bool Reading(Privilege &output, TLVObject &data) { - int32_t tokenId; + uint32_t tokenId; int32_t pid; std::string readPermission; std::string writePermission; @@ -1241,11 +1253,11 @@ bool Writing(const Runtime &input, TLVObject &data) if (!Writing(input.isPrivate, data)) { return false; } - int32_t size = input.privileges.size(); + size_t size = input.privileges.size(); if (!Writing(size, data)) { return false; } - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { if (!Writing(input.privileges[i], data)) { return false; } diff --git a/framework/common/tlv_util.h b/framework/common/tlv_util.h index 487ba38..a36e73f 100755 --- a/framework/common/tlv_util.h +++ b/framework/common/tlv_util.h @@ -19,6 +19,7 @@ #include #include "application_defined_record.h" +#include "audio.h" #include "file.h" #include "folder.h" #include "html.h" @@ -60,6 +61,9 @@ bool Writing(const int32_t &input, TLVObject &data); template<> bool Reading(int32_t &output, TLVObject &data); +template<> +bool Writing(const size_t &input, TLVObject &data); + template<> bool Writing(const int64_t &input, TLVObject &data); template<> @@ -70,6 +74,9 @@ bool Writing(const bool &input, TLVObject &data); template<> bool Reading(bool &output, TLVObject &data); +template<> +bool Reading(size_t &output, TLVObject &data); + template<> bool Writing(const std::string &input, TLVObject &data); template<> -- Gitee From 71614a833306f4e723c47e92979f22645a65c876 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Wed, 24 May 2023 21:34:46 +0800 Subject: [PATCH 5/5] fix review Signed-off-by: genglingxia --- framework/common/tlv_object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/common/tlv_object.h b/framework/common/tlv_object.h index 21af2c2..fd4b552 100755 --- a/framework/common/tlv_object.h +++ b/framework/common/tlv_object.h @@ -28,13 +28,13 @@ namespace UDMF { enum TAG : uint16_t { TAG_INT32 = 0x0000, TAG_INT64, + TAG_SIZE_T, TAG_BOOL, TAG_DOUBLE, TAG_STRING, TAG_VECTOR, TAG_MAP, TAG_BUTT, - TAG_SIZE_T, }; #pragma pack(1) -- Gitee