X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FString.c;h=756f19c7c3fc2d46cee17329691c4a7d729cd338;hp=bda7d5ac06afb1099faec19ca2d84f4f952da73d;hb=f5e6aa8e176c3f1dc557d85749ef797b8d482b56;hpb=d6a82eaf8d8971f9d4eecda80f421281363c0772 diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c index bda7d5ac06..756f19c7c3 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c @@ -2,8 +2,9 @@ Implementation for EFI_HII_STRING_PROTOCOL. -Copyright (c) 2007 - 2010, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -248,6 +249,7 @@ GetStringFontInfo ( @param StringTextOffset Offset, relative to the found block address, of the string text information. @param LastStringId Output the last string id when StringId = 0 or StringId = -1. + @param StartStringId The first id in the skip block which StringId in the block. @retval EFI_SUCCESS The string text and font is retrieved successfully. @@ -265,7 +267,8 @@ FindStringBlock ( OUT UINT8 *BlockType, OPTIONAL OUT UINT8 **StringBlockAddr, OPTIONAL OUT UINTN *StringTextOffset, OPTIONAL - OUT EFI_STRING_ID *LastStringId OPTIONAL + OUT EFI_STRING_ID *LastStringId, OPTIONAL + OUT EFI_STRING_ID *StartStringId OPTIONAL ) { UINT8 *BlockHdr; @@ -293,6 +296,7 @@ FindStringBlock ( ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE); CurrentStringId = 1; + StringSize = 0; if (StringId != (EFI_STRING_ID) (-1) && StringId != 0) { ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); @@ -333,12 +337,13 @@ FindStringBlock ( case EFI_HII_SIBT_STRINGS_SCSU: CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16)); - StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8); + StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8)); BlockSize += StringTextPtr - BlockHdr; for (Index = 0; Index < StringCount; Index++) { BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -352,15 +357,16 @@ FindStringBlock ( case EFI_HII_SIBT_STRINGS_SCSU_FONT: CopyMem ( &StringCount, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT16) ); - StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8); + StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8)); BlockSize += StringTextPtr - BlockHdr; for (Index = 0; Index < StringCount; Index++) { BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -404,6 +410,7 @@ FindStringBlock ( GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); BlockSize += StringSize; if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -420,13 +427,14 @@ FindStringBlock ( BlockSize += Offset; CopyMem ( &StringCount, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT16) ); for (Index = 0; Index < StringCount; Index++) { GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); BlockSize += StringSize; if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -459,7 +467,7 @@ FindStringBlock ( break; case EFI_HII_SIBT_SKIP1: - SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK))); + SkipCount = (UINT16) (*(UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK))); CurrentStringId = (UINT16) (CurrentStringId + SkipCount); BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK); break; @@ -473,7 +481,7 @@ FindStringBlock ( case EFI_HII_SIBT_EXT1: CopyMem ( &Length8, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT8) ); BlockSize += Length8; @@ -488,7 +496,7 @@ FindStringBlock ( // BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); CopyMem (&FontId, BlockHdr, sizeof (UINT8)); - BlockHdr += sizeof (UINT8); + BlockHdr ++; CopyMem (&FontSize, BlockHdr, sizeof (UINT16)); BlockHdr += sizeof (UINT16); CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE)); @@ -529,7 +537,7 @@ FindStringBlock ( case EFI_HII_SIBT_EXT4: CopyMem ( &Length32, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT32) ); @@ -540,12 +548,21 @@ FindStringBlock ( break; } - if (StringId > 0) { + if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); + *BlockType = *BlockHdr; + *StringBlockAddr = BlockHdr; + *StringTextOffset = Offset; + if (StringId == CurrentStringId - 1) { - *BlockType = *BlockHdr; - *StringBlockAddr = BlockHdr; - *StringTextOffset = Offset; - return EFI_SUCCESS; + // + // if only one skip item, return EFI_NOT_FOUND. + // + if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) { + return EFI_NOT_FOUND; + } else { + return EFI_SUCCESS; + } } if (StringId < CurrentStringId - 1) { @@ -553,14 +570,16 @@ FindStringBlock ( } } BlockHdr = StringPackage->StringBlock + BlockSize; - + if (StartStringId != NULL) { + *StartStringId = CurrentStringId; + } } // // Get last string ID // - if (StringId == (EFI_STRING_ID) (-1)) { - *LastStringId = CurrentStringId - 1; + if (StringId == (EFI_STRING_ID) (-1) && LastStringId != NULL) { + *LastStringId = (EFI_STRING_ID) (CurrentStringId - 1); return EFI_SUCCESS; } @@ -599,7 +618,7 @@ GetStringWorker ( IN HII_STRING_PACKAGE_INSTANCE *StringPackage, IN EFI_STRING_ID StringId, OUT EFI_STRING String, - IN OUT UINTN *StringSize, + IN OUT UINTN *StringSize, OPTIONAL OUT EFI_FONT_INFO **StringFontInfo OPTIONAL ) { @@ -610,7 +629,7 @@ GetStringWorker ( EFI_STATUS Status; UINT8 FontId; - ASSERT (StringPackage != NULL && StringSize != NULL); + ASSERT (StringPackage != NULL); ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE); // @@ -623,12 +642,20 @@ GetStringWorker ( &BlockType, &StringBlockAddr, &StringTextOffset, + NULL, NULL ); if (EFI_ERROR (Status)) { return Status; } + if (StringSize == NULL) { + // + // String text buffer is not requested + // + return EFI_SUCCESS; + } + // // Get the string text. // @@ -677,6 +704,153 @@ GetStringWorker ( return EFI_SUCCESS; } +/** + If GetStringBlock find the StringId's string is not saved in the exist string block, + this function will create the UCS2 string block to save the string; also split the + skip block into two or one skip block. + + This is a internal function. + + @param StringPackage Hii string package instance. + @param StartStringId The first id in the skip block which StringId in the block. + @param StringId The string's id, which is unique within + PackageList. + @param BlockType Output the block type of found string block. + @param StringBlockAddr Output the block address of found string block. + @param FontBlock whether this string block has font info. + + @retval EFI_SUCCESS The string font is outputed successfully. + @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block. + +**/ +EFI_STATUS +InsertLackStringBlock ( + IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage, + IN EFI_STRING_ID StartStringId, + IN EFI_STRING_ID StringId, + IN OUT UINT8 *BlockType, + IN OUT UINT8 **StringBlockAddr, + IN BOOLEAN FontBlock + ) +{ + UINT8 *BlockPtr; + UINT8 *StringBlock; + UINT32 SkipLen; + UINT32 OldBlockSize; + UINT32 NewBlockSize; + UINT32 FrontSkipNum; + UINT32 NewUCSBlockLen; + UINT8 *OldStringAddr; + UINT32 IdCount; + + FrontSkipNum = 0; + SkipLen = 0; + OldStringAddr = *StringBlockAddr; + + ASSERT (*BlockType == EFI_HII_SIBT_SKIP1 || *BlockType == EFI_HII_SIBT_SKIP2); + // + // Old skip block size. + // + if (*BlockType == EFI_HII_SIBT_SKIP1) { + SkipLen = sizeof (EFI_HII_SIBT_SKIP1_BLOCK); + IdCount = *(UINT8*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK)); + } else { + SkipLen = sizeof (EFI_HII_SIBT_SKIP2_BLOCK); + IdCount = *(UINT16*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK)); + } + + // + // New create UCS or UCS2 block size. + // + if (FontBlock) { + NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK); + } else { + NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK); + } + + OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize; + + if (StartStringId == StringId) { + // + // New block + [Skip block] + // + if (IdCount > 1) { + NewBlockSize = OldBlockSize + NewUCSBlockLen; + } else { + NewBlockSize = OldBlockSize + NewUCSBlockLen - SkipLen; + } + } else if (StartStringId + IdCount - 1 == StringId){ + // + // Skip block + New block + // + NewBlockSize = OldBlockSize + NewUCSBlockLen; + FrontSkipNum = StringId - StartStringId; + } else { + // + // Skip block + New block + [Skip block] + // + NewBlockSize = OldBlockSize + NewUCSBlockLen + SkipLen; + FrontSkipNum = StringId - StartStringId; + } + + StringBlock = (UINT8 *) AllocateZeroPool (NewBlockSize); + if (StringBlock == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Copy old block in front of skip block. + // + CopyMem (StringBlock, StringPackage->StringBlock, OldStringAddr - StringPackage->StringBlock); + BlockPtr = StringBlock + (OldStringAddr - StringPackage->StringBlock); + + if (FrontSkipNum > 0) { + *BlockPtr = *BlockType; + if (*BlockType == EFI_HII_SIBT_SKIP1) { + *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) FrontSkipNum; + } else { + *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) FrontSkipNum; + } + BlockPtr += SkipLen; + } + + // + // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK + // + *StringBlockAddr = BlockPtr; + if (FontBlock) { + *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT; + } else { + *BlockPtr = EFI_HII_SIBT_STRING_UCS2; + } + BlockPtr += NewUCSBlockLen; + + if (IdCount > FrontSkipNum + 1) { + *BlockPtr = *BlockType; + if (*BlockType == EFI_HII_SIBT_SKIP1) { + *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) (IdCount - FrontSkipNum - 1); + } else { + *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) (IdCount - FrontSkipNum - 1); + } + BlockPtr += SkipLen; + } + + // + // Append a EFI_HII_SIBT_END block to the end. + // + CopyMem (BlockPtr, OldStringAddr + SkipLen, OldBlockSize - (OldStringAddr - StringPackage->StringBlock) - SkipLen); + + if (FontBlock) { + *BlockType = EFI_HII_SIBT_STRING_UCS2_FONT; + } else { + *BlockType = EFI_HII_SIBT_STRING_UCS2; + } + FreePool (StringPackage->StringBlock); + StringPackage->StringBlock = StringBlock; + StringPackage->StringPkgHdr->Header.Length += NewBlockSize - OldBlockSize; + + return EFI_SUCCESS; +} /** Parse all string blocks to set a String specified by StringId. @@ -724,8 +898,10 @@ SetStringWorker ( EFI_HII_SIBT_EXT2_BLOCK Ext2; UINTN StringSize; UINTN TmpSize; + EFI_STRING_ID StartStringId; - + StartStringId = 0; + StringSize = 0; ASSERT (Private != NULL && StringPackage != NULL && String != NULL); ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE); // @@ -738,10 +914,25 @@ SetStringWorker ( &BlockType, &StringBlockAddr, &StringTextOffset, - NULL + NULL, + &StartStringId ); - if (EFI_ERROR (Status)) { - return Status; + if (EFI_ERROR (Status) && (BlockType == EFI_HII_SIBT_SKIP1 || BlockType == EFI_HII_SIBT_SKIP2)) { + Status = InsertLackStringBlock(StringPackage, + StartStringId, + StringId, + &BlockType, + &StringBlockAddr, + (BOOLEAN)(StringFontInfo != NULL) + ); + if (EFI_ERROR (Status)) { + return Status; + } + if (StringFontInfo != NULL) { + StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16); + } else { + StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16); + } } LocalFont = NULL; @@ -799,7 +990,7 @@ SetStringWorker ( case EFI_HII_SIBT_STRINGS_SCSU: case EFI_HII_SIBT_STRINGS_SCSU_FONT: BlockSize = OldBlockSize + StrLen (String); - BlockSize -= AsciiStrLen ((CHAR8 *) StringTextPtr); + BlockSize -= AsciiStrSize ((CHAR8 *) StringTextPtr); Block = AllocateZeroPool (BlockSize); if (Block == NULL) { return EFI_OUT_OF_RESOURCES; @@ -891,7 +1082,7 @@ SetStringWorker ( BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, &GlobalFont->FontInfo->FontSize, sizeof (UINT16)); BlockPtr += sizeof (UINT16); CopyMem (BlockPtr, &GlobalFont->FontInfo->FontStyle, sizeof (UINT32)); @@ -1041,7 +1232,8 @@ HiiNewString ( NULL, NULL, NULL, - &NextStringId + &NextStringId, + NULL ); if (EFI_ERROR (Status)) { goto Done; @@ -1103,7 +1295,7 @@ HiiNewString ( // // Set new StringId // - *StringId = NewStringId + 1; + *StringId = (EFI_STRING_ID) (NewStringId + 1); } if (MatchStringPackage != NULL) { @@ -1143,7 +1335,7 @@ HiiNewString ( StringPackage->StringPkgHdr->StringInfoOffset = HeaderSize; CopyMem (StringPackage->StringPkgHdr->LanguageWindow, mLanguageWindow, 16 * sizeof (CHAR16)); StringPackage->StringPkgHdr->LanguageName = 1; - AsciiStrCpy (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language); + AsciiStrCpyS (StringPackage->StringPkgHdr->Language, (HeaderSize - OFFSET_OF(EFI_HII_STRING_PACKAGE_HDR,Language)) / sizeof (CHAR8), (CHAR8 *) Language); // // Calculate the length of the string blocks, including string block to record @@ -1252,7 +1444,7 @@ HiiNewString ( *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT; BlockPtr += sizeof (EFI_HII_STRING_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String)); BlockPtr += StrSize ((EFI_STRING) String); @@ -1296,7 +1488,7 @@ HiiNewString ( BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontSize, sizeof (UINT16)); BlockPtr += sizeof (UINT16); CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontStyle, sizeof (EFI_HII_FONT_STYLE)); @@ -1313,7 +1505,7 @@ HiiNewString ( *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT; BlockPtr += sizeof (EFI_HII_STRING_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String)); BlockPtr += StrSize ((EFI_STRING) String); @@ -1400,7 +1592,8 @@ Done: @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to hold the string. - @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL. + @retval EFI_INVALID_PARAMETER The Language or StringSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by StringSize was not zero and String was NULL. @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the request. @@ -1471,7 +1664,7 @@ HiiGetString ( Link = Link->ForwardLink ) { StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); - Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo); + Status = GetStringWorker (Private, StringPackage, StringId, NULL, NULL, NULL); if (!EFI_ERROR (Status)) { return EFI_INVALID_LANGUAGE; } @@ -1578,13 +1771,15 @@ HiiSetString ( @param This A pointer to the EFI_HII_STRING_PROTOCOL instance. @param PackageList The package list to examine. - @param Languages Points to the buffer to hold the returned string. + @param Languages Points to the buffer to hold the returned + null-terminated ASCII string. @param LanguagesSize On entry, points to the size of the buffer pointed to by Languages, in bytes. On return, points to the length of Languages, in bytes. @retval EFI_SUCCESS The languages were returned successfully. - @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The LanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by LanguagesSize is not zero and Languages is NULL. @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of supported languages. LanguageSize is updated to contain the required size. @@ -1608,7 +1803,10 @@ HiiGetLanguages ( HII_STRING_PACKAGE_INSTANCE *StringPackage; UINTN ResultSize; - if (This == NULL || Languages == NULL || LanguagesSize == NULL || PackageList == NULL) { + if (This == NULL || LanguagesSize == NULL || PackageList == NULL) { + return EFI_INVALID_PARAMETER; + } + if (*LanguagesSize != 0 && Languages == NULL) { return EFI_INVALID_PARAMETER; } if (!IsHiiHandleValid (PackageList)) { @@ -1640,7 +1838,7 @@ HiiGetLanguages ( StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); ResultSize += AsciiStrSize (StringPackage->StringPkgHdr->Language); if (ResultSize <= *LanguagesSize) { - AsciiStrCpy (Languages, StringPackage->StringPkgHdr->Language); + AsciiStrCpyS (Languages, *LanguagesSize / sizeof (CHAR8), StringPackage->StringPkgHdr->Language); Languages += AsciiStrSize (StringPackage->StringPkgHdr->Language); *(Languages - 1) = L';'; } @@ -1666,26 +1864,30 @@ HiiGetLanguages ( @param This A pointer to the EFI_HII_STRING_PROTOCOL instance. @param PackageList The package list to examine. - @param FirstLanguage Points to the primary language. - @param SecondaryLanguages Points to the buffer to hold the returned list of + @param PrimaryLanguage Points to the null-terminated ASCII string that specifies + the primary language. Languages are specified in the + format specified in Appendix M of the UEFI 2.0 specification. + @param SecondaryLanguages Points to the buffer to hold the returned null-terminated + ASCII string that describes the list of secondary languages for the specified - FirstLanguage. If there are no secondary - languages, the function returns successfully, but + PrimaryLanguage. If there are no secondary + languages, the function returns successfully, but this is set to NULL. @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed - to by SecondaryLanguages, in bytes. On return, + to by SecondaryLanguages, in bytes. On return, points to the length of SecondaryLanguages in bytes. @retval EFI_SUCCESS Secondary languages were correctly returned. - @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or - SecondaryLanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by SecondaryLanguagesSize is not + zero and SecondaryLanguages is NULL. @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is too small to hold the returned information. - SecondLanguageSize is updated to hold the size of + SecondaryLanguageSize is updated to hold the size of the buffer required. - @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not - present in the specified package list. - @retval EFI_NOT_FOUND The specified PackageList is not in the Database. + @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not + present in the specified package list. + @retval EFI_NOT_FOUND The specified PackageList is not in the Database. **/ EFI_STATUS @@ -1693,7 +1895,7 @@ EFIAPI HiiGetSecondaryLanguages ( IN CONST EFI_HII_STRING_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, - IN CONST CHAR8 *FirstLanguage, + IN CONST CHAR8 *PrimaryLanguage, IN OUT CHAR8 *SecondaryLanguages, IN OUT UINTN *SecondaryLanguagesSize ) @@ -1707,10 +1909,10 @@ HiiGetSecondaryLanguages ( CHAR8 *Languages; UINTN ResultSize; - if (This == NULL || PackageList == NULL || FirstLanguage == NULL) { + if (This == NULL || PackageList == NULL || PrimaryLanguage == NULL || SecondaryLanguagesSize == NULL) { return EFI_INVALID_PARAMETER; } - if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) { + if (SecondaryLanguages == NULL && *SecondaryLanguagesSize != 0) { return EFI_INVALID_PARAMETER; } if (!IsHiiHandleValid (PackageList)) { @@ -1738,7 +1940,7 @@ HiiGetSecondaryLanguages ( Link1 = Link1->ForwardLink ) { StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); - if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) FirstLanguage)) { + if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) PrimaryLanguage)) { Languages = StringPackage->StringPkgHdr->Language; // // Language is a series of ';' terminated strings, first one is primary @@ -1753,7 +1955,7 @@ HiiGetSecondaryLanguages ( ResultSize = AsciiStrSize (Languages); if (ResultSize <= *SecondaryLanguagesSize) { - AsciiStrCpy (SecondaryLanguages, Languages); + AsciiStrCpyS (SecondaryLanguages, *SecondaryLanguagesSize / sizeof (CHAR8), Languages); } else { *SecondaryLanguagesSize = ResultSize; return EFI_BUFFER_TOO_SMALL; @@ -1766,11 +1968,36 @@ HiiGetSecondaryLanguages ( return EFI_INVALID_LANGUAGE; } +/** + Converts the ascii character of the string from uppercase to lowercase. + This is a internal function. + + @param ConfigString String to be converted + +**/ +VOID +EFIAPI +AsciiHiiToLower ( + IN CHAR8 *ConfigString + ) +{ + ASSERT (ConfigString != NULL); + + // + // Convert all hex digits in range [A-F] in the configuration header to [a-f] + // + for (; *ConfigString != '\0'; ConfigString++) { + if ( *ConfigString >= 'A' && *ConfigString <= 'Z') { + *ConfigString = (CHAR8) (*ConfigString - 'A' + 'a'); + } + } +} + /** Compare whether two names of languages are identical. - @param Language1 Name of language 1 - @param Language2 Name of language 2 + @param Language1 Name of language 1 from StringPackage + @param Language2 Name of language 2 to be compared with language 1. @retval TRUE same @retval FALSE not same @@ -1782,25 +2009,48 @@ HiiCompareLanguage ( IN CHAR8 *Language2 ) { + UINTN Index; + UINTN StrLen; + CHAR8 *Lan1; + CHAR8 *Lan2; + // - // Porting Guide: - // This library interface is simply obsolete. - // Include the source code to user code. + // Convert to lower to compare. // - UINTN Index; + StrLen = AsciiStrSize (Language1); + Lan1 = AllocateZeroPool (StrLen); + ASSERT (Lan1 != NULL); + AsciiStrCpyS(Lan1, StrLen / sizeof (CHAR8), Language1); + AsciiHiiToLower (Lan1); + + StrLen = AsciiStrSize (Language2); + Lan2 = AllocateZeroPool (StrLen); + ASSERT (Lan2 != NULL); + AsciiStrCpyS(Lan2, StrLen / sizeof (CHAR8), Language2); + AsciiHiiToLower (Lan2); - for (Index = 0; (Language1[Index] != 0) && (Language2[Index] != 0); Index++) { - if (Language1[Index] != Language2[Index]) { + // + // Compare the Primary Language in Language1 to Language2 + // + for (Index = 0; Lan1[Index] != 0 && Lan1[Index] != ';'; Index++) { + if (Lan1[Index] != Lan2[Index]) { + // + // Return FALSE if any characters are different. + // + FreePool (Lan1); + FreePool (Lan2); return FALSE; } } - if (((Language1[Index] == 0) && (Language2[Index] == 0)) || - ((Language1[Index] == 0) && (Language2[Index] != ';')) || - ((Language1[Index] == ';') && (Language2[Index] != 0)) || - ((Language1[Index] == ';') && (Language2[Index] != ';'))) { - return TRUE; - } + FreePool (Lan1); + FreePool (Lan2); - return FALSE; + // + // Only return TRUE if Language2[Index] is a Null-terminator which means + // the Primary Language in Language1 is the same length as Language2. If + // Language2[Index] is not a Null-terminator, then Language2 is longer than + // the Primary Language in Language1, and FALSE must be returned. + // + return (BOOLEAN) (Language2[Index] == 0); }