]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Rename module name from ***To*** to ***On***. AAAOnBBB means this module produce...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
new file mode 100644 (file)
index 0000000..6e96619
--- /dev/null
@@ -0,0 +1,493 @@
+/**@file\r
+  This file implements the protocol functions related to string package.\r
+  \r
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+#include "HiiDatabase.h"\r
+\r
+typedef struct {\r
+  CHAR8 *Iso639;\r
+  CHAR8 *Rfc3066;\r
+} ISO639TORFC3066MAP;\r
+\r
+ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
+    {"eng", "en-US"},\r
+    {"fra", "fr-FR"},\r
+};\r
+\r
+CHAR8 *\r
+ConvertIso639ToRfc3066 (\r
+  CHAR8 *Iso638Lang\r
+  )\r
+{\r
+  UINTN Index;\r
+  CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
+  \r
+  AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));\r
+  for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {\r
+       if (AsciiLanguage [Index] == 0) {\r
+               break;\r
+       } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {\r
+               AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');\r
+       }\r
+  }\r
+\r
+  for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
+    if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {\r
+      return Iso639ToRfc3066Map[Index].Rfc3066;\r
+    }\r
+  }\r
+\r
+  return (CHAR8 *) NULL;\r
+}\r
+\r
+/**\r
+  Test if all of the characters in a string have corresponding font characters.\r
+\r
+  This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
+  return EFI_UNSUPPORTED.\r
+\r
+  @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param StringToTest    A pointer to a Unicode string.\r
+  @param FirstMissing    A pointer to an index into the string. On input, the index of \r
+                         the first character in the StringToTest to examine. On exit, the index \r
+                         of the first character encountered for which a glyph is unavailable. \r
+                         If all glyphs in the string are available, the index is the index of the terminator \r
+                         of the string. \r
+  @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
+                         it contains the amount of memory that is required to store the string¡¯s glyph equivalent.\r
+\r
+  @retval EFI_UNSUPPORTED  The function performs nothing and return EFI_UNSUPPORTED.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiTestString (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     CHAR16             *StringToTest,\r
+  IN OUT UINT32             *FirstMissing,\r
+  OUT    UINT32             *GlyphBufferSize\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  \r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Find the corressponding TAG GUID from a Framework HII Handle given.\r
+\r
+  @param Private      The HII Thunk Module Private context.\r
+  @param FwHiiHandle  The Framemwork HII Handle.\r
+  @param TagGuid      The output of TAG GUID found.\r
+\r
+  @return NULL        If Framework HII Handle is invalid.\r
+  @return The corresponding HII Thunk Context.\r
+**/\r
+EFI_STATUS\r
+GetTagGuidByFwHiiHandle (\r
+  IN  CONST HII_THUNK_PRIVATE_DATA      *Private,\r
+  IN        FRAMEWORK_EFI_HII_HANDLE    FwHiiHandle,\r
+  OUT       EFI_GUID                    *TagGuid\r
+  )\r
+{\r
+  LIST_ENTRY                                *Link;\r
+  HII_THUNK_CONTEXT                          *ThunkContext;\r
+\r
+  ASSERT (TagGuid != NULL);\r
+\r
+  Link = GetFirstNode (&Private->ThunkContextListHead);\r
+  while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
+\r
+    ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
+\r
+    if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
+      CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  Create or update the String given a new string and String ID.\r
+\r
+  @param ThunkContext           The Thunk Context.\r
+  @param Rfc3066AsciiLanguage   The RFC 3066 Language code in ASCII string format.\r
+  @param NewString              The new string.\r
+  @param StringId               The String ID. If StringId is 0, a new String Token\r
+                                is created. Otherwise, the String Token StringId is \r
+                                updated.\r
+                                \r
+\r
+  @retval EFI_SUCCESS           The new string is created or updated successfully. \r
+                                The new String Token ID is returned in StringId if\r
+                                *StringId is 0 on input.\r
+  @return Others                The update of string failed.                                  \r
+  \r
+**/\r
+EFI_STATUS\r
+UpdateString (\r
+  IN CONST HII_THUNK_CONTEXT        *ThunkContext,\r
+  IN CONST CHAR8                    *Rfc3066AsciiLanguage,\r
+  IN       CHAR16                   *NewString,\r
+  IN OUT STRING_REF                 *StringId\r
+  )\r
+{\r
+  EFI_STRING_ID                             NewStringId;\r
+  EFI_STATUS                                Status;\r
+\r
+\r
+  NewStringId = 0;\r
+  \r
+  if (*StringId == 0) {\r
+    //\r
+    // Create a new string token.\r
+    //\r
+    if (Rfc3066AsciiLanguage == NULL) {\r
+      //\r
+      // For all languages in the package list.\r
+      //\r
+      Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &NewStringId, NewString);\r
+    } else {\r
+      //\r
+      // For specified language.\r
+      //\r
+      Status = mHiiStringProtocol->NewString (\r
+                                     mHiiStringProtocol,\r
+                                     ThunkContext->UefiHiiHandle,\r
+                                     &NewStringId,\r
+                                     Rfc3066AsciiLanguage,\r
+                                     NULL,\r
+                                     NewString,\r
+                                     NULL\r
+                                     );\r
+    }\r
+  } else {\r
+    //\r
+    // Update the existing string token.\r
+    //\r
+    if (Rfc3066AsciiLanguage == NULL) {\r
+      //\r
+      // For all languages in the package list.\r
+      //\r
+      Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *StringId, NewString);\r
+    } else {\r
+      //\r
+      // For specified language.\r
+      //\r
+      Status = mHiiStringProtocol->SetString (\r
+                                   mHiiStringProtocol,\r
+                                   ThunkContext->UefiHiiHandle,\r
+                                   *StringId,\r
+                                   Rfc3066AsciiLanguage,\r
+                                   NewString,\r
+                                   NULL\r
+                                   );\r
+    }\r
+  }\r
+  \r
+  if (!EFI_ERROR (Status)) {\r
+    if (*StringId == 0) {\r
+      //\r
+      // When creating new string, return the newly created String Token.\r
+      //\r
+      *StringId = NewStringId;\r
+    }\r
+  } else {\r
+    //\r
+    // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
+    //\r
+    *StringId = 0;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Create or update a String Token in a String Package.\r
+\r
+  If *Reference == 0, a new String Token is created.\r
+\r
+  @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param Language        Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
+                         identifier, indicating the language to print. A string consisting of\r
+                         all spaces indicates that the string is applicable to all languages.\r
+  @param Handle          The handle of the language pack to which the string is to be added.\r
+  @param Token           The string token assigned to the string.\r
+  @param NewString       The string to be added.\r
+\r
+\r
+  @retval EFI_SUCCESS             The string was effectively registered.\r
+  @retval EFI_INVALID_PARAMETER   The Handle was unknown. The string is not created or updated in the\r
+                                  the string package.\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiNewString (\r
+  IN     EFI_HII_PROTOCOL           *This,\r
+  IN     CHAR16                     *Language,\r
+  IN     FRAMEWORK_EFI_HII_HANDLE   Handle,\r
+  IN OUT STRING_REF                 *Reference,\r
+  IN     CHAR16                     *NewString\r
+  )\r
+{\r
+  EFI_STATUS                                Status;\r
+  HII_THUNK_PRIVATE_DATA                    *Private;\r
+  EFI_GUID                                  TagGuid;\r
+  LIST_ENTRY                                *Link;\r
+  HII_THUNK_CONTEXT                          *ThunkContext;\r
+  HII_THUNK_CONTEXT                          *StringPackThunkContext;\r
+  EFI_STRING_ID                             StringId;\r
+  EFI_STRING_ID                             LastStringId;\r
+  CHAR8                                     AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
+  CHAR16                                    LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
+  CHAR8                                     *Rfc3066AsciiLanguage;\r
+\r
+  LastStringId      = (EFI_STRING_ID) 0;\r
+  StringId          = (EFI_STRING_ID) 0;\r
+  Rfc3066AsciiLanguage = NULL;\r
+\r
+  if (Language != NULL) {\r
+    ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
+    ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
+    CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
+    UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
+    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
+    ASSERT (Rfc3066AsciiLanguage != NULL);\r
+  }\r
+\r
+  Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);\r
+  if (StringPackThunkContext == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (StringPackThunkContext->SharingStringPack) {\r
+    Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Link = GetFirstNode (&Private->ThunkContextListHead);\r
+    while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
+      ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
+\r
+      if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
+        if (ThunkContext->SharingStringPack) {\r
+          StringId = *Reference;\r
+          Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+          if (EFI_ERROR (Status)) {\r
+            break;\r
+          }\r
+          \r
+          DEBUG_CODE_BEGIN ();\r
+          if (*Reference == 0) {\r
+            //\r
+            // When creating new string token, make sure all created token is the same\r
+            // for all string packages registered using FW HII interface.\r
+            //\r
+            if (LastStringId == (EFI_STRING_ID) 0) {\r
+              LastStringId = StringId;\r
+            } else {\r
+              if (LastStringId != StringId) {\r
+                ASSERT(FALSE);\r
+              }\r
+            }\r
+          }\r
+          DEBUG_CODE_END ();\r
+          \r
+        }\r
+      }\r
+\r
+      Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
+    }\r
+  } else {\r
+    StringId = *Reference;\r
+    Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    if (*Reference == 0) {\r
+      *Reference = StringId;\r
+    }\r
+  } else {\r
+    //\r
+    // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function removes any new strings that were added after the initial string export for this handle.\r
+  UEFI HII String Protocol does not have Reset String function. This function perform nothing.\r
+\r
+  @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param Handle          The HII handle on which the string resides.\r
+\r
+  @retval EFI_SUCCESS    This function is a NOP and always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiResetStrings (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     FRAMEWORK_EFI_HII_HANDLE      Handle\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ This function extracts a string from a package already registered with the EFI HII database.\r
+\r
+  @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param Handle          The HII handle on which the string resides.\r
+  @param Token           The string token assigned to the string.\r
+  @param Raw             If TRUE, the string is returned unedited in the internal storage format described\r
+                         above. If false, the string returned is edited by replacing <cr> with <space>\r
+                         and by removing special characters such as the <wide> prefix.\r
+  @param LanguageString  Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
+                         identifier, indicating the language to print. If the LanguageString is empty (starts\r
+                         with a NULL), the default system language will be used to determine the language.\r
+  @param BufferLength    Length of the StringBuffer. If the status reports that the buffer width is too\r
+                         small, this parameter is filled with the length of the buffer needed.\r
+  @param StringBuffer    The buffer designed to receive the characters in the string. Type EFI_STRING is\r
+                         defined in String.\r
+\r
+  @retval EFI_INVALID_PARAMETER If input parameter is invalid.\r
+  @retval EFI_BUFFER_TOO_SMALL  If the *BufferLength is too small.\r
+  @retval EFI_SUCCESS           Operation is successful.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetString (\r
+  IN     EFI_HII_PROTOCOL           *This,\r
+  IN     FRAMEWORK_EFI_HII_HANDLE   Handle,\r
+  IN     STRING_REF                 Token,\r
+  IN     BOOLEAN                    Raw,\r
+  IN     CHAR16                     *LanguageString,\r
+  IN OUT UINTN                      *BufferLengthTemp,\r
+  OUT    EFI_STRING                 StringBuffer\r
+  )\r
+{\r
+  CHAR8                                 *Iso639AsciiLanguage;\r
+  HII_THUNK_PRIVATE_DATA                *Private;\r
+  CHAR8                                 *Rfc3066AsciiLanguage;\r
+  EFI_HII_HANDLE                        UefiHiiHandle;\r
+  EFI_STATUS                            Status;\r
+\r
+  Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  Iso639AsciiLanguage = NULL;\r
+  Rfc3066AsciiLanguage = NULL;\r
+\r
+  if (LanguageString != NULL) {\r
+    Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
+    if (Iso639AsciiLanguage == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    UnicodeStrToAsciiStr  (LanguageString, Iso639AsciiLanguage);\r
+\r
+    //\r
+    // Caller of Framework HII Interface uses the Language Identification String defined \r
+    // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
+    //\r
+    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
+\r
+    //\r
+    // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
+    // Iso639ToRfc3066Map.\r
+    //\r
+    ASSERT (Rfc3066AsciiLanguage != NULL);\r
+    \r
+  }\r
+\r
+  UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
+  if (UefiHiiHandle == NULL) {\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
+  }\r
+\r
+  if (Rfc3066AsciiLanguage == NULL) {\r
+    Status =  HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);\r
+  } else {\r
+    Status = mHiiStringProtocol->GetString (\r
+                                 mHiiStringProtocol,\r
+                                 Rfc3066AsciiLanguage,\r
+                                 UefiHiiHandle,\r
+                                 Token,\r
+                                 StringBuffer,\r
+                                 BufferLengthTemp,\r
+                                 NULL\r
+                                 );\r
+  }\r
+\r
+Done:\r
+       if (Iso639AsciiLanguage != NULL) {\r
+    FreePool (Iso639AsciiLanguage);\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+  This function allows a program to extract a part of a string of not more than a given width.\r
+  With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
+  columns.  The effort of measuring the fit of strings inside columns is localized to this call.\r
+\r
+  This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
+  return EFI_UNSUPPORTED.\r
+\r
+  @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param Handle          The HII handle on which the string resides.\r
+  @param Token           The string token assigned to the string.\r
+  @param Raw             If TRUE, the string is returned unedited in the internal storage format described\r
+                         above. If false, the string returned is edited by replacing <cr> with <space>\r
+                         and by removing special characters such as the <wide> prefix.\r
+  @param LanguageString  Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
+                         identifier, indicating the language to print. If the LanguageString is empty (starts\r
+                         with a NULL), the default system language will be used to determine the language.\r
+  @param BufferLength    Length of the StringBuffer. If the status reports that the buffer width is too\r
+                         small, this parameter is filled with the length of the buffer needed.\r
+  @param StringBuffer    The buffer designed to receive the characters in the string. Type EFI_STRING is\r
+                         defined in String.\r
+\r
+  @retval EFI_UNSUPPORTED.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetLine (\r
+  IN     EFI_HII_PROTOCOL           *This,\r
+  IN     FRAMEWORK_EFI_HII_HANDLE   Handle,\r
+  IN     STRING_REF                 Token,\r
+  IN OUT UINT16                     *Index,\r
+  IN     UINT16                     LineWidth,\r
+  IN     CHAR16                     *LanguageString,\r
+  IN OUT UINT16                     *BufferLength,\r
+  OUT    EFI_STRING                 StringBuffer\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r