]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / IfrParse.c
index c813081454965cc3809213c6acde88edc4d3995e..f640d12e3aa9c4a5fbcf496f823e3ca1062cd3d5 100644 (file)
@@ -1,5 +1,7 @@
 /** @file
-Copyright (c) 2007, Intel Corporation
+Parser for IFR binary encoding.
+
+Copyright (c) 2007 - 2008, Intel Corporation
 All rights reserved. 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
@@ -8,15 +10,6 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
-Module Name:
-
-  IfrParse.c
-
-Abstract:
-
-  Parser for IFR binary encoding.
-
-
 **/
 
 #include "Setup.h"
@@ -32,6 +25,7 @@ FORM_EXPRESSION  *mSuppressExpression;
 FORM_EXPRESSION  *mGrayOutExpression;
 
 EFI_GUID  gTianoHiiIfrGuid = EFI_IFR_TIANO_GUID;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  mFrameworkHiiCompatibilityGuid = EFI_IFR_FRAMEWORK_GUID;
 
 
 /**
@@ -95,6 +89,54 @@ CreateStatement (
   return Statement;
 }
 
+EFI_STATUS
+UpdateCheckBoxStringToken (
+  IN CONST FORM_BROWSER_FORMSET *FormSet,
+  IN       FORM_BROWSER_STATEMENT *Statement
+  )
+{
+  CHAR16                  Str[MAXIMUM_VALUE_CHARACTERS];
+  EFI_STRING_ID           Id;
+  EFI_STATUS              Status;
+
+  ASSERT (Statement != NULL);
+  ASSERT (Statement->Operand == EFI_IFR_NUMERIC_OP);
+  
+  UnicodeValueToString (Str, 0, Statement->VarStoreInfo.VarName, MAXIMUM_VALUE_CHARACTERS - 1);
+  
+  Status = HiiLibNewString (FormSet->HiiHandle, &Id, Str);
+
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Statement->VarStoreInfo.VarName = Id;
+    
+  return EFI_SUCCESS;
+}
+
+BOOLEAN
+IsNextOpCodeGuidedVarEqName (
+  UINT8 *OpCodeData
+  )
+{
+  //
+  // Get next opcode
+  //
+  OpCodeData += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
+  if (*OpCodeData == EFI_IFR_GUID_OP) {
+    if (CompareGuid (&mFrameworkHiiCompatibilityGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
+      //
+      // Specific GUIDed opcodes to support IFR generated from Framework HII VFR 
+      //
+      if ((((EFI_IFR_GUID_VAREQNAME *) OpCodeData)->ExtendOpCode) == EFI_IFR_EXTEND_OP_VAREQNAME) {
+        return TRUE;
+      }
+    }
+  }
+
+  return FALSE;
+}
 
 /**
   Initialize Question's members.
@@ -118,6 +160,7 @@ CreateQuestion (
   LIST_ENTRY               *Link;
   FORMSET_STORAGE          *Storage;
   NAME_VALUE_NODE          *NameValueNode;
+  EFI_STATUS               Status;
 
   Statement = CreateStatement (OpCodeData, FormSet, Form);
   if (Statement == NULL) {
@@ -138,6 +181,19 @@ CreateQuestion (
     return Statement;
   }
 
+  //
+  // Take a look at next OpCode to see whether it is a GUIDed opcode to support
+  // Framework Compatibility
+  //
+  if (FeaturePcdGet (PcdFrameworkHiiCompatibilitySupport)) {
+    if ((*OpCodeData == EFI_IFR_NUMERIC_OP) && IsNextOpCodeGuidedVarEqName (OpCodeData)) {
+      Status = UpdateCheckBoxStringToken (FormSet, Statement);
+      if (EFI_ERROR (Status)) {
+        return NULL;
+      }
+    }
+  }
+
   //
   // Find Storage for this Question
   //
@@ -337,7 +393,7 @@ InitializeRequestElement (
     StrLen = UnicodeSPrint (RequestElement, 30 * sizeof (CHAR16), L"&%s", Question->VariableName);
   }
 
-  if ((Question->Operand == EFI_IFR_PASSWORD_OP) && (Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK)) {
+  if ((Question->Operand == EFI_IFR_PASSWORD_OP) && ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK)) {
     //
     // Password with CALLBACK flag is stored in encoded format,
     // so don't need to append it to <ConfigRequest>
@@ -371,12 +427,10 @@ InitializeRequestElement (
 
 
 /**
-  Free resources of a Expression
+  Free resources of a Expression.
 
   @param  FormSet                Pointer of the Expression
 
-  @return None.
-
 **/
 VOID
 DestroyExpression (
@@ -391,7 +445,9 @@ DestroyExpression (
     OpCode = EXPRESSION_OPCODE_FROM_LINK (Link);
     RemoveEntryList (&OpCode->Link);
 
-    SafeFreePool (OpCode->ValueList);
+    if (OpCode->ValueList != NULL) {
+      FreePool (OpCode->ValueList);
+    }
   }
 
   //
@@ -402,12 +458,10 @@ DestroyExpression (
 
 
 /**
-  Free resources of a storage
+  Free resources of a storage.
 
   @param  Storage                Pointer of the storage
 
-  @return None.
-
 **/
 VOID
 DestroyStorage (
@@ -421,35 +475,49 @@ DestroyStorage (
     return;
   }
 
-  SafeFreePool (Storage->Name);
-  SafeFreePool (Storage->Buffer);
-  SafeFreePool (Storage->EditBuffer);
+  if (Storage->Name != NULL) {
+    FreePool (Storage->Name);
+  }
+  if (Storage->Buffer != NULL) {
+    FreePool (Storage->Buffer);
+  }
+  if (Storage->EditBuffer != NULL) {
+    FreePool (Storage->EditBuffer);
+  }
 
   while (!IsListEmpty (&Storage->NameValueListHead)) {
     Link = GetFirstNode (&Storage->NameValueListHead);
     NameValueNode = NAME_VALUE_NODE_FROM_LINK (Link);
     RemoveEntryList (&NameValueNode->Link);
 
-    SafeFreePool (NameValueNode->Name);
-    SafeFreePool (NameValueNode->Value);
-    SafeFreePool (NameValueNode->EditValue);
-    SafeFreePool (NameValueNode);
+    if (NameValueNode->Name != NULL) {
+      FreePool (NameValueNode->Name);
+    }
+    if (NameValueNode->Value != NULL) {
+      FreePool (NameValueNode->Value);
+    }
+    if (NameValueNode->EditValue != NULL) {
+      FreePool (NameValueNode->EditValue);
+    }
+    FreePool (NameValueNode);
   }
 
-  SafeFreePool (Storage->ConfigHdr);
-  SafeFreePool (Storage->ConfigRequest);
+  if (Storage->ConfigHdr != NULL) {
+    FreePool (Storage->ConfigHdr);
+  }
+  if (Storage->ConfigRequest != NULL) {
+    FreePool (Storage->ConfigRequest);
+  }
 
-  gBS->FreePool (Storage);
+  FreePool (Storage);
 }
 
 
 /**
-  Free resources of a Statement
+  Free resources of a Statement.
 
   @param  Statement              Pointer of the Statement
 
-  @return None.
-
 **/
 VOID
 DestroyStatement (
@@ -505,17 +573,19 @@ DestroyStatement (
     DestroyExpression (Expression);
   }
 
-  SafeFreePool (Statement->VariableName);
-  SafeFreePool (Statement->BlockName);
+  if (Statement->VariableName != NULL) {
+    FreePool (Statement->VariableName);
+  }
+  if (Statement->BlockName != NULL) {
+    FreePool (Statement->BlockName);
+  }
 }
 
 
 /**
-  Free resources of a Form
-
-  @param  Form                   Pointer of the Form
+  Free resources of a Form.
 
-  @return None.
+  @param  Form                   Pointer of the Form.
 
 **/
 VOID
@@ -557,12 +627,10 @@ DestroyForm (
 
 
 /**
-  Free resources allocated for a FormSet
+  Free resources allocated for a FormSet.
 
   @param  FormSet                Pointer of the FormSet
 
-  @return None.
-
 **/
 VOID
 DestroyFormSet (
@@ -577,7 +645,7 @@ DestroyFormSet (
   //
   // Free IFR binary buffer
   //
-  SafeFreePool (FormSet->IfrBinaryData);
+  FreePool (FormSet->IfrBinaryData);
 
   //
   // Free FormSet Storage
@@ -618,10 +686,14 @@ DestroyFormSet (
     }
   }
 
-  SafeFreePool (FormSet->StatementBuffer);
-  SafeFreePool (FormSet->ExpressionBuffer);
+  if (FormSet->StatementBuffer != NULL) {
+    FreePool (FormSet->StatementBuffer);
+  }
+  if (FormSet->ExpressionBuffer != NULL) {
+    FreePool (FormSet->ExpressionBuffer);
+  }
 
-  SafeFreePool (FormSet);
+  FreePool (FormSet);
 }
 
 
@@ -641,7 +713,10 @@ IsExpressionOpCode (
 {
   if (((Operand >= EFI_IFR_EQ_ID_VAL_OP) && (Operand <= EFI_IFR_NOT_OP)) ||
       ((Operand >= EFI_IFR_MATCH_OP) && (Operand <= EFI_IFR_SPAN_OP)) ||
-      (Operand == EFI_IFR_CATENATE_OP)
+      (Operand == EFI_IFR_CATENATE_OP) ||
+      (Operand == EFI_IFR_TO_LOWER_OP) ||
+      (Operand == EFI_IFR_TO_UPPER_OP) ||
+      (Operand == EFI_IFR_VERSION_OP)
      ) {
     return TRUE;
   } else {
@@ -657,8 +732,6 @@ IsExpressionOpCode (
   @param  NumberOfStatement      Number of Statemens(Questions)
   @param  NumberOfExpression     Number of Expression OpCodes
 
-  @return None.
-
 **/
 VOID
 CountOpCodes (
@@ -694,6 +767,7 @@ CountOpCodes (
 }
 
 
+
 /**
   Parse opcodes in the formset IFR binary.
 
@@ -791,7 +865,7 @@ ParseOpCodes (
     //
     // If scope bit set, push onto scope stack
     //
-    if (Scope) {
+    if (Scope != 0) {
       PushScope (Operand);
     }
 
@@ -1091,7 +1165,7 @@ ParseOpCodes (
       CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);
       CurrentStatement->Flags = ((EFI_IFR_SUBTITLE *) OpCodeData)->Flags;
 
-      if (Scope) {
+      if (Scope != 0) {
         mInScopeSubtitle = TRUE;
       }
       break;
@@ -1187,7 +1261,7 @@ ParseOpCodes (
 
       InitializeRequestElement (FormSet, CurrentStatement);
 
-      if ((Operand == EFI_IFR_ONE_OF_OP) && Scope) {
+      if ((Operand == EFI_IFR_ONE_OF_OP) && Scope != 0) {
         SuppressForOption = TRUE;
       }
       break;
@@ -1208,7 +1282,7 @@ ParseOpCodes (
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_OTHER;
       CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);
 
-      if (Scope) {
+      if (Scope != 0) {
         SuppressForOption = TRUE;
       }
       break;
@@ -1221,6 +1295,7 @@ ParseOpCodes (
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_BOOLEAN;
 
       InitializeRequestElement (FormSet, CurrentStatement);
+
       break;
 
     case EFI_IFR_STRING_OP:
@@ -1233,11 +1308,11 @@ ParseOpCodes (
       //
       CurrentStatement->Minimum = ((EFI_IFR_STRING *) OpCodeData)->MinSize;
       CurrentStatement->Maximum = ((EFI_IFR_STRING *) OpCodeData)->MaxSize;
-      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16));
+      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (CHAR16));
       CurrentStatement->Flags = ((EFI_IFR_STRING *) OpCodeData)->Flags;
 
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
-      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);
+      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth + sizeof (CHAR16));
 
       InitializeRequestElement (FormSet, CurrentStatement);
       break;
@@ -1252,10 +1327,10 @@ ParseOpCodes (
       //
       CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_PASSWORD *) OpCodeData)->MinSize, sizeof (UINT16));
       CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_PASSWORD *) OpCodeData)->MaxSize, sizeof (UINT16));
-      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16));
+      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (CHAR16));
 
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
-      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);
+      CurrentStatement->BufferValue = AllocateZeroPool ((CurrentStatement->StorageWidth + sizeof (CHAR16)));
 
       InitializeRequestElement (FormSet, CurrentStatement);
       break;
@@ -1320,7 +1395,7 @@ ParseOpCodes (
       //
       InsertTailList (&CurrentStatement->DefaultListHead, &CurrentDefault->Link);
 
-      if (Scope) {
+      if (Scope != 0) {
         InScopeDefault = TRUE;
       }
       break;
@@ -1528,6 +1603,7 @@ ParseOpCodes (
           break;
         }
       }
+
       break;
 
     //