2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "InternalHiiLib.h"
13 This function create a new string in String Package or updates an existing
14 string in a String Package. If StringId is 0, then a new string is added to
15 a String Package. If StringId is not zero, then a string in String Package is
16 updated. If SupportedLanguages is NULL, then the string is added or updated
17 for all the languages that the String Package supports. If SupportedLanguages
18 is not NULL, then the string is added or updated for the set of languages
19 specified by SupportedLanguages.
21 If HiiHandle is NULL, then ASSERT().
22 If String is NULL, then ASSERT().
24 @param[in] HiiHandle A handle that was previously registered in the
26 @param[in] StringId If zero, then a new string is created in the
27 String Package associated with HiiHandle. If
28 non-zero, then the string specified by StringId
29 is updated in the String Package associated
31 @param[in] String A pointer to the Null-terminated Unicode string
32 to add or update in the String Package associated
34 @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of
35 language codes. If this parameter is NULL, then
36 String is added or updated in the String Package
37 associated with HiiHandle for all the languages
38 that the String Package supports. If this
39 parameter is not NULL, then then String is added
40 or updated in the String Package associated with
41 HiiHandle for the set oflanguages specified by
42 SupportedLanguages. The format of
43 SupportedLanguages must follow the language
44 format assumed the HII Database.
46 @retval 0 The string could not be added or updated in the String Package.
47 @retval Other The EFI_STRING_ID of the newly added or updated string.
53 IN EFI_HII_HANDLE HiiHandle
,
54 IN EFI_STRING_ID StringId
, OPTIONAL
55 IN CONST EFI_STRING String
,
56 IN CONST CHAR8
*SupportedLanguages OPTIONAL
60 CHAR8
*AllocatedLanguages
;
64 ASSERT (HiiHandle
!= NULL
);
65 ASSERT (String
!= NULL
);
67 if (SupportedLanguages
== NULL
) {
69 // Retrieve the languages that the package specified by HiiHandle supports
71 AllocatedLanguages
= HiiGetSupportedLanguages (HiiHandle
);
74 // Allocate a copy of the SupportLanguages string that passed in
76 AllocatedLanguages
= AllocateCopyPool (AsciiStrSize (SupportedLanguages
), SupportedLanguages
);
80 // If there are not enough resources for the supported languages string, then return a StringId of 0
82 if (AllocatedLanguages
== NULL
) {
83 return (EFI_STRING_ID
)(0);
86 Status
= EFI_INVALID_PARAMETER
;
88 // Loop through each language that the string supports
90 for (Supported
= AllocatedLanguages
; *Supported
!= '\0'; ) {
92 // Cache a pointer to the beginning of the current language in the list of languages
97 // Search for the next language separator and replace it with a Null-terminator
99 for (; *Supported
!= 0 && *Supported
!= ';'; Supported
++);
100 if (*Supported
!= 0) {
101 *(Supported
++) = '\0';
104 if ((SupportedLanguages
== NULL
) && AsciiStrnCmp (Language
, UEFI_CONFIG_LANG
, AsciiStrLen (UEFI_CONFIG_LANG
)) == 0) {
106 // Skip string package used for keyword protocol.
112 // If StringId is 0, then call NewString(). Otherwise, call SetString()
114 if (StringId
== (EFI_STRING_ID
)(0)) {
115 Status
= gHiiString
->NewString (gHiiString
, HiiHandle
, &StringId
, Language
, NULL
, String
, NULL
);
117 Status
= gHiiString
->SetString (gHiiString
, HiiHandle
, StringId
, Language
, String
, NULL
);
121 // If there was an error, then break out of the loop and return a StringId of 0
123 if (EFI_ERROR (Status
)) {
129 // Free the buffer of supported languages
131 FreePool (AllocatedLanguages
);
133 if (EFI_ERROR (Status
)) {
134 return (EFI_STRING_ID
)(0);
142 Retrieves a string from a string package names by GUID in a specific language.
143 If the language is not specified, then a string from a string package in the
144 current platform language is retrieved. If the string can not be retrieved
145 using the specified language or the current platform language, then the string
146 is retrieved from the string package in the first language the string package
147 supports. The returned string is allocated using AllocatePool(). The caller
148 is responsible for freeing the allocated buffer using FreePool().
150 If PackageListGuid is NULL, then ASSERT().
151 If StringId is 0, then ASSERT.
153 @param[in] PackageListGuid The GUID of a package list that was previously
154 registered in the HII Database.
155 @param[in] StringId The identifier of the string to retrieved from the
156 string package associated with PackageListGuid.
157 @param[in] Language The language of the string to retrieve. If this
158 parameter is NULL, then the current platform
159 language is used. The format of Language must
160 follow the language format assumed the HII Database.
162 @retval NULL The package list specified by PackageListGuid is not present in the
164 @retval NULL The string specified by StringId is not present in the string package.
165 @retval Other The string was returned.
170 HiiGetPackageString (
171 IN CONST EFI_GUID
*PackageListGuid
,
172 IN EFI_STRING_ID StringId
,
173 IN CONST CHAR8
*Language OPTIONAL
176 EFI_HII_HANDLE
*HiiHandleBuffer
;
177 EFI_HII_HANDLE HiiHandle
;
179 ASSERT (PackageListGuid
!= NULL
);
181 HiiHandleBuffer
= HiiGetHiiHandles (PackageListGuid
);
182 if (HiiHandleBuffer
== NULL
) {
186 HiiHandle
= HiiHandleBuffer
[0];
187 FreePool (HiiHandleBuffer
);
189 return HiiGetString (HiiHandle
, StringId
, Language
);
193 Retrieves a string from a string package in a specific language. If the language
194 is not specified, then a string from a string package in the current platform
195 language is retrieved. If the string can not be retrieved using the specified
196 language or the current platform language, then the string is retrieved from
197 the string package in the first language the string package supports. The
198 returned string is allocated using AllocatePool(). The caller is responsible
199 for freeing the allocated buffer using FreePool().
201 If HiiHandle is NULL, then ASSERT().
202 If StringId is 0, then ASSET.
204 @param[in] HiiHandle A handle that was previously registered in the HII Database.
205 @param[in] StringId The identifier of the string to retrieved from the string
206 package associated with HiiHandle.
207 @param[in] Language The language of the string to retrieve. If this parameter
208 is NULL, then the current platform language is used. The
209 format of Language must follow the language format assumed
212 @retval NULL The string specified by StringId is not present in the string package.
213 @retval Other The string was returned.
219 IN EFI_HII_HANDLE HiiHandle
,
220 IN EFI_STRING_ID StringId
,
221 IN CONST CHAR8
*Language OPTIONAL
228 CHAR8
*SupportedLanguages
;
229 CHAR8
*PlatformLanguage
;
232 ASSERT (HiiHandle
!= NULL
);
233 ASSERT (StringId
!= 0);
236 // Initialize all allocated buffers to NULL
238 SupportedLanguages
= NULL
;
239 PlatformLanguage
= NULL
;
244 // Get the languages that the package specified by HiiHandle supports
246 SupportedLanguages
= HiiGetSupportedLanguages (HiiHandle
);
247 if (SupportedLanguages
== NULL
) {
252 // Get the current platform language setting
254 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
257 // If Languag is NULL, then set it to an empty string, so it will be
258 // skipped by GetBestLanguage()
260 if (Language
== NULL
) {
265 // Get the best matching language from SupportedLanguages
267 BestLanguage
= GetBestLanguage (
269 FALSE
, // RFC 4646 mode
270 Language
, // Highest priority
271 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Next highest priority
272 SupportedLanguages
, // Lowest priority
275 if (BestLanguage
== NULL
) {
280 // Retrieve the size of the string in the string package for the BestLanguage
283 Status
= gHiiString
->GetString (
293 // If GetString() returns EFI_SUCCESS for a zero size,
294 // then there are no supported languages registered for HiiHandle. If GetString()
295 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
296 // in the HII Database
298 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
303 // Allocate a buffer for the return string
305 String
= AllocateZeroPool (StringSize
);
306 if (String
== NULL
) {
311 // Retrieve the string from the string package
313 Status
= gHiiString
->GetString (
322 if (EFI_ERROR (Status
)) {
324 // Free the buffer and return NULL if the supported languages can not be retrieved.
332 // Free allocated buffers
334 if (SupportedLanguages
!= NULL
) {
335 FreePool (SupportedLanguages
);
337 if (PlatformLanguage
!= NULL
) {
338 FreePool (PlatformLanguage
);
340 if (BestLanguage
!= NULL
) {
341 FreePool (BestLanguage
);
345 // Return the Null-terminated Unicode string