diff --git a/framework/common/tlv_object.h b/framework/common/tlv_object.h index 80f2b717bd3b4f622bf96372fce2c5128f996381..fd4b552534b9b500117325a6c3cccb027ac9c297 100755 --- a/framework/common/tlv_object.h +++ b/framework/common/tlv_object.h @@ -28,6 +28,7 @@ namespace UDMF { enum TAG : uint16_t { TAG_INT32 = 0x0000, TAG_INT64, + TAG_SIZE_T, TAG_BOOL, TAG_DOUBLE, TAG_STRING, @@ -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.cpp b/framework/common/tlv_util.cpp index 6bab0b1ff81882eb68b8ebb44db413a7d7a2bf36..0402808efbf01ae05129213692ce50ffc38b6519 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 cc7500403d3da146c8b42173277c1b4cb437436a..a36e73f5bd63e34a3ddb128cf5b771ea9c738946 100755 --- a/framework/common/tlv_util.h +++ b/framework/common/tlv_util.h @@ -61,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<> @@ -71,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<> diff --git a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp index da5553dd00601f96acbf69e370512beece75b6b0..bb631270321f1d8d9b2db107dd2f538c7194760d 100755 --- a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp +++ b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp @@ -42,7 +42,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(); @@ -177,7 +177,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; @@ -1395,4 +1395,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 37c74a9193e20a29b46991d7ca45704fa3e59807..7f18ae9eb01371fce903b46d3b95cc4cbcac2719 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 78f36349ec5509e157d1db5538bd7dcfef32666c..1e9253980a27dfa91fdeb5cbd0e150dc26d167e4 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; } @@ -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 e1d09a05fc27f9c7eb51b63414f0ef935328964e..c368b15a13a051aaa077c94c76a8e5dc9c7346a1 100755 --- a/framework/manager/permission/checker_manager.h +++ b/framework/manager/permission/checker_manager.h @@ -27,12 +27,12 @@ class CheckerManager { public: struct CheckInfo { uint32_t tokenId; - uint32_t pid; + int32_t pid; }; 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 7b4c37603e41be0963089d7a27a5848ce82fac14..804e1d0a9e0cfeb9bb00def109c249a873cb46a6 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) { + 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 1c2ac0f1bc0205109e87a0f519097f13141440fc..5aec008f8df7eac1bb061da46bacd1863c35318d 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 fa5e8c6ecac4ec784af36497f92ccf147d6ff9e1..11fafd721d65a4739a1e92150b7d94178a45d8b8 100755 --- a/framework/manager/store/runtime_store.cpp +++ b/framework/manager/store/runtime_store.cpp @@ -29,7 +29,7 @@ const AppId RuntimeStore::APP_ID = { "distributeddata" }; const std::string RuntimeStore::DATA_PREFIX = "udmf://"; const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/distributeddata"; -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 597d0f5110bba894131ac4b3a597312bfcd392f5..ff21586e1575d57dfa9bdce18a8dbc501ff99866 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 506a5c7d648fc0c0e5db088229b4cd9cf7994145..600ff04d5e403b2d8d72a8284d921a070ce4e02c 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 928b66f2d93129bb97c377d8ba19527e7c64d268..51a526406c36bf55ae12e368bf9f92a0c3e04b45 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) \