From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.4415.1611288236327171020 for ; Thu, 21 Jan 2021 20:03:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=LTzQkSr0; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0656d08194=abner.chang@hpe.com) Received: from pps.filterd (m0134421.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10M3xBS0006234; Fri, 22 Jan 2021 04:03:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id; s=pps0720; bh=JRUFo1EoshRLO1mdP83wPi/0n6RDCYYzs8YK+vQTPjk=; b=LTzQkSr0yPBdAdMlxUrXfhwV4Gat5oEjzlYuprzuds+Ew0BeoQtrRr9/fyVhojcN7z6c qjSRqhzhkbPAqobBBiGaO2xTp1AZGL33+iequEBLBA80P+VJN56HwJxr0WtCUc8dOkDC ba2mOTkJy6R3Z92XJJsaFP4edfhXkhg0oSg+eFvFjjRVu1jM4TMHH1EMRNNtbyMMHYuh n5Ea8dE1++mnslqRQgET7Nfj2a+8ujONFIRDUi3Ufapx2LypGh3bWhgausdNmiaqjuYp FGLtkYkTWPFFwelXgON4eWSuqWjjdITKwEf+CMC6F7m77hLe2mU4CUa5ORrm/BreZy9q rA== Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0b-002e3701.pphosted.com with ESMTP id 367jnx1nm2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Jan 2021 04:03:55 +0000 Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g9t5009.houston.hpe.com (Postfix) with ESMTP id 766DA5B; Fri, 22 Jan 2021 04:03:54 +0000 (UTC) Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 4334945; Fri, 22 Jan 2021 04:03:53 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Dandan Bi , Eric Dong , Nickle Wang Subject: [PATCH] MdeModulePkg/Library: Add HiiGetStringEx to UefiHiiLib for EDK2 Redfish Date: Fri, 22 Jan 2021 11:15:25 +0800 Message-Id: <20210122031525.30972-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.17.1 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-22_02:2021-01-21,2021-01-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101220018 Add HiiGetStringEx and leveraged by HiiGetString function to support getting string with the best language in optionally. This avoids the string in x-uefi language is misled to the language defined by "PlatformLang" or the "Supported Languages". This change is introduced to support x-uefi keyword language for configuring BIOS setting. Signed-off-by: Jiaxin Wu Signed-off-by: Siyuan Fu Signed-off-by: Fan Wang Signed-off-by: Abner Chang Cc: Dandan Bi Cc: Eric Dong Cc: Nickle Wang --- MdeModulePkg/Include/Library/HiiLib.h | 41 +++++++++++- MdeModulePkg/Library/UefiHiiLib/HiiString.c | 73 ++++++++++++++++----- 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/MdeModulePkg/Include/Library/HiiLib.h b/MdeModulePkg/Include/Library/HiiLib.h index c475cb74a1..66c654dcd3 100644 --- a/MdeModulePkg/Include/Library/HiiLib.h +++ b/MdeModulePkg/Include/Library/HiiLib.h @@ -1,7 +1,7 @@ /** @file Public include file for the HII Library -Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -152,8 +152,43 @@ HiiGetString ( IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL - ) -; + ); + +/** + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. + @param[in] TryBestLanguage If TRUE, try to get the best matching language from all + supported languages. + + + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. + +**/ +EFI_STRING +EFIAPI +HiiGetStringEx ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL, + IN BOOLEAN TryBestLanguage + ); /** Retrieves a string from a string package named by GUID, in the specified language. diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c b/MdeModulePkg/Library/UefiHiiLib/HiiString.c index 95229f8a8c..f3c52ace56 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c @@ -1,7 +1,7 @@ /** @file HII Library implementation that uses DXE protocols and services. - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -220,6 +220,44 @@ HiiGetString ( IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL ) +{ + return HiiGetStringEx (HiiHandle, StringId, Language, TRUE); +} + +/** + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. + @param[in] TryBestLanguage If TRUE, try to get the best matching language from all + supported languages. + + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. + +**/ +EFI_STRING +EFIAPI +HiiGetStringEx ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL, + IN BOOLEAN TryBestLanguage + ) { EFI_STATUS Status; UINTN StringSize; @@ -261,21 +299,26 @@ HiiGetString ( Language = ""; } - // - // Get the best matching language from SupportedLanguages - // - BestLanguage = GetBestLanguage ( - SupportedLanguages, - FALSE, // RFC 4646 mode - Language, // Highest priority - PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority - SupportedLanguages, // Lowest priority - NULL - ); - if (BestLanguage == NULL) { - goto Error; + if (TryBestLanguage) { + // + // Get the best matching language from SupportedLanguages + // + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, // RFC 4646 mode + Language, // Highest priority + PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority + SupportedLanguages, // Lowest priority + NULL + ); + if (BestLanguage == NULL) { + goto Error; + } + } else { + BestLanguage = (CHAR8 *) Language; } + // // Retrieve the size of the string in the string package for the BestLanguage // @@ -337,7 +380,7 @@ Error: if (PlatformLanguage != NULL) { FreePool (PlatformLanguage); } - if (BestLanguage != NULL) { + if (TryBestLanguage && BestLanguage != NULL) { FreePool (BestLanguage); } -- 2.17.1