MdeModulePkg/Library: Add HiiGetStringEx to UefiHiiLib for EDK2 Redfish

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 <jiaxin.wu@intel.com>
Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Fan Wang <fan.wang@intel.com>
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Reviewed-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Abner Chang 2021-01-22 10:54:57 +08:00 committed by mergify[bot]
parent 1b6c3a94ec
commit 0d96664df3
2 changed files with 119 additions and 39 deletions

View File

@ -1,7 +1,8 @@
/** @file /** @file
Public include file for the HII Library Public include file for the HII Library
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -123,16 +124,8 @@ HiiSetString (
; ;
/** /**
Retrieves a string from a string package in a specific language. If the language Retrieves a string from a string package in a specific language specified in Language
is not specified, then a string from a string package in the current platform or in the best lanaguage. See HiiGetStringEx () for the details.
language is retrieved. If the string cannot 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 ASSERT().
@param[in] HiiHandle A handle that was previously registered in the HII Database. @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 @param[in] StringId The identifier of the string to retrieved from the string
@ -152,8 +145,49 @@ HiiGetString (
IN EFI_HII_HANDLE HiiHandle, IN EFI_HII_HANDLE HiiHandle,
IN EFI_STRING_ID StringId, IN EFI_STRING_ID StringId,
IN CONST CHAR8 *Language OPTIONAL IN CONST CHAR8 *Language OPTIONAL
) );
;
/**
Retrieves a string from a string package in a specific language or in the best
language at discretion of this function according to the priority of languages.
TryBestLanguage is used to get the string in the best language or in the language
specified in Language parameter. The behavior is,
If TryBestLanguage is TRUE, this function looks for the best language for the string.
- 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.
If TryBestLanguage is FALSE, Language must be specified for retrieving the string.
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.
If TryBestLanguage is FALE and Language is NULL, then ASSERT().
@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.If FALSE, the Language must be assigned
for the StringID.
@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. Retrieves a string from a string package named by GUID, in the specified language.

View File

@ -1,7 +1,8 @@
/** @file /** @file
HII Library implementation that uses DXE protocols and services. HII Library implementation that uses DXE protocols and services.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -190,16 +191,8 @@ HiiGetPackageString (
} }
/** /**
Retrieves a string from a string package in a specific language. If the language Retrieves a string from a string package in a specific language specified in Language
is not specified, then a string from a string package in the current platform or in the best lanaguage. See HiiGetStringEx () for the details.
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] HiiHandle A handle that was previously registered in the HII Database.
@param[in] StringId The identifier of the string to retrieved from the string @param[in] StringId The identifier of the string to retrieved from the string
@ -220,6 +213,51 @@ HiiGetString (
IN EFI_STRING_ID StringId, IN EFI_STRING_ID StringId,
IN CONST CHAR8 *Language OPTIONAL IN CONST CHAR8 *Language OPTIONAL
) )
{
return HiiGetStringEx (HiiHandle, StringId, Language, TRUE);
}
/**
Retrieves a string from a string package in a specific language or in the best
language at discretion of this function according to the priority of languages.
TryBestLanguage is used to get the string in the best language or in the language
specified in Language parameter. The behavior is,
If TryBestLanguage is TRUE, this function looks for the best language for the string.
- 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.
If TryBestLanguage is FALSE, Language must be specified for retrieving the string.
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.
If TryBestLanguage is FALE and Language is NULL, then ASSERT().
@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.If FALSE, the Language must be assigned
for the StringID.
@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; EFI_STATUS Status;
UINTN StringSize; UINTN StringSize;
@ -231,7 +269,10 @@ HiiGetString (
ASSERT (HiiHandle != NULL); ASSERT (HiiHandle != NULL);
ASSERT (StringId != 0); ASSERT (StringId != 0);
//
// Language must be specified if TryBestLanguage = FALSE.
//
ASSERT (!(!TryBestLanguage && Language == NULL));
// //
// Initialize all allocated buffers to NULL // Initialize all allocated buffers to NULL
// //
@ -261,21 +302,26 @@ HiiGetString (
Language = ""; Language = "";
} }
// if (TryBestLanguage) {
// Get the best matching language from SupportedLanguages //
// // Get the best matching language from SupportedLanguages
BestLanguage = GetBestLanguage ( //
SupportedLanguages, BestLanguage = GetBestLanguage (
FALSE, // RFC 4646 mode SupportedLanguages,
Language, // Highest priority FALSE, // RFC 4646 mode
PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority Language, // Highest priority
SupportedLanguages, // Lowest priority PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority
NULL SupportedLanguages, // Lowest priority
); NULL
if (BestLanguage == NULL) { );
goto Error; if (BestLanguage == NULL) {
goto Error;
}
} else {
BestLanguage = (CHAR8 *) Language;
} }
// //
// Retrieve the size of the string in the string package for the BestLanguage // Retrieve the size of the string in the string package for the BestLanguage
// //
@ -337,7 +383,7 @@ Error:
if (PlatformLanguage != NULL) { if (PlatformLanguage != NULL) {
FreePool (PlatformLanguage); FreePool (PlatformLanguage);
} }
if (BestLanguage != NULL) { if (TryBestLanguage && BestLanguage != NULL) {
FreePool (BestLanguage); FreePool (BestLanguage);
} }