2 This file implements the protocol functions related to string package.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HiiDatabase.h"
23 ISO639TORFC3066MAP Iso639ToRfc3066Map
[] = {
29 // Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
30 // Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
31 // The last 2 CHAR8 values are the ISO 639-1 code.
33 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable
[] =
173 ConvertIso639ToRfc3066 (
178 CHAR8 AsciiLanguage
[ISO_639_2_ENTRY_SIZE
+ 1];
180 AsciiStrnCpy (AsciiLanguage
, Iso638Lang
, sizeof (AsciiLanguage
));
181 for (Index
= 0; Index
< ISO_639_2_ENTRY_SIZE
+ 1; Index
++) {
182 if (AsciiLanguage
[Index
] == 0) {
184 } else if (AsciiLanguage
[Index
] >= 'A' && AsciiLanguage
[Index
] <= 'Z') {
185 AsciiLanguage
[Index
] = (CHAR8
) (AsciiLanguage
[Index
] - 'A' + 'a');
189 for (Index
= 0; Index
< sizeof (Iso639ToRfc3066Map
) / sizeof (Iso639ToRfc3066Map
[0]); Index
++) {
190 if (AsciiStrnCmp (AsciiLanguage
, Iso639ToRfc3066Map
[Index
].Iso639
, AsciiStrSize (AsciiLanguage
)) == 0) {
191 return Iso639ToRfc3066Map
[Index
].Rfc3066
;
195 return (CHAR8
*) NULL
;
199 Convert language code from RFC3066 to ISO639-2.
201 @param LanguageRfc3066 RFC3066 language code.
202 @param LanguageIso639 ISO639-2 language code.
204 @retval EFI_SUCCESS Language code converted.
205 @retval EFI_NOT_FOUND Language code not found.
210 ConvertRfc3066LanguageToIso639Language (
211 IN CHAR8
*LanguageRfc3066
,
212 OUT CHAR8
*LanguageIso639
217 if ((LanguageRfc3066
[2] != '-') && (LanguageRfc3066
[2] != 0)) {
218 CopyMem (LanguageIso639
, LanguageRfc3066
, 3);
222 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
223 if (CompareMem (LanguageRfc3066
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2) == 0) {
224 CopyMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3);
229 return EFI_NOT_FOUND
;
234 Convert language code from ISO639-2 to RFC3066 and return the converted language.
235 Caller is responsible for freeing the allocated buffer.
237 LanguageIso639 contain a single ISO639-2 code such as
240 If LanguageIso639 is NULL, then ASSERT.
241 If LanguageRfc3066 is NULL, then ASSERT.
243 @param LanguageIso639 ISO639-2 language code.
245 @return the allocated buffer or NULL, if the language is not found.
250 ConvertIso639LanguageToRfc3066Language (
251 IN CONST CHAR8
*LanguageIso639
255 CHAR8
*Rfc3066Language
;
257 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
258 if (CompareMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3) == 0) {
259 Rfc3066Language
= AllocateZeroPool (3);
260 if (Rfc3066Language
!= NULL
) {
261 Rfc3066Language
= CopyMem (Rfc3066Language
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2);
263 return Rfc3066Language
;
271 Test if all of the characters in a string have corresponding font characters.
273 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
274 return EFI_UNSUPPORTED.
276 @param This A pointer to the EFI_HII_PROTOCOL instance.
277 @param StringToTest A pointer to a Unicode string.
278 @param FirstMissing A pointer to an index into the string. On input, the index of
279 the first character in the StringToTest to examine. On exit, the index
280 of the first character encountered for which a glyph is unavailable.
281 If all glyphs in the string are available, the index is the index of the terminator
283 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS,
284 it contains the amount of memory that is required to store the string? glyph equivalent.
286 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.
291 IN EFI_HII_PROTOCOL
*This
,
292 IN CHAR16
*StringToTest
,
293 IN OUT UINT32
*FirstMissing
,
294 OUT UINT32
*GlyphBufferSize
299 return EFI_UNSUPPORTED
;
304 Find the corressponding TAG GUID from a Framework HII Handle given.
306 @param Private The HII Thunk Module Private context.
307 @param FwHiiHandle The Framemwork HII Handle.
308 @param TagGuid The output of TAG GUID found.
310 @return NULL If Framework HII Handle is invalid.
311 @return The corresponding HII Thunk Context.
314 GetTagGuidByFwHiiHandle (
315 IN CONST HII_THUNK_PRIVATE_DATA
*Private
,
316 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle
,
317 OUT EFI_GUID
*TagGuid
321 HII_THUNK_CONTEXT
*ThunkContext
;
323 ASSERT (TagGuid
!= NULL
);
325 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
326 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
328 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
330 if (FwHiiHandle
== ThunkContext
->FwHiiHandle
) {
331 CopyGuid (TagGuid
, &ThunkContext
->TagGuid
);
335 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
338 return EFI_NOT_FOUND
;
342 Create or update the String given a new string and String ID.
344 @param ThunkContext The Thunk Context.
345 @param Rfc3066AsciiLanguage The RFC 3066 Language code in ASCII string format.
346 @param NewString The new string.
347 @param StringId The String ID. If StringId is 0, a new String Token
348 is created. Otherwise, the String Token StringId is
352 @retval EFI_SUCCESS The new string is created or updated successfully.
353 The new String Token ID is returned in StringId if
354 *StringId is 0 on input.
355 @return Others The update of string failed.
360 IN CONST HII_THUNK_CONTEXT
*ThunkContext
,
361 IN CONST CHAR8
*Rfc3066AsciiLanguage
,
362 IN CHAR16
*NewString
,
363 IN OUT STRING_REF
*StringId
366 EFI_STRING_ID NewStringId
;
368 NewStringId
= HiiSetString (ThunkContext
->UefiHiiHandle
, *StringId
, NewString
, Rfc3066AsciiLanguage
);
369 *StringId
= NewStringId
;
370 if (NewStringId
== 0) {
372 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
374 return EFI_INVALID_PARAMETER
;
381 Create or update a String Token in a String Package.
383 If *Reference == 0, a new String Token is created.
385 @param This A pointer to the EFI_HII_PROTOCOL instance.
386 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language
387 identifier, indicating the language to print. A string consisting of
388 all spaces indicates that the string is applicable to all languages.
389 @param Handle The handle of the language pack to which the string is to be added.
390 @param Token The string token assigned to the string.
391 @param NewString The string to be added.
394 @retval EFI_SUCCESS The string was effectively registered.
395 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the
402 IN EFI_HII_PROTOCOL
*This
,
404 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
405 IN OUT STRING_REF
*Reference
,
410 HII_THUNK_PRIVATE_DATA
*Private
;
413 HII_THUNK_CONTEXT
*ThunkContext
;
414 HII_THUNK_CONTEXT
*StringPackThunkContext
;
415 EFI_STRING_ID StringId
;
416 EFI_STRING_ID LastStringId
;
417 CHAR8 AsciiLanguage
[ISO_639_2_ENTRY_SIZE
+ 1];
418 CHAR16 LanguageCopy
[ISO_639_2_ENTRY_SIZE
+ 1];
419 CHAR8
*Rfc3066AsciiLanguage
;
421 LastStringId
= (EFI_STRING_ID
) 0;
422 StringId
= (EFI_STRING_ID
) 0;
423 Rfc3066AsciiLanguage
= NULL
;
425 if (Language
!= NULL
) {
426 ZeroMem (AsciiLanguage
, sizeof (AsciiLanguage
));;
427 ZeroMem (LanguageCopy
, sizeof (LanguageCopy
));
428 CopyMem (LanguageCopy
, Language
, ISO_639_2_ENTRY_SIZE
* sizeof (CHAR16
));
429 UnicodeStrToAsciiStr (LanguageCopy
, AsciiLanguage
);
430 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (AsciiLanguage
);
431 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
434 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
436 StringPackThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
437 if (StringPackThunkContext
== NULL
) {
438 return EFI_INVALID_PARAMETER
;
441 if (StringPackThunkContext
->SharingStringPack
) {
442 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
443 ASSERT_EFI_ERROR (Status
);
445 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
446 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
447 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
449 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
450 if (ThunkContext
->SharingStringPack
) {
451 StringId
= *Reference
;
452 Status
= UpdateString (ThunkContext
, Rfc3066AsciiLanguage
, NewString
, &StringId
);
453 if (EFI_ERROR (Status
)) {
458 if (*Reference
== 0) {
460 // When creating new string token, make sure all created token is the same
461 // for all string packages registered using FW HII interface.
463 if (LastStringId
== (EFI_STRING_ID
) 0) {
464 LastStringId
= StringId
;
466 if (LastStringId
!= StringId
) {
476 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
479 StringId
= *Reference
;
480 Status
= UpdateString (StringPackThunkContext
, Rfc3066AsciiLanguage
, NewString
, &StringId
);
483 if (!EFI_ERROR (Status
)) {
484 if (*Reference
== 0) {
485 *Reference
= StringId
;
489 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
491 Status
= EFI_INVALID_PARAMETER
;
498 This function removes any new strings that were added after the initial string export for this handle.
499 UEFI HII String Protocol does not have Reset String function. This function perform nothing.
501 @param This A pointer to the EFI_HII_PROTOCOL instance.
502 @param Handle The HII handle on which the string resides.
504 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.
510 IN EFI_HII_PROTOCOL
*This
,
511 IN FRAMEWORK_EFI_HII_HANDLE Handle
518 This function extracts a string from a package already registered with the EFI HII database.
520 @param This A pointer to the EFI_HII_PROTOCOL instance.
521 @param Handle The HII handle on which the string resides.
522 @param Token The string token assigned to the string.
523 @param Raw If TRUE, the string is returned unedited in the internal storage format described
524 above. If false, the string returned is edited by replacing <cr> with <space>
525 and by removing special characters such as the <wide> prefix.
526 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
527 identifier, indicating the language to print. If the LanguageString is empty (starts
528 with a NULL), the default system language will be used to determine the language.
529 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
530 small, this parameter is filled with the length of the buffer needed.
531 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
534 @retval EFI_INVALID_PARAMETER If input parameter is invalid.
535 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.
536 @retval EFI_SUCCESS Operation is successful.
542 IN EFI_HII_PROTOCOL
*This
,
543 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
546 IN CHAR16
*LanguageString
,
547 IN OUT UINTN
*BufferLengthTemp
,
548 OUT EFI_STRING StringBuffer
551 HII_THUNK_PRIVATE_DATA
*Private
;
552 CHAR8
*Iso639AsciiLanguage
;
553 CHAR8
*Rfc3066AsciiLanguage
;
554 CHAR8
*SupportedLanguages
;
555 CHAR8
*PlatformLanguage
;
557 EFI_HII_HANDLE UefiHiiHandle
;
560 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
562 Iso639AsciiLanguage
= NULL
;
563 Rfc3066AsciiLanguage
= NULL
;
565 if (LanguageString
!= NULL
) {
566 Iso639AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
567 if (Iso639AsciiLanguage
== NULL
) {
568 return EFI_OUT_OF_RESOURCES
;
570 UnicodeStrToAsciiStr (LanguageString
, Iso639AsciiLanguage
);
573 // Caller of Framework HII Interface uses the Language Identification String defined
574 // in Iso639. So map it to the Language Identifier defined in RFC3066.
576 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (Iso639AsciiLanguage
);
579 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
580 // Iso639ToRfc3066Map.
582 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
586 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
587 if (UefiHiiHandle
== NULL
) {
588 Status
= EFI_NOT_FOUND
;
592 if (Rfc3066AsciiLanguage
== NULL
) {
594 // Get the languages that the package specified by HiiHandle supports
596 SupportedLanguages
= HiiGetSupportedLanguages (UefiHiiHandle
);
597 if (SupportedLanguages
== NULL
) {
602 // Get the current platform language setting
604 PlatformLanguage
= GetEfiGlobalVariable (L
"PlatformLang");
605 if (PlatformLanguage
== NULL
) {
610 // Get the best matching language from SupportedLanguages
612 BestLanguage
= GetBestLanguage (
614 FALSE
, // RFC 4646 mode
615 PlatformLanguage
, // Next highest priority
616 SupportedLanguages
, // Lowest priority
619 if (BestLanguage
== NULL
) {
620 FreePool (PlatformLanguage
);
622 FreePool (SupportedLanguages
);
624 Status
= EFI_INVALID_PARAMETER
;
628 Status
= mHiiStringProtocol
->GetString (
637 FreePool (BestLanguage
);
639 Status
= mHiiStringProtocol
->GetString (
641 Rfc3066AsciiLanguage
,
651 if (Iso639AsciiLanguage
!= NULL
) {
652 FreePool (Iso639AsciiLanguage
);
660 This function allows a program to extract a part of a string of not more than a given width.
661 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
662 columns. The effort of measuring the fit of strings inside columns is localized to this call.
664 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
665 return EFI_UNSUPPORTED.
667 @param This A pointer to the EFI_HII_PROTOCOL instance.
668 @param Handle The HII handle on which the string resides.
669 @param Token The string token assigned to the string.
670 @param Raw If TRUE, the string is returned unedited in the internal storage format described
671 above. If false, the string returned is edited by replacing <cr> with <space>
672 and by removing special characters such as the <wide> prefix.
673 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
674 identifier, indicating the language to print. If the LanguageString is empty (starts
675 with a NULL), the default system language will be used to determine the language.
676 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
677 small, this parameter is filled with the length of the buffer needed.
678 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
681 @retval EFI_UNSUPPORTED.
686 IN EFI_HII_PROTOCOL
*This
,
687 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
689 IN OUT UINT16
*Index
,
691 IN CHAR16
*LanguageString
,
692 IN OUT UINT16
*BufferLength
,
693 OUT EFI_STRING StringBuffer
697 return EFI_UNSUPPORTED
;