diff --git a/services/implementation/BUILD.gn b/services/implementation/BUILD.gn index 2fcda9634f23d75fb0b37dd8f388bddcc3a57f41..949270521df8b2f2a8ac2b22e1b5af20ac04ad6a 100644 --- a/services/implementation/BUILD.gn +++ b/services/implementation/BUILD.gn @@ -206,6 +206,7 @@ if (defined(ohos_lite)) { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9dc318af6b6d7e49919b5e5dd015ed75c11457f6..1178814f07872483df0451aa74dedb0775ba8196 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -636,8 +636,6 @@ void DmAuthManager::ProcessSinkMsg() void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string message) { - LOGI("sessionId %{public}d, authResponseContext_->sessionId %{public}d.", sessionId, - authResponseContext_->sessionId); if (authResponseContext_ == nullptr || authMessageProcessor_ == nullptr || sessionId != authResponseContext_->sessionId) { LOGE("OnDataReceived failed, authResponseContext or authMessageProcessor_ is nullptr."); @@ -2408,8 +2406,6 @@ void DmAuthManager::ProcIncompatible(const int32_t &sessionId) void DmAuthManager::OnAuthDeviceDataReceived(const int32_t sessionId, const std::string message) { - LOGI("sessionId %{public}d, authResponseContext_->sessionId %{public}d.", sessionId, - authResponseContext_->sessionId); if (authResponseContext_ == nullptr || authMessageProcessor_ == nullptr || hiChainAuthConnector_ == nullptr || authResponseContext_->sessionId != sessionId) { LOGE("OnAuthDeviceDataReceived param is invalid"); diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 4bce015e48a48ebc839788d4e3f95341e0d3e5fe..09cf86e4380c7b8c6ebffa1681226101af33be3b 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -18,6 +18,7 @@ #include "dm_anonymous.h" #include "hichain_connector_callback.h" #include "parameter.h" +#include "cJSON.h" namespace OHOS { namespace DistributedHardware { @@ -165,11 +166,11 @@ int32_t HiChainAuthConnector::GenerateCredential(std::string &localUdid, int32_t char *returnData = nullptr; if (ProcessCredential(CRED_OP_CREATE, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain generate credential failed."); - DeleteArrayPtr(returnData); + cJSON_free(returnData); return ERR_DM_FAILED; } std::string returnDataStr = static_cast(returnData); - DeleteArrayPtr(returnData); + cJSON_free(returnData); nlohmann::json jsonObject = nlohmann::json::parse(returnDataStr, nullptr, false); if (jsonObject.is_discarded()) { LOGE("Decode generate return data jsonStr error."); @@ -200,11 +201,11 @@ bool HiChainAuthConnector::QueryCredential(std::string &localUdid, int32_t osAcc char *returnData = nullptr; if (ProcessCredential(CRED_OP_QUERY, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); - DeleteArrayPtr(returnData); + cJSON_free(returnData); return false; } std::string returnDataStr = static_cast(returnData); - DeleteArrayPtr(returnData); + cJSON_free(returnData); nlohmann::json jsonObject = nlohmann::json::parse(returnDataStr, nullptr, false); if (jsonObject.is_discarded()) { LOGE("Decode query return data jsonStr error."); @@ -233,11 +234,11 @@ int32_t HiChainAuthConnector::GetCredential(std::string &localUdid, int32_t osAc char *returnData = nullptr; if (ProcessCredential(CRED_OP_QUERY, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); - DeleteArrayPtr(returnData); + cJSON_free(returnData); return ERR_DM_FAILED; } std::string returnDataStr = static_cast(returnData); - DeleteArrayPtr(returnData); + cJSON_free(returnData); nlohmann::json jsonObject = nlohmann::json::parse(returnDataStr, nullptr, false); if (jsonObject.is_discarded()) { LOGE("Decode query return data jsonStr error."); @@ -267,11 +268,11 @@ int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, std::string char *returnData = nullptr; if (ProcessCredential(CRED_OP_IMPORT, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); - DeleteArrayPtr(returnData); + cJSON_free(returnData); return ERR_DM_FAILED; } std::string returnDataStr = static_cast(returnData); - DeleteArrayPtr(returnData); + cJSON_free(returnData); nlohmann::json jsonObject = nlohmann::json::parse(returnDataStr, nullptr, false); if (jsonObject.is_discarded()) { LOGE("Decode import return data jsonStr error."); @@ -300,11 +301,11 @@ int32_t HiChainAuthConnector::DeleteCredential(const std::string &deviceId, int3 char *returnData = nullptr; if (ProcessCredential(CRED_OP_DELETE, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); - DeleteArrayPtr(returnData); + cJSON_free(returnData); return false; } std::string returnDataStr = static_cast(returnData); - DeleteArrayPtr(returnData); + cJSON_free(returnData); nlohmann::json jsonObject = nlohmann::json::parse(returnDataStr, nullptr, false); if (jsonObject.is_discarded()) { LOGE("Decode import return data jsonStr error."); diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 79610f8923e6666ddfeb319a69196cb240ac4cd9..0da7cff7714eeb3203b74c4028312827e3be5809 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -243,7 +243,7 @@ bool HiChainConnector::GetGroupInfoCommon(const int32_t userId, const std::strin int32_t ret = deviceGroupManager_->getGroupInfo(userId, pkgName, queryParams.c_str(), &groupVec, &num); if (ret != 0) { LOGE("[HICHAIN]fail to get group info with ret:%{public}d.", ret); - DeleteArrayPtr(groupVec); + deviceGroupManager_->destroyInfo(&groupVec); return false; } if (groupVec == nullptr) { @@ -252,13 +252,12 @@ bool HiChainConnector::GetGroupInfoCommon(const int32_t userId, const std::strin } if (num == 0) { LOGE("[HICHAIN]return groups info number is zero."); - DeleteArrayPtr(groupVec); + deviceGroupManager_->destroyInfo(&groupVec); return false; } LOGI("HiChainConnector::GetGroupInfo groupNum(%{public}u)", num); std::string relatedGroups = std::string(groupVec); deviceGroupManager_->destroyInfo(&groupVec); - DeleteArrayPtr(groupVec); nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); if (jsonObject.is_discarded()) { LOGE("returnGroups parse error"); @@ -832,13 +831,12 @@ int32_t HiChainConnector::getRegisterInfo(const std::string &queryParams, std::s char *credentialInfo = nullptr; if (deviceGroupManager_->getRegisterInfo(queryParams.c_str(), &credentialInfo) != DM_OK) { LOGE("[HICHAIN]fail to request hichain registerinfo."); - DeleteArrayPtr(credentialInfo); + deviceGroupManager_->destroyInfo(&credentialInfo); return ERR_DM_FAILED; } returnJsonStr = credentialInfo; deviceGroupManager_->destroyInfo(&credentialInfo); - DeleteArrayPtr(credentialInfo); LOGI("request hichain device registerinfo successfully."); return DM_OK; } @@ -1063,6 +1061,7 @@ std::vector HiChainConnector::GetTrustedDevices(const std::string & &devicesJson, &devNum); if (ret != 0 || devicesJson == nullptr) { LOGE("[HICHAIN]failed to get trusted devicesJson, ret: %{public}d", ret); + deviceGroupManager_->destroyInfo(&devicesJson); return {}; } GetTrustedDevicesUdid(devicesJson, trustedDevices); @@ -1125,7 +1124,7 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(const std::string &deviceId, co deviceGroupManager_->getRelatedGroups(userId, pkgName, deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { LOGE("[HICHAIN] fail to get related groups with ret:%{public}d.", ret); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); return ERR_DM_FAILED; } if (returnGroups == nullptr) { @@ -1134,11 +1133,11 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(const std::string &deviceId, co } if (groupNum == 0) { LOGE("[HICHAIN]return related goups number is zero."); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); return ERR_DM_FAILED; } std::string relatedGroups = std::string(returnGroups); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); if (jsonObject.is_discarded()) { LOGE("returnGroups parse error"); @@ -1189,7 +1188,7 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(int32_t userId, const std::stri deviceGroupManager_->getRelatedGroups(userId, pkgName, deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { LOGE("[HICHAIN] fail to get related groups with ret:%{public}d.", ret); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); return ERR_DM_FAILED; } if (returnGroups == nullptr) { @@ -1198,11 +1197,11 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(int32_t userId, const std::stri } if (groupNum == 0) { LOGE("[HICHAIN]return related goups number is zero."); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); return ERR_DM_FAILED; } std::string relatedGroups = std::string(returnGroups); - DeleteArrayPtr(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); if (jsonObject.is_discarded()) { LOGE("returnGroups parse error");