diff --git a/common_lib/impl/src/json_utils.c b/common_lib/impl/src/json_utils.c index f6887bbc41985e6b65f0759d5ec47ef738b85131..a62c483326f75037c36d9978a8b14c0d036044bb 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 a0ee6f8aa69891c6340b5bb31599afc947191073..421ee94b7fa8bee1c8c32bd091553a123beca20d 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 d199c9382cc76d7a2b99b9798caae9e9d56356c4..41d03dff3b71b23d637bdf735710e20c7a7804d8 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 5eb4d8ea9d6b0dcaf7fd8f6210bca61a64c015fa..51fc83b58cf2449d2486aa5f89bbb0a92a053f67 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 b6141bbf1c1d8b34fd1bd2c10e86266da2f2af93..7df252a9308018c173daf866b677fd5d84bb7497 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 81686260d7fb3dc7b9455d79eb7cacd0bf637bd2..34676e27f910db8f5befad9d8067925bf096f732 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 5647dbcce7934e4ee88db59125979b271c6dd07f..8f9f815b5f849acb9d86f27586d998d03af880a9 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 3349f5c119d473547afa923ca79230e0d12cbfc0..fda7d5082b98feeb5139a9d42fd25e642bec778f 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 68b037dc8541436fbb0964a5718ba2d2b5d7bfd1..580441af8b2745754362dc4733a5330a82bd9816 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 ea8be9cbcf01906b2ca5dfbb090990755da80ce2..4198d3d8832a585697cdb499a48a7783dbc03255 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 e1eb7658beed8635367941c94aec44c6affc7545..bba153b88395c1a7fd79294899487abad81b6f5f 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 8b883fb1d9749a90b90437d44c8749f4f71f5f74..fab6b25280d48641e130c652fb1bb0c7d94b162b 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 11e62aeadb85b14f1510f6e15913f2b90237513c..2ee21b2fe90f8424e6222dc130053c230e72ffe6 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 1cd558fc5c10b21c52b4cff6575b60bbd52a3b72..2d881227954485ca7b9ef7dc7167a0eacc1ef95a 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 04fe43c8d24e3125cd02689a5e52fc9f3f5581ee..c5601c0a69b414d3082978269569927c70a1fffc 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 4900785c613d785e9f51bd73ed2ead3911a1e8e1..b5baac0cb4098b8fd149789928498091dadcc14c 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 05ecbda8cbd1341fc9ab564a97ec414d962b2320..604d492cf72de17152105bb156cb00555995efc2 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 9110e9f640dc3a71cab73b1224e46e0c5921c6f1..0d49c723436a27b47d5a1a92f33b12c997fdd745 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 e6607940036d38873111c1b2c90806f646672d20..6712115132a0766c26ecc0d51af7f7690bd8cb82 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 6c091fc3ee92c552133e5d0806e77eaa766b30a7..bbcb084413a1d1d0df3838ec447a43813d6fec9e 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 cf9783ccf3258e500e70f5ac5cad70b09a2083ca..3f00d8fc7b4f9d5504a07de2a072e48c4b3e50d9 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 24cd7f5723f23aab2c587b16efe3924dc0a93d04..bb9a5f0c95efe027980ba57947bc1897ca1f31b7 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 b83a19e4f1579514368facf261b7b41d721f1d37..76b09089fc0f4001b72bce40759736a3568bb6be 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 8cda62fd087d310d7633e9c890815fd92cd68639..9bf9ec1109ce8b93b683f1de9888203cb63c95d5 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 c27d348f7e9f3372e820193a7f6d523a940d0a04..f756d4c4015041a23697243b4608970aa12b3e80 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 1ca683abf51d45f27d189f245d5289d647857a9a..9ee61e4499cb857ee600c5fef19efd2ad8cb7076 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 04263d67b7ebd73bcdbd3b21eda32732900034c5..fdad8779ce9ce0d77fef3b1b1ccb828c0c900f23 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 a3b75a33c9496ef92fc3480e3de7132f7692db1b..8fa358cdcb1a6bca9f84b8c659a08406e9e281fb 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 99330405f387fea629f79e82d199114e2315c31a..65af6759b33f100c34b995efb1b8f6206990c2f5 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 855e20d6374f410ec5cc721bebd0eef8f81e388f..25fc3e906e69ccd5ff51d626477c8b2b89a54564 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 a5921045af9ec6655e42b44f151e2d2b2754fad3..02b3c252ad1464a4c5904bc280ea67ea9be6c966 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 49b6a4b38e640d79cb51923af1469ff16ee04020..56562fcd54d4664f86d961200bee862f36b0ae72 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 0950832a894eaad7e8d7cc608ee98f4c38cb3a4b..b4114ff599a1662ac58ffd4a3af09609ba223bc1 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 d1903d9645756175ab19372bc025d2fbfd3f1e54..20c0c22d7a93a1aa521fc6856132558a3d40ad07 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 1d0b058cd556d919ea523632b97814972701e50e..ac428dca33dcde1700d822a96158d048ad02f124 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 fcd837acba41a3e82be1a896ee5b7145c1459978..dce6aeff8d39f39f56713370ed95cad4c00f1a56 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 022c2bcf2d9dd091c28a492c51a9c9d265b02a19..0000000000000000000000000000000000000000 --- 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