From 7d424ce8ff51a50a750f9a2580385726db937677 Mon Sep 17 00:00:00 2001 From: oh_ci Date: Sat, 16 Aug 2025 05:48:13 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1146=20?= =?UTF-8?q?:=20change=20HcStrcmp=20to=20IsStrEqual=20and=20add=20UT'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common_lib/impl/src/json_utils.c | 2 +- common_lib/impl/src/string_util.c | 9 +-- common_lib/interfaces/string_util.h | 6 +- .../os_adapter/impl/src/linux/hc_file.c | 4 +- .../impl/src/liteos/mini/hc_file_posix.c | 4 +- .../src/sa_load_on_demand.cpp | 4 +- frameworks/src/lite/ipc_adapt.c | 6 +- frameworks/src/standard/ipc_adapt.cpp | 4 +- .../src/credential_data_manager.c | 12 +-- .../src/group_data_manager.c | 24 +++--- .../src/hiview_adapter/hidump_adapter.c | 4 +- .../src/hiview_adapter/performance_dumper.c | 6 +- .../security_label_adapter.c | 4 +- .../listener/src/cred_listener.c | 4 +- .../identity_service/src/identity_operation.c | 18 ++--- .../creds_manager/asy_token_manager.c | 16 ++-- .../creds_manager/sym_token_manager.c | 6 +- .../common/das_task_common.c | 4 +- .../src/account_unrelated/das_task_main.c | 4 +- .../src/broadcast_manager/broadcast_manager.c | 6 +- .../src/callback_manager/callback_manager.c | 8 +- .../across_account_group.c | 8 +- .../src/group_operation/group_operation.c | 2 +- .../group_operation_common.c | 10 +-- .../identical_account_group.c | 4 +- .../src/credential_operator.c | 4 +- .../src/pseudonym_manager.c | 18 ++--- .../session_manager/src/dev_session_mgr.c | 2 +- .../compatible_bind_sub_session_common.c | 4 +- .../src/session/v2/dev_session_util.c | 4 +- .../expand_process_lib/save_trusted_info.c | 4 +- test/unittest/deviceauth/BUILD.gn | 3 +- .../deviceauth_identity_service_test.cpp | 2 +- .../source/identity_service_ipc_test.cpp | 4 +- .../deviceauth/source/json_utils_mock.c | 4 +- .../unit_test/source/common_lib_test.cpp | 15 +--- .../source/group_data_manager_test.cpp | 81 ------------------- 37 files changed, 116 insertions(+), 208 deletions(-) delete mode 100644 test/unittest/deviceauth/unit_test/source/group_data_manager_test.cpp diff --git a/common_lib/impl/src/json_utils.c b/common_lib/impl/src/json_utils.c index f6887bbc..a62c4833 100644 --- a/common_lib/impl/src/json_utils.c +++ b/common_lib/impl/src/json_utils.c @@ -101,7 +101,7 @@ void DeleteAllItemExceptOne(CJson *jsonObj, const char *key) CJson *nextItem = NULL; while (curItem != NULL) { nextItem = curItem->next; - if (!IsStrEqual(key, curItem->string)) { + if (HcStrcmp(key, curItem->string) != 0) { cJSON_Delete(cJSON_DetachItemViaPointer(jsonObj, curItem)); } curItem = nextItem; diff --git a/common_lib/impl/src/string_util.c b/common_lib/impl/src/string_util.c index a0ee6f8a..421ee94b 100644 --- a/common_lib/impl/src/string_util.c +++ b/common_lib/impl/src/string_util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -174,11 +174,10 @@ int32_t GetAnonymousString(const char *originStr, char *anonymousStr, uint32_t a return CLIB_SUCCESS; } -bool IsStrEqual(const char *str1, const char *str2) +int HcStrcmp(const char *str1, const char *str2) { if (str1 == NULL || str2 == NULL) { - return false; + return CLIB_FAILED; } - - return strcmp(str1, str2) == 0; + return strcmp(str1, str2); } \ No newline at end of file diff --git a/common_lib/interfaces/string_util.h b/common_lib/interfaces/string_util.h index d199c938..41d03dff 100644 --- a/common_lib/interfaces/string_util.h +++ b/common_lib/interfaces/string_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -97,9 +97,9 @@ int32_t GetAnonymousString(const char *originStr, char *anonymousStr, uint32_t a * Safe compare two strings. * @param str1: the first string. * @param str2: the second string. - * @return false if str1 or str2 is NULL else return strcmp(str1, str2) == 0. + * @return if str1 or str2 is NULL return CLIB_FAILED(-1), else return strcmp(str1, str2). */ -bool IsStrEqual(const char *str1, const char *str2); +int HcStrcmp(const char *str1, const char *str2); #ifdef __cplusplus } diff --git a/deps_adapter/os_adapter/impl/src/linux/hc_file.c b/deps_adapter/os_adapter/impl/src/linux/hc_file.c index 5eb4d8ea..51fc83b5 100644 --- a/deps_adapter/os_adapter/impl/src/linux/hc_file.c +++ b/deps_adapter/os_adapter/impl/src/linux/hc_file.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -201,7 +201,7 @@ void HcFileGetSubFileName(const char *path, StringVector *nameVec) return; } while ((entry = readdir(dir)) != NULL) { - if (IsStrEqual(entry->d_name, ".") || IsStrEqual(entry->d_name, "..")) { + if ((HcStrcmp(entry->d_name, ".") == 0) || (HcStrcmp(entry->d_name, "..") == 0)) { continue; } HcString subFileName = CreateString(); diff --git a/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file_posix.c b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file_posix.c index b6141bbf..7df252a9 100644 --- a/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file_posix.c +++ b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file_posix.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 Huawei Device Co., Ltd. + * 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 @@ -202,7 +202,7 @@ void HcFileGetSubFileName(const char *path, StringVector *nameVec) return; } while ((entry = readdir(dir)) != NULL) { - if (IsStrEqual(entry->d_name, ".") || IsStrEqual(entry->d_name, "..")) { + if ((HcStrcmp(entry->d_name, ".") == 0) || (HcStrcmp(entry->d_name, "..") == 0)) { continue; } HcString subFileName = CreateString(); diff --git a/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp b/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp index 81686260..34676e27 100644 --- a/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp +++ b/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp @@ -189,7 +189,7 @@ static bool UpdateCallbackInfoIfExist(const char *appId, const DeviceAuthCallbac if (entry == nullptr || entry->appId == nullptr) { continue; } - if (IsStrEqual(entry->appId, appId) && entry->callbackType == callbackType) { + if (HcStrcmp(entry->appId, appId) == 0 && entry->callbackType == callbackType) { LOGI("[SDK]:start to update callback, appId: %" LOG_PUB "s, callbackType: %" LOG_PUB "d", appId, callbackType); bool ret = UpdateCallback(entry, callback, dataChangeListener, listener, index); @@ -287,7 +287,7 @@ int32_t RemoveCallbackInfoFromList(const char *appId, int32_t callbackType) if (entry == nullptr || entry->appId == nullptr) { continue; } - if (IsStrEqual(entry->appId, appId) && entry->callbackType == callbackType) { + if (HcStrcmp(entry->appId, appId) == 0 && entry->callbackType == callbackType) { LOGW("[SDK]: start to remove callbackInfo."); DevAuthCallbackInfo deleteCallbackInfo; HC_VECTOR_POPELEMENT(&g_devAuthCallbackList, &deleteCallbackInfo, index); diff --git a/frameworks/src/lite/ipc_adapt.c b/frameworks/src/lite/ipc_adapt.c index 5647dbcc..8f9f815b 100644 --- a/frameworks/src/lite/ipc_adapt.c +++ b/frameworks/src/lite/ipc_adapt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -153,13 +153,15 @@ void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx) static IpcCallBackNode *GetIpcCallBackByAppId(const char *appId, int32_t type) { int32_t i; + int32_t ret; LOGI("appid: %" LOG_PUB "s", appId); for (i = 0; i < IPC_CALL_BACK_MAX_NODES; i++) { if (g_ipcCallBackList.ctx[i].appId[0] == 0) { continue; } - if (IsStrEqual(g_ipcCallBackList.ctx[i].appId, appId) && (g_ipcCallBackList.ctx[i].cbType == type)) { + ret = HcStrcmp(g_ipcCallBackList.ctx[i].appId, appId); + if ((ret == 0) && (g_ipcCallBackList.ctx[i].cbType == type)) { return &g_ipcCallBackList.ctx[i]; } } diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp index 3349f5c1..fda7d508 100644 --- a/frameworks/src/standard/ipc_adapt.cpp +++ b/frameworks/src/standard/ipc_adapt.cpp @@ -155,12 +155,14 @@ void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx) static IpcCallBackNode *GetIpcCallBackByAppId(const char *appId, int32_t type) { int32_t i; + int32_t ret; for (i = 0; i < IPC_CALL_BACK_MAX_NODES; i++) { if (g_ipcCallBackList.ctx[i].appId[0] == 0) { continue; } - if (IsStrEqual(g_ipcCallBackList.ctx[i].appId, appId) && (g_ipcCallBackList.ctx[i].cbType == type)) { + ret = HcStrcmp(g_ipcCallBackList.ctx[i].appId, appId); + if ((ret == 0) && (g_ipcCallBackList.ctx[i].cbType == type)) { return &g_ipcCallBackList.ctx[i]; } } diff --git a/services/data_manager/cred_data_manager/src/credential_data_manager.c b/services/data_manager/cred_data_manager/src/credential_data_manager.c index 68b037dc..580441af 100644 --- a/services/data_manager/cred_data_manager/src/credential_data_manager.c +++ b/services/data_manager/cred_data_manager/src/credential_data_manager.c @@ -535,7 +535,7 @@ static void LoadDevAuthCredDb(void) if (osAccountIdStr == NULL) { continue; } - if (IsStrEqual(osAccountIdStr, "hccredential.dat")) { + if (HcStrcmp(osAccountIdStr, "hccredential.dat") == 0) { LoadOsAccountCredDb(DEFAULT_OS_ACCOUNT); } else if (sscanf_s(osAccountIdStr, "hccredential%d.dat", &osAccountId) == 1) { LoadOsAccountCredDb(osAccountId); @@ -638,20 +638,20 @@ static bool SaveCredInfoToParcel(const OsAccountCredInfo *info, HcParcel *parcel static bool CompareStringParams(const QueryCredentialParams *params, const Credential *entry) { - if ((params->deviceId != NULL) && (!IsStrEqual(params->deviceId, StringGet(&entry->deviceId)))) { + if ((params->deviceId != NULL) && (HcStrcmp(params->deviceId, StringGet(&entry->deviceId)) != 0)) { return false; } - if ((params->credOwner != NULL) && (!IsStrEqual(params->credOwner, StringGet(&entry->credOwner)))) { + if ((params->credOwner != NULL) && (HcStrcmp(params->credOwner, StringGet(&entry->credOwner)) != 0)) { return false; } - if ((params->userId != NULL) && (!IsStrEqual(params->userId, StringGet(&entry->userId)))) { + if ((params->userId != NULL) && (HcStrcmp(params->userId, StringGet(&entry->userId)) != 0)) { return false; } - if ((params->credId != NULL) && (!IsStrEqual(params->credId, StringGet(&entry->credId)))) { + if ((params->credId != NULL) && (HcStrcmp(params->credId, StringGet(&entry->credId)) != 0)) { return false; } if ((params->peerUserSpaceId != NULL) && - (!IsStrEqual(params->peerUserSpaceId, StringGet(&entry->peerUserSpaceId)))) { + (HcStrcmp(params->peerUserSpaceId, StringGet(&entry->peerUserSpaceId)) != 0)) { return false; } return true; diff --git a/services/data_manager/group_data_manager/src/group_data_manager.c b/services/data_manager/group_data_manager/src/group_data_manager.c index ea8be9cb..4198d3d8 100644 --- a/services/data_manager/group_data_manager/src/group_data_manager.c +++ b/services/data_manager/group_data_manager/src/group_data_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 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 @@ -772,7 +772,7 @@ static void LoadDeviceAuthDb(void) LOGW("[DB]: Invalid osAccountIdStr!"); continue; } - if (IsStrEqual(osAccountIdStr, "hcgroup.dat")) { + if (HcStrcmp(osAccountIdStr, "hcgroup.dat") == 0) { LoadOsAccountDb(DEFAULT_OS_ACCOUNT); } else if (sscanf_s(osAccountIdStr, "hcgroup%d.dat", &osAccountId) == 1) { LoadOsAccountDb(osAccountId); @@ -912,16 +912,16 @@ static bool SaveInfoToParcel(const OsAccountTrustedInfo *info, HcParcel *parcel) static bool CompareQueryGroupParams(const QueryGroupParams *params, const TrustedGroupEntry *entry) { - if ((params->groupId != NULL) && (!IsStrEqual(params->groupId, StringGet(&entry->id)))) { + if ((params->groupId != NULL) && (HcStrcmp(params->groupId, StringGet(&entry->id)) != 0)) { return false; } - if ((params->groupName != NULL) && (!IsStrEqual(params->groupName, StringGet(&entry->name)))) { + if ((params->groupName != NULL) && (HcStrcmp(params->groupName, StringGet(&entry->name)) != 0)) { return false; } - if ((params->userId != NULL) && (!IsStrEqual(params->userId, StringGet(&entry->userId)))) { + if ((params->userId != NULL) && (HcStrcmp(params->userId, StringGet(&entry->userId)) != 0)) { return false; } - if ((params->sharedUserId != NULL) && (!IsStrEqual(params->sharedUserId, StringGet(&entry->sharedUserId)))) { + if ((params->sharedUserId != NULL) && (HcStrcmp(params->sharedUserId, StringGet(&entry->sharedUserId)) != 0)) { return false; } if ((params->groupType != ALL_GROUP) && (params->groupType != entry->type)) { @@ -932,7 +932,7 @@ static bool CompareQueryGroupParams(const QueryGroupParams *params, const Truste } if (params->ownerName != NULL) { HcString entryOwner = HC_VECTOR_GET(&entry->managers, 0); - if (!IsStrEqual(params->ownerName, StringGet(&entryOwner))) { + if (HcStrcmp(params->ownerName, StringGet(&entryOwner)) != 0) { return false; } } @@ -941,16 +941,16 @@ static bool CompareQueryGroupParams(const QueryGroupParams *params, const Truste static bool CompareQueryDeviceParams(const QueryDeviceParams *params, const TrustedDeviceEntry *entry) { - if ((params->groupId != NULL) && (!IsStrEqual(params->groupId, StringGet(&entry->groupId)))) { + if ((params->groupId != NULL) && (HcStrcmp(params->groupId, StringGet(&entry->groupId)) != 0)) { return false; } - if ((params->udid != NULL) && (!IsStrEqual(params->udid, StringGet(&entry->udid)))) { + if ((params->udid != NULL) && (HcStrcmp(params->udid, StringGet(&entry->udid)) != 0)) { return false; } - if ((params->authId != NULL) && (!IsStrEqual(params->authId, StringGet(&entry->authId)))) { + if ((params->authId != NULL) && (HcStrcmp(params->authId, StringGet(&entry->authId)) != 0)) { return false; } - if ((params->userId != NULL) && (!IsStrEqual(params->userId, StringGet(&entry->userId)))) { + if ((params->userId != NULL) && (HcStrcmp(params->userId, StringGet(&entry->userId)) != 0)) { return false; } return true; @@ -1194,7 +1194,7 @@ static bool IsSelfDeviceEntry(const TrustedDeviceEntry *deviceEntry) LOGE("The entryUdid is NULL!"); return false; } - return IsStrEqual(selfUdid, entryUdid); + return HcStrcmp(selfUdid, entryUdid) == 0; } static int32_t GenerateMessageWithOsAccount(const TrustedGroupEntry *groupEntry, int32_t osAccountId, diff --git a/services/frameworks/src/hiview_adapter/hidump_adapter.c b/services/frameworks/src/hiview_adapter/hidump_adapter.c index e1eb7658..bba153b8 100644 --- a/services/frameworks/src/hiview_adapter/hidump_adapter.c +++ b/services/frameworks/src/hiview_adapter/hidump_adapter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 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 @@ -25,7 +25,7 @@ static PerformanceDumpCallBack g_performDumpCallback = NULL; static void DumpByArgs(int fd, StringVector *strArgVec) { HcString strArg = strArgVec->get(strArgVec, 0); - if (IsStrEqual(StringGet(&strArg), PERFORM_DUMP_ARG)) { + if (HcStrcmp(StringGet(&strArg), PERFORM_DUMP_ARG) == 0) { if (g_performDumpCallback != NULL) { g_performDumpCallback(fd, strArgVec); } diff --git a/services/frameworks/src/hiview_adapter/performance_dumper.c b/services/frameworks/src/hiview_adapter/performance_dumper.c index 8b883fb1..fab6b252 100644 --- a/services/frameworks/src/hiview_adapter/performance_dumper.c +++ b/services/frameworks/src/hiview_adapter/performance_dumper.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -362,10 +362,10 @@ static void PerformanceDump(int fd, StringVector *strArgVec) return; } HcString strArg = strArgVec->get(strArgVec, 1); - if (IsStrEqual(StringGet(&strArg), ENABLE_PERFORMANCE_DUMPER)) { + if (HcStrcmp(StringGet(&strArg), ENABLE_PERFORMANCE_DUMPER) == 0) { g_isPerformDumpEnabled = true; dprintf(fd, "performance dumper is enabled!\n"); - } else if (IsStrEqual(StringGet(&strArg), DISABLE_PERFORMANCE_DUMPER)) { + } else if (HcStrcmp(StringGet(&strArg), DISABLE_PERFORMANCE_DUMPER) == 0) { ClearPerformDataVec(); g_isPerformDumpEnabled = false; dprintf(fd, "performance dumper is disabled!\n"); diff --git a/services/frameworks/src/security_label_adapter/security_label_adapter.c b/services/frameworks/src/security_label_adapter/security_label_adapter.c index 11e62aea..2ee21b2f 100644 --- a/services/frameworks/src/security_label_adapter/security_label_adapter.c +++ b/services/frameworks/src/security_label_adapter/security_label_adapter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -51,7 +51,7 @@ static bool IsSetLabelNeeded(const char *filePath, const char *labelToSet) if (GetSecurityLabel(filePath, &existLabel) != HC_SUCCESS) { return true; } - if (!IsStrEqual(existLabel, labelToSet)) { + if (HcStrcmp(existLabel, labelToSet) != 0) { LOGI("Incorrect security level, need to reset."); HcFree(existLabel); return true; diff --git a/services/identity_service/listener/src/cred_listener.c b/services/identity_service/listener/src/cred_listener.c index 1cd558fc..2d881227 100644 --- a/services/identity_service/listener/src/cred_listener.c +++ b/services/identity_service/listener/src/cred_listener.c @@ -101,7 +101,7 @@ static int32_t UpdateListenerIfExist(const char *appId, const CredChangeListener (void)LockHcMutex(g_credListenerMutex); CredListenerEntry *entry = NULL; FOR_EACH_HC_VECTOR(g_credListenerVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { if (memcpy_s(entry->listener, sizeof(CredChangeListener), listener, sizeof(CredChangeListener)) != IS_SUCCESS) { UnlockHcMutex(g_credListenerMutex); @@ -223,7 +223,7 @@ int32_t RemoveCredListener(const char *appId) uint32_t index; CredListenerEntry *entry = NULL; FOR_EACH_HC_VECTOR(g_credListenerVec, index, entry) { - if (entry != NULL && IsStrEqual(entry->appId, appId)) { + if (entry != NULL && HcStrcmp(entry->appId, appId) == 0) { HcFree(entry->appId); HcFree(entry->listener); CredListenerEntry tempEntry; diff --git a/services/identity_service/src/identity_operation.c b/services/identity_service/src/identity_operation.c index 04fe43c8..c5601c0a 100644 --- a/services/identity_service/src/identity_operation.c +++ b/services/identity_service/src/identity_operation.c @@ -581,7 +581,7 @@ static int32_t SetIssuer(Credential *credential, CJson *json) static int32_t SetDeviceId(Credential *credential, CJson *json) { const char *deviceId = GetStringFromJson(json, FIELD_DEVICE_ID); - if (deviceId == NULL || IsStrEqual(deviceId, "")) { + if (deviceId == NULL || HcStrcmp(deviceId, "") == 0) { LOGE("Failed to get deviceId from credReqParam"); return IS_ERR_JSON_GET; } @@ -595,7 +595,7 @@ static int32_t SetDeviceId(Credential *credential, CJson *json) static int32_t SetCredOwner(Credential *credential, CJson *json) { const char *credOwner = GetStringFromJson(json, FIELD_CRED_OWNER); - if (credOwner == NULL || IsStrEqual(credOwner, "")) { + if (credOwner == NULL || HcStrcmp(credOwner, "") == 0) { LOGE("Failed to get credOwner from credReqParam"); return IS_ERR_JSON_GET; } @@ -624,7 +624,7 @@ static int32_t SetProofType(Credential *credential, CJson *json) static int32_t SetUserId(Credential *credential, CJson *json) { const char *userId = GetStringFromJson(json, FIELD_USER_ID); - if (credential->credType == ACCOUNT_RELATED && (userId == NULL || IsStrEqual(userId, ""))) { + if (credential->credType == ACCOUNT_RELATED && (userId == NULL || HcStrcmp(userId, "") == 0)) { LOGE("Invalid params, when credType is account, userId is NULL"); return IS_ERR_INVALID_PARAMS; } @@ -675,7 +675,7 @@ static int32_t SetPeerUserSpaceId(Credential *credential, CJson *json, uint8_t m { const char *peerUserSpaceId = GetStringFromJson(json, FIELD_PEER_USER_SPACE_ID); if (credential->credType == ACCOUNT_UNRELATED && method == METHOD_IMPORT && - (peerUserSpaceId == NULL || IsStrEqual(peerUserSpaceId, ""))) { + (peerUserSpaceId == NULL || HcStrcmp(peerUserSpaceId, "") == 0)) { LOGE("Invalid params, when credType is not account and method is import, peer osaccount id is NULL"); return IS_ERR_INVALID_PARAMS; } @@ -710,7 +710,7 @@ static int32_t SetAppList(Credential *credential, CJson *json) static int32_t SetExtendInfo(Credential *credential, CJson *json) { const char *extendInfo = GetStringFromJson(json, FIELD_EXTEND_INFO); - if (extendInfo == NULL || IsStrEqual(extendInfo, "")) { + if (extendInfo == NULL || HcStrcmp(extendInfo, "") == 0) { LOGW("Failed to get extendInfo from credReqParam"); } if (extendInfo == NULL) { @@ -1267,7 +1267,7 @@ int32_t SetRequiredParamsFromJson(QueryCredentialParams *queryParams, CJson *bas return IS_ERR_NOT_SUPPORT; } const char *credOwner = GetStringFromJson(baseInfoJson, FIELD_CRED_OWNER); - if (credOwner == NULL || IsStrEqual(credOwner, "")) { + if (credOwner == NULL || HcStrcmp(credOwner, "") == 0) { LOGE("Failed to set query params: credOwner"); return IS_ERR_JSON_GET; } @@ -1278,13 +1278,13 @@ int32_t SetRequiredParamsFromJson(QueryCredentialParams *queryParams, CJson *bas int32_t SetUpdateToQueryParams(CJson *json, QueryCredentialParams *queryParams) { const char *userId = GetStringFromJson(json, FIELD_USER_ID); - if (userId == NULL || IsStrEqual(userId, "")) { + if (userId == NULL || HcStrcmp(userId, "") == 0) { LOGE("Failed to set query params: userId"); return IS_ERR_JSON_GET; } queryParams->userId = userId; const char *deviceId = GetStringFromJson(json, FIELD_DEVICE_ID); - if (deviceId == NULL || IsStrEqual(deviceId, "")) { + if (deviceId == NULL || HcStrcmp(deviceId, "") == 0) { LOGE("Failed to set query params: deviceId"); return IS_ERR_JSON_GET; } @@ -1303,7 +1303,7 @@ static int32_t EraseCredIdInVec(const char *credId, CredentialVec *credVec) continue; } const char *itemCredId = StringGet(&(*item)->credId); - if (itemCredId != NULL && IsStrEqual(credId, itemCredId)) { + if (itemCredId != NULL && HcStrcmp(credId, itemCredId) == 0) { credVec->eraseElement(credVec, item, index); return IS_SUCCESS; } diff --git a/services/legacy/authenticators/src/account_related/creds_manager/asy_token_manager.c b/services/legacy/authenticators/src/account_related/creds_manager/asy_token_manager.c index 4900785c..b5baac0c 100644 --- a/services/legacy/authenticators/src/account_related/creds_manager/asy_token_manager.c +++ b/services/legacy/authenticators/src/account_related/creds_manager/asy_token_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 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 @@ -617,8 +617,8 @@ static AccountToken **QueryTokenPtrIfMatch(const AccountTokenVec *vec, const cha uint32_t index; AccountToken **token; FOR_EACH_HC_VECTOR(*vec, index, token) { - if ((IsStrEqual(userId, (const char *)((*token)->pkInfo.userId.val))) && - (IsStrEqual(deviceId, (const char *)((*token)->pkInfo.deviceId.val)))) { + if ((HcStrcmp(userId, (const char *)((*token)->pkInfo.userId.val)) == 0) && + (HcStrcmp(deviceId, (const char *)((*token)->pkInfo.deviceId.val)) == 0)) { return token; } } @@ -688,7 +688,7 @@ static int32_t DoExportPkAndCompare(int32_t osAccountId, const char *userId, con return ret; } UnlockHcMutex(g_accountDbMutex); - if (memcmp(devicePk, publicKeyVal, PK_SIZE) == 0) { + if (HcStrcmp((const char *)devicePk, (const char *)publicKeyVal) == 0) { HcFree(publicKeyVal); return HC_SUCCESS; } @@ -756,7 +756,7 @@ static int32_t CheckUserId(const char *userId, const CJson *in) LOGE("Failed to get userIdFromPk"); return HC_ERR_JSON_GET; } - if (IsStrEqual(userId, userIdFromPk)) { + if (HcStrcmp(userId, userIdFromPk) == 0) { return HC_SUCCESS; } return HC_ERROR; @@ -1144,8 +1144,8 @@ static int32_t DeleteTokenInner(int32_t osAccountId, const char *userId, const c while (index < HC_VECTOR_SIZE(&info->tokens)) { token = info->tokens.getp(&info->tokens, index); if ((token == NULL) || (*token == NULL) || - (!IsStrEqual(userId, (const char *)((*token)->pkInfo.userId.val))) || - (!IsStrEqual(deviceId, (const char *)((*token)->pkInfo.deviceId.val)))) { + (HcStrcmp(userId, (const char *)((*token)->pkInfo.userId.val)) != 0) || + (HcStrcmp(deviceId, (const char *)((*token)->pkInfo.deviceId.val)) != 0)) { index++; continue; } @@ -1281,7 +1281,7 @@ static void LoadTokenDb(void) if (name == NULL) { continue; } - if (IsStrEqual(name, "account_data_asy.dat")) { + if (HcStrcmp(name, "account_data_asy.dat") == 0) { LoadOsAccountTokenDb(DEFAULT_OS_ACCOUNT); } else if (sscanf_s(name, "account_data_asy%d.dat", &osAccountId) == 1) { LoadOsAccountTokenDb(osAccountId); diff --git a/services/legacy/authenticators/src/account_related/creds_manager/sym_token_manager.c b/services/legacy/authenticators/src/account_related/creds_manager/sym_token_manager.c index 05ecbda8..604d492c 100644 --- a/services/legacy/authenticators/src/account_related/creds_manager/sym_token_manager.c +++ b/services/legacy/authenticators/src/account_related/creds_manager/sym_token_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 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 @@ -57,7 +57,7 @@ static bool IsTokenMatch(const SymToken *token, const char *userId, const char * LOGE("deviceId is null!"); return false; } - return (IsStrEqual(userId, token->userId)) && (IsStrEqual(deviceId, token->deviceId)); + return (HcStrcmp(userId, token->userId) == 0) && (HcStrcmp(deviceId, token->deviceId) == 0); } static bool GetTokensFilePathCe(int32_t osAccountId, char *tokenPath, uint32_t pathBufferLen) @@ -732,7 +732,7 @@ static void LoadTokenDb(void) if (name == NULL) { continue; } - if (IsStrEqual(name, "account_data_sym.dat")) { + if (HcStrcmp(name, "account_data_sym.dat") == 0) { LoadOsSymTokensDb(DEFAULT_OS_ACCOUNT); } else if (sscanf_s(name, "account_data_sym%d.dat", &osAccountId) == 1) { LoadOsSymTokensDb(osAccountId); diff --git a/services/legacy/authenticators/src/account_unrelated/common/das_task_common.c b/services/legacy/authenticators/src/account_unrelated/common/das_task_common.c index 9110e9f6..0d49c723 100644 --- a/services/legacy/authenticators/src/account_unrelated/common/das_task_common.c +++ b/services/legacy/authenticators/src/account_unrelated/common/das_task_common.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -218,7 +218,7 @@ static bool IsPeerDevice(const Uint8Buff *authId) HcFree(authIdStr); return false; } - bool isPeerDevice = !IsStrEqual(selfUdid, authIdStr); + bool isPeerDevice = HcStrcmp(selfUdid, authIdStr) != 0; HcFree(authIdStr); return isPeerDevice; } diff --git a/services/legacy/authenticators/src/account_unrelated/das_task_main.c b/services/legacy/authenticators/src/account_unrelated/das_task_main.c index e6607940..67121151 100644 --- a/services/legacy/authenticators/src/account_unrelated/das_task_main.c +++ b/services/legacy/authenticators/src/account_unrelated/das_task_main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -98,7 +98,7 @@ static int CombineJson(CJson *desObj, const CJson *srcObj) return HC_ERR_NULL_PTR; } CJson *payload = GetObjFromJson(desObj, FIELD_PAYLOAD); - if (IsStrEqual(key, FIELD_PAYLOAD) && payload != NULL) { + if (HcStrcmp(key, FIELD_PAYLOAD) == 0 && payload != NULL) { res = CombineJson(payload, item); if (res != HC_SUCCESS) { LOGE("Combine payload failed, res: %" LOG_PUB "x.", res); diff --git a/services/legacy/group_manager/src/broadcast_manager/broadcast_manager.c b/services/legacy/group_manager/src/broadcast_manager/broadcast_manager.c index 6c091fc3..bbcb0844 100644 --- a/services/legacy/group_manager/src/broadcast_manager/broadcast_manager.c +++ b/services/legacy/group_manager/src/broadcast_manager/broadcast_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -162,7 +162,7 @@ static int32_t UpdateListenerIfExist(const char *appId, const DataChangeListener ListenerEntry *entry = NULL; (void)LockHcMutex(g_broadcastMutex); FOR_EACH_HC_VECTOR(g_listenerEntryVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { if (memcpy_s(entry->listener, sizeof(DataChangeListener), listener, sizeof(DataChangeListener)) != HC_SUCCESS) { UnlockHcMutex(g_broadcastMutex); @@ -297,7 +297,7 @@ int32_t RemoveListener(const char *appId) uint32_t index; ListenerEntry *entry = NULL; FOR_EACH_HC_VECTOR(g_listenerEntryVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { HcFree(entry->appId); HcFree(entry->listener); ListenerEntry tempEntry; diff --git a/services/legacy/group_manager/src/callback_manager/callback_manager.c b/services/legacy/group_manager/src/callback_manager/callback_manager.c index cf9783cc..3f00d8fc 100644 --- a/services/legacy/group_manager/src/callback_manager/callback_manager.c +++ b/services/legacy/group_manager/src/callback_manager/callback_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -39,7 +39,7 @@ static int32_t UpdateCallbackIfExist(const char *appId, const DeviceAuthCallback CallbackEntry *entry = NULL; (void)LockHcMutex(g_callbackMutex); FOR_EACH_HC_VECTOR(g_callbackVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { if (memcpy_s(entry->callback, sizeof(DeviceAuthCallback), callback, sizeof(DeviceAuthCallback)) != EOK) { UnlockHcMutex(g_callbackMutex); @@ -164,7 +164,7 @@ const DeviceAuthCallback *GetGMCallbackByAppId(const char *appId) CallbackEntry *entry = NULL; (void)LockHcMutex(g_callbackMutex); FOR_EACH_HC_VECTOR(g_callbackVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { UnlockHcMutex(g_callbackMutex); return entry->callback; } @@ -196,7 +196,7 @@ int32_t UnRegGroupManagerCallback(const char *appId) CallbackEntry *entry = NULL; (void)LockHcMutex(g_callbackMutex); FOR_EACH_HC_VECTOR(g_callbackVec, index, entry) { - if (IsStrEqual(entry->appId, appId)) { + if (HcStrcmp(entry->appId, appId) == 0) { HcFree(entry->appId); HcFree(entry->callback); CallbackEntry tempEntry; diff --git a/services/legacy/group_manager/src/group_operation/across_account_group/across_account_group.c b/services/legacy/group_manager/src/group_operation/across_account_group/across_account_group.c index 24cd7f57..bb9a5f0c 100644 --- a/services/legacy/group_manager/src/group_operation/across_account_group/across_account_group.c +++ b/services/legacy/group_manager/src/group_operation/across_account_group/across_account_group.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 Huawei Device Co., Ltd. + * 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 @@ -200,7 +200,7 @@ static int32_t AssertIdenticalGroupExist(int32_t osAccountId, const CJson *jsonP uint32_t index; TrustedGroupEntry **entry = NULL; FOR_EACH_HC_VECTOR(groupEntryVec, index, entry) { - if (IsStrEqual(userId, StringGet(&((*entry)->userId)))) { + if (HcStrcmp(userId, StringGet(&((*entry)->userId))) == 0) { isExist = true; break; } @@ -226,7 +226,7 @@ static int32_t AssertSharedUserIdValid(const CJson *jsonParams) LOGE("Failed to get sharedUserId from jsonParams!"); return HC_ERR_JSON_GET; } - if (IsStrEqual(sharedUserId, userId)) { + if (HcStrcmp(sharedUserId, userId) == 0) { LOGE("The input peerUserId is the same as the local userId!"); return HC_ERR_INVALID_PARAMS; } @@ -500,7 +500,7 @@ static int32_t CheckUserIdValid(int32_t osAccountId, const CJson *jsonParams, co return HC_ERR_DB; } FOR_EACH_HC_VECTOR(groupEntryVec, index, entry) { - if (IsStrEqual(userId, StringGet(&(*entry)->sharedUserId))) { + if (HcStrcmp(userId, StringGet(&(*entry)->sharedUserId)) == 0) { ClearGroupEntryVec(&groupEntryVec); return HC_SUCCESS; } diff --git a/services/legacy/group_manager/src/group_operation/group_operation.c b/services/legacy/group_manager/src/group_operation/group_operation.c index b83a19e4..76b09089 100644 --- a/services/legacy/group_manager/src/group_operation/group_operation.c +++ b/services/legacy/group_manager/src/group_operation/group_operation.c @@ -1759,7 +1759,7 @@ static bool IsCallerExtPart(int32_t opCode, CJson *params) LOGE("Failed to get appId!"); return false; } - if (!IsStrEqual(appId, EXT_PART_APP_ID)) { + if (HcStrcmp(appId, EXT_PART_APP_ID) != 0) { return false; } return true; diff --git a/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c b/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c index 8cda62fd..9bf9ec11 100644 --- a/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c +++ b/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c @@ -64,7 +64,7 @@ static bool IsGroupManager(const char *appId, const TrustedGroupEntry *entry) uint32_t index; HcString *manager = NULL; FOR_EACH_HC_VECTOR(entry->managers, index, manager) { - if ((IsStrEqual(StringGet(manager), appId)) || + if ((HcStrcmp(StringGet(manager), appId) == 0) || CheckUpgradeIdentity(entry->upgradeFlag, appId, StringGet(manager)) == HC_SUCCESS) { return true; } @@ -77,7 +77,7 @@ static bool IsGroupFriend(const char *appId, const TrustedGroupEntry *entry) uint32_t index; HcString *trustedFriend = NULL; FOR_EACH_HC_VECTOR(entry->friends, index, trustedFriend) { - if ((IsStrEqual(StringGet(trustedFriend), appId)) || + if ((HcStrcmp(StringGet(trustedFriend), appId) == 0) || CheckUpgradeIdentity(entry->upgradeFlag, appId, StringGet(trustedFriend)) == HC_SUCCESS) { return true; } @@ -195,7 +195,7 @@ bool IsLocalDevice(const char *udid) LOGE("Failed to get local udid! res: %" LOG_PUB "d", res); return true; } - return IsStrEqual(localUdid, udid); + return (HcStrcmp(localUdid, udid) == 0); } bool IsGroupOwner(int32_t osAccountId, const char *groupId, const char *appId) @@ -216,7 +216,7 @@ bool IsGroupOwner(int32_t osAccountId, const char *groupId, const char *appId) DestroyGroupEntry(entry); return false; } - if ((IsStrEqual(groupOwner, appId)) || + if ((HcStrcmp(groupOwner, appId) == 0) || CheckUpgradeIdentity(entry->upgradeFlag, appId, groupOwner) == HC_SUCCESS) { DestroyGroupEntry(entry); return true; @@ -743,7 +743,7 @@ int32_t AssertPeerDeviceNotSelf(const char *peerUdid) LOGE("Failed to get local udid! res: %" LOG_PUB "d", res); return HC_ERR_DB; } - if (IsStrEqual(peerUdid, udid)) { + if (HcStrcmp(peerUdid, udid) == 0) { LOGE("You are not allowed to delete yourself!"); return HC_ERR_INVALID_PARAMS; } diff --git a/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c b/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c index c27d348f..f756d4c4 100644 --- a/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c +++ b/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 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 @@ -502,7 +502,7 @@ static int32_t CheckUserIdValid(int32_t osAccountId, const CJson *jsonParams, co return HC_ERR_DB; } FOR_EACH_HC_VECTOR(groupEntryVec, index, entry) { - if (IsStrEqual(userId, StringGet(&(*entry)->userId))) { + if (HcStrcmp(userId, StringGet(&(*entry)->userId)) == 0) { ClearGroupEntryVec(&groupEntryVec); return HC_SUCCESS; } diff --git a/services/legacy/identity_manager/src/credential_operator.c b/services/legacy/identity_manager/src/credential_operator.c index 1ca683ab..9ee61e44 100644 --- a/services/legacy/identity_manager/src/credential_operator.c +++ b/services/legacy/identity_manager/src/credential_operator.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -83,7 +83,7 @@ static bool IsPeerDevice(const Uint8Buff *authId) HcFree(authIdStr); return false; } - bool isPeerDevice = !IsStrEqual(selfUdid, authIdStr); + bool isPeerDevice = HcStrcmp(selfUdid, authIdStr) != 0; HcFree(authIdStr); return isPeerDevice; } diff --git a/services/privacy_enhancement/src/pseudonym_manager.c b/services/privacy_enhancement/src/pseudonym_manager.c index 04263d67..fdad8779 100644 --- a/services/privacy_enhancement/src/pseudonym_manager.c +++ b/services/privacy_enhancement/src/pseudonym_manager.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -85,7 +85,7 @@ static PseudonymInfo **QueryPseudonymInfoPtrIfMatch(const PseudonymInfoVec *vec, uint32_t index; PseudonymInfo **pseudonymInfo; FOR_EACH_HC_VECTOR(*vec, index, pseudonymInfo) { - if (IsStrEqual(realInfo, (*pseudonymInfo)->realInfo)) { + if (HcStrcmp(realInfo, (*pseudonymInfo)->realInfo) == 0) { return pseudonymInfo; } } @@ -386,9 +386,9 @@ static int32_t SavePseudonymInfoToFile(int32_t osAccountId, const PseudonymInfoV static const char *GetParamByFieldName(const char *fieldName, PseudonymInfo *pseudonymInfoEntry) { - if (IsStrEqual(fieldName, FIELD_DEVICE_ID)) { + if (HcStrcmp(fieldName, FIELD_DEVICE_ID) == 0) { return pseudonymInfoEntry->deviceId; - } else if (IsStrEqual(fieldName, FIELD_INDEX_KEY)) { + } else if (HcStrcmp(fieldName, FIELD_INDEX_KEY) == 0) { return pseudonymInfoEntry->indexKey; } else { LOGE("Not support this field!"); @@ -524,7 +524,7 @@ static int32_t DeletePseudonymInner(int32_t osAccountId, const char *dataTodelet while (index < HC_VECTOR_SIZE(&info->pseudonymInfoVec)) { pseudonymInfoEntry = info->pseudonymInfoVec.getp(&info->pseudonymInfoVec, index); if ((pseudonymInfoEntry == NULL) || (*pseudonymInfoEntry == NULL) || - (!IsStrEqual(dataTodelete, GetParamByFieldName(fieldName, *pseudonymInfoEntry)))) { + (HcStrcmp(dataTodelete, GetParamByFieldName(fieldName, *pseudonymInfoEntry))) != 0) { index++; continue; } @@ -587,7 +587,7 @@ static void LoadPseudonymData(void) if (name == NULL) { continue; } - if (IsStrEqual(name, "pseudonym_data.dat")) { + if (HcStrcmp(name, "pseudonym_data.dat") == 0) { LoadOsAccountPseudonymDb(DEFAULT_OS_ACCOUNT); } else if (sscanf_s(name, "pseudonym_data%d.dat", &osAccountId) == 1) { LoadOsAccountPseudonymDb(osAccountId); @@ -615,7 +615,7 @@ static int32_t GetRealInfo(int32_t osAccountId, const char *pseudonymId, char ** PseudonymInfo **pseudonymInfoEntry = NULL; FOR_EACH_HC_VECTOR(info->pseudonymInfoVec, index, pseudonymInfoEntry) { if ((pseudonymInfoEntry != NULL) && (*pseudonymInfoEntry != NULL) && - (IsStrEqual((*pseudonymInfoEntry)->pseudonymId, pseudonymId))) { + (HcStrcmp((*pseudonymInfoEntry)->pseudonymId, pseudonymId) == 0)) { if (DeepCopyString((*pseudonymInfoEntry)->realInfo, realInfo) != HC_SUCCESS) { LOGE("Failed to deep copy pseudonymInfoentry realInfo!"); UnlockHcMutex(g_mutex); @@ -647,7 +647,7 @@ static int32_t GetPseudonymId(int32_t osAccountId, const char *indexKey, char ** PseudonymInfo **pseudonymInfoEntry = NULL; FOR_EACH_HC_VECTOR(info->pseudonymInfoVec, index, pseudonymInfoEntry) { if ((pseudonymInfoEntry != NULL) && (*pseudonymInfoEntry != NULL) && - (IsStrEqual((*pseudonymInfoEntry)->indexKey, indexKey))) { + (HcStrcmp((*pseudonymInfoEntry)->indexKey, indexKey) == 0)) { if (DeepCopyString((*pseudonymInfoEntry)->pseudonymId, pseudonymId) != HC_SUCCESS) { LOGE("Failed to deep copy pseudonymId!"); UnlockHcMutex(g_mutex); @@ -802,7 +802,7 @@ static bool IsNeedRefreshPseudonymId(int32_t osAccountId, const char *indexKey) PseudonymInfo **pseudonymInfoEntry = NULL; FOR_EACH_HC_VECTOR(info->pseudonymInfoVec, index, pseudonymInfoEntry) { if ((pseudonymInfoEntry != NULL) && (*pseudonymInfoEntry != NULL) && - (IsStrEqual((*pseudonymInfoEntry)->indexKey, indexKey))) { + (HcStrcmp((*pseudonymInfoEntry)->indexKey, indexKey) == 0)) { if (IsNeedRefresh(*pseudonymInfoEntry)) { UnlockHcMutex(g_mutex); return true; diff --git a/services/session_manager/src/dev_session_mgr.c b/services/session_manager/src/dev_session_mgr.c index a3b75a33..8fa358cd 100644 --- a/services/session_manager/src/dev_session_mgr.c +++ b/services/session_manager/src/dev_session_mgr.c @@ -248,7 +248,7 @@ void CancelDevSession(int64_t sessionId, const char *appId) SessionInfo *ptr; FOR_EACH_HC_VECTOR(g_sessionInfoList, index, ptr) { DevSession *session = ptr->session; - if (session->id == sessionId && IsStrEqual(session->appId, appId)) { + if (session->id == sessionId && HcStrcmp(session->appId, appId) == 0) { session->destroy(session); HC_VECTOR_POPELEMENT(&g_sessionInfoList, ptr, index); LOGI("cancel session success. [CurNum]: %" LOG_PUB "u, [Id]: %" LOG_PUB PRId64, diff --git a/services/session_manager/src/session/v1/compatible_bind_sub_session/compatible_bind_sub_session_common.c b/services/session_manager/src/session/v1/compatible_bind_sub_session/compatible_bind_sub_session_common.c index 99330405..65af6759 100644 --- a/services/session_manager/src/session/v1/compatible_bind_sub_session/compatible_bind_sub_session_common.c +++ b/services/session_manager/src/session/v1/compatible_bind_sub_session/compatible_bind_sub_session_common.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -164,7 +164,7 @@ static int32_t CheckAuthIdAndUserTypeValid(int32_t osAccountId, int userType, co return result; } const char *oriAuthId = StringGet(&deviceInfo->authId); - if ((deviceInfo->devType != userType) || ((oriAuthId != NULL) && (!IsStrEqual(oriAuthId, authId)))) { + if ((deviceInfo->devType != userType) || ((oriAuthId != NULL) && (HcStrcmp(oriAuthId, authId) != 0))) { LOGE("Once a group is created, the service cannot change the local authId and userType used in the group!"); DestroyDeviceEntry(deviceInfo); return HC_ERR_INVALID_PARAMS; diff --git a/services/session_manager/src/session/v2/dev_session_util.c b/services/session_manager/src/session/v2/dev_session_util.c index 855e20d6..25fc3e90 100644 --- a/services/session_manager/src/session/v2/dev_session_util.c +++ b/services/session_manager/src/session/v2/dev_session_util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -795,7 +795,7 @@ bool IsPeerSameUserId(int32_t osAccountId, const char *peerUserId) return false; } TrustedGroupEntry *groupEntry = groupVec.get(&groupVec, 0); - bool isSame = (IsStrEqual(StringGet(&(groupEntry->userId)), peerUserId)); + bool isSame = (HcStrcmp(StringGet(&(groupEntry->userId)), peerUserId) == 0); ClearGroupEntryVec(&groupVec); return isSame; } \ No newline at end of file diff --git a/services/session_manager/src/session/v2/expand_sub_session/expand_process_lib/save_trusted_info.c b/services/session_manager/src/session/v2/expand_sub_session/expand_process_lib/save_trusted_info.c index a5921045..02b3c252 100644 --- a/services/session_manager/src/session/v2/expand_sub_session/expand_process_lib/save_trusted_info.c +++ b/services/session_manager/src/session/v2/expand_sub_session/expand_process_lib/save_trusted_info.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 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 @@ -369,7 +369,7 @@ static bool IsAcrossAccount(const CmdParams *params) LOGW("userIdSelf or userIdPeer is null"); return false; } - if (!params->isBind && !IsStrEqual(params->userIdSelf, params->userIdPeer)) { + if (!params->isBind && HcStrcmp(params->userIdSelf, params->userIdPeer) != 0) { LOGI("No peer-to-peer binding and SelfUserId is not equal to PeerUserId, don't need to add peerDevice!"); return true; } diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index 49b6a4b3..56562fcd 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2025 Huawei Device Co., Ltd. +# Copyright (C) 2021-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 @@ -633,7 +633,6 @@ ohos_unittest("deviceauth_unit_test") { "unit_test/source/account_related_creds_manager_dir_test.cpp", "unit_test/source/common_lib_test.cpp", "unit_test/source/key_management_test.cpp", - "unit_test/source/group_data_manager_test.cpp", ] defines = [ diff --git a/test/unittest/deviceauth/source/deviceauth_identity_service_test.cpp b/test/unittest/deviceauth/source/deviceauth_identity_service_test.cpp index 0950832a..b4114ff5 100644 --- a/test/unittest/deviceauth/source/deviceauth_identity_service_test.cpp +++ b/test/unittest/deviceauth/source/deviceauth_identity_service_test.cpp @@ -841,7 +841,7 @@ HWTEST_F(CredMgrQueryCredInfoByCredIdTest, CredMgrQueryCredInfoByCredIdTest001, CJson *credInfoJson = CreateJsonFromString(returnCredInfo); HcFree(returnCredInfo); const char *deviceId = GetStringFromJson(credInfoJson, FIELD_DEVICE_ID); - EXPECT_EQ(IsStrEqual(deviceId, TEST_DEVICE_ID), true); + EXPECT_EQ(HcStrcmp(deviceId, TEST_DEVICE_ID), TEST_RESULT_SUCCESS); FreeJson(credInfoJson); } diff --git a/test/unittest/deviceauth/source/identity_service_ipc_test.cpp b/test/unittest/deviceauth/source/identity_service_ipc_test.cpp index d1903d96..20c0c22d 100644 --- a/test/unittest/deviceauth/source/identity_service_ipc_test.cpp +++ b/test/unittest/deviceauth/source/identity_service_ipc_test.cpp @@ -20,12 +20,12 @@ #include "device_auth.h" #include "device_auth_defines.h" #include "json_utils.h" -#include "string_util.h" #include "hc_types.h" #include "securec.h" #include "nativetoken_kit.h" #include "token_setproc.h" #include "accesstoken_kit.h" +#include "string_util.h" using namespace std; using namespace testing::ext; @@ -403,7 +403,7 @@ HWTEST_F(CredMgrQueryCredInfoByCredIdTest, CredMgrQueryCredInfoByCredIdTest001, HcFree(returnCredInfo); const char *deviceId = GetStringFromJson(credInfoJson, FIELD_DEVICE_ID); if (deviceId != nullptr) { - EXPECT_EQ(IsStrEqual(deviceId, TEST_DEVICE_ID), true); + EXPECT_EQ(HcStrcmp(deviceId, TEST_DEVICE_ID), TEST_RESULT_SUCCESS); } FreeJson(credInfoJson); } diff --git a/test/unittest/deviceauth/source/json_utils_mock.c b/test/unittest/deviceauth/source/json_utils_mock.c index 1d0b058c..ac428dca 100644 --- a/test/unittest/deviceauth/source/json_utils_mock.c +++ b/test/unittest/deviceauth/source/json_utils_mock.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2025 Huawei Device Co., Ltd. + * Copyright (C) 2021 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 @@ -129,7 +129,7 @@ void DeleteAllItemExceptOne(CJson *jsonObj, const char *key) CJson *nextItem = NULL; while (curItem != NULL) { nextItem = curItem->next; - if (!IsStrEqual(key, curItem->string)) { + if (HcStrcmp(key, curItem->string) != 0) { cJSON_Delete(cJSON_DetachItemViaPointer(jsonObj, curItem)); } curItem = nextItem; diff --git a/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp b/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp index fcd837ac..dce6aeff 100644 --- a/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp +++ b/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2025 Huawei Device Co., Ltd. + * 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 @@ -821,17 +821,4 @@ HWTEST_F(CommonLibTest, ParseTlvNodeTest001, TestSize.Level0) EXPECT_EQ(ret, TLV_FAIL); DeleteParcel(&parcelWithData); } - -HWTEST_F(CommonLibTest, IsStrEqualTest001, TestSize.Level0) -{ - EXPECT_EQ(IsStrEqual(nullptr, nullptr), false); - EXPECT_EQ(IsStrEqual("123", nullptr), false); - EXPECT_EQ(IsStrEqual(nullptr, "123"), false); - EXPECT_EQ(IsStrEqual("123", "123"), true); - EXPECT_EQ(IsStrEqual("123", "1234"), false); - EXPECT_EQ(IsStrEqual("1234", "123"), false); - EXPECT_EQ(IsStrEqual("", ""), true); - EXPECT_EQ(IsStrEqual("", "123"), false); - EXPECT_EQ(IsStrEqual("123", ""), false); -} } \ No newline at end of file diff --git a/test/unittest/deviceauth/unit_test/source/group_data_manager_test.cpp b/test/unittest/deviceauth/unit_test/source/group_data_manager_test.cpp deleted file mode 100644 index 022c2bcf..00000000 --- a/test/unittest/deviceauth/unit_test/source/group_data_manager_test.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2025 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 "gtest/gtest.h" -#include "group_data_manager.h" -#include "device_auth_defines.h" -#include "device_auth.h" -#include "common_defs.h" -using namespace testing::ext; -namespace { -static const int32_t TEST_OS_ACCOUNT_ID = 0; -static const char *TEST_OWNER = "test_owner"; -static const char *TEST_GROUP_ID = "test_group_id"; -static const char *TEST_GROUP_NAME = "test_group_name"; -static const char *TEST_USER_ID = "0"; -static const char *TEST_SHARED_USER_ID = "test_sharedUser_id"; -class GroupDataManagerTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void GroupDataManagerTest::SetUpTestCase(void) {} -void GroupDataManagerTest::TearDownTestCase(void) {} - -void GroupDataManagerTest::SetUp(void) -{ - InitDatabase(); -} - -void GroupDataManagerTest::TearDown(void) -{ - DestroyDatabase(); -} - -static TrustedGroupEntry *generateTestGroupEntry(void) -{ - TrustedGroupEntry *entry = CreateGroupEntry(); - if (entry == NULL) { - return NULL; - } - entry->type = ALL_GROUP; - entry->visibility = ALL_GROUP_VISIBILITY; - HcString ownerName = CreateString(); - StringSetPointer(&(ownerName), TEST_OWNER); - entry->managers.pushBack(&entry->managers, &ownerName); - StringSetPointer(&(entry->name), TEST_GROUP_NAME); - StringSetPointer(&(entry->id), TEST_GROUP_ID); - StringSetPointer(&(entry->userId), TEST_USER_ID); - StringSetPointer(&(entry->sharedUserId), TEST_SHARED_USER_ID); - return entry; -} - -HWTEST_F(GroupDataManagerTest, DelGroupTEST001, TestSize.Level0) -{ - QueryGroupParams param = InitQueryGroupParams(); - TrustedGroupEntry *entry = generateTestGroupEntry(); - GroupEntryVec vec = CreateGroupEntryVec(); - ASSERT_NE(entry, nullptr); - EXPECT_EQ(AddGroup(TEST_OS_ACCOUNT_ID, entry), HC_SUCCESS); - EXPECT_EQ(DelGroup(TEST_OS_ACCOUNT_ID, nullptr), HC_ERR_NULL_PTR); - EXPECT_EQ(QueryGroups(TEST_OS_ACCOUNT_ID, ¶m, &vec), HC_SUCCESS); - EXPECT_EQ(HC_VECTOR_SIZE(&vec), 1); - ClearGroupEntryVec(&vec); - DestroyGroupEntry(entry); -} -} \ No newline at end of file -- Gitee