From 59aefb7e0dc811a3e66ae23c1730028365354361 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Thu, 4 Mar 2010 06:48:52 +0000 Subject: Update HiiConfigAccess.ExtractConfig interface to support NULL request string and ConfigHdr request string. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10180 6f19259b-4bc3-4df7-8a09-765794883524 --- .../FrameworkHiiOnUefiHiiThunk/ConfigAccess.c | 229 ++++++++++++++++----- 1 file changed, 177 insertions(+), 52 deletions(-) (limited to 'EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c') diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c index c49ffe66c6..cdf4b09e15 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c @@ -147,6 +147,10 @@ GetStorageFromConfigString ( FORMSET_STORAGE *Storage; CHAR16 *Name; + if (ConfigString == NULL) { + return NULL; + } + StorageList = GetFirstNode (&FormSet->StorageListHead); while (!IsNull (&FormSet->StorageListHead, StorageList)) { @@ -165,7 +169,7 @@ GetStorageFromConfigString ( StorageList = GetNextNode (&FormSet->StorageListHead, StorageList); } - return NULL; + return NULL; } /** @@ -419,73 +423,194 @@ ThunkExtractConfig ( OUT EFI_STRING *Results ) { - EFI_STATUS Status; - CONFIG_ACCESS_PRIVATE *ConfigAccess; - FORMSET_STORAGE *BufferStorage; - VOID *Data; - UINTN DataSize; - - if (Request == NULL) { + EFI_STATUS Status; + CONFIG_ACCESS_PRIVATE *ConfigAccess; + FORMSET_STORAGE *BufferStorage; + VOID *Data; + UINTN DataSize; + FORM_BROWSER_FORMSET *FormSetContext; + CHAR16 *VarStoreName; + EFI_STRING ConfigRequestHdr; + EFI_STRING ConfigRequest; + UINTN Size; + BOOLEAN AllocatedRequest; + LIST_ENTRY *StorageList; + EFI_STRING SingleResult; + EFI_STRING FinalResults; + EFI_STRING StrPointer; + + if (Progress == NULL || Results == NULL) { + return EFI_INVALID_PARAMETER; + } + *Progress = Request; + + Status = EFI_SUCCESS; + Data = NULL; + StrPointer = NULL; + SingleResult = NULL; + FinalResults = NULL; + ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This); + FormSetContext = ConfigAccess->ThunkContext->FormSet; + if (IsListEmpty (&FormSetContext->StorageListHead)) { + // + // No VarStorage does exist in this form. + // return EFI_NOT_FOUND; } + StorageList = GetFirstNode (&FormSetContext->StorageListHead); - Data = NULL; - ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This); + do { + if (Request != NULL) { + BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Request); + if (BufferStorage == NULL) { + return EFI_NOT_FOUND; + } + } else { + if (IsNull (&FormSetContext->StorageListHead, StorageList)) { + // + // No Storage to be extracted into the results. + // + break; + } + BufferStorage = FORMSET_STORAGE_FROM_LINK (StorageList); + StorageList = GetNextNode (&FormSetContext->StorageListHead, StorageList); + } + + VarStoreName = NULL; + ConfigRequestHdr = NULL; + ConfigRequest = NULL; + Size = 0; + AllocatedRequest = FALSE; - BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Request); + if (ConfigAccess->ThunkContext->NvMapOverride == NULL) { + // + // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback. + // + if (ConfigAccess->FormCallbackProtocol == NULL || + ConfigAccess->FormCallbackProtocol->NvRead == NULL) { + Status = GetUefiVariable ( + BufferStorage, + &Data, + &DataSize + ); + } else { + Status = CallFormCallBack ( + BufferStorage, + ConfigAccess->FormCallbackProtocol, + &Data, + &DataSize + ); + } + } else { + // + // Use the NvMapOverride. + // + DataSize = BufferStorage->Size; + Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride); + + if (Data != NULL) { + Status = EFI_SUCCESS; + } else { + Status = EFI_OUT_OF_RESOURCES; + } + } + + if (!EFI_ERROR (Status)) { + ConfigRequest = Request; + if (Request == NULL || (StrStr (Request, L"OFFSET") == NULL)) { + // + // Request is without any request element, construct full request string. + // - if (BufferStorage == NULL) { - *Progress = (EFI_STRING) Request; - return EFI_NOT_FOUND; - } + if ((BufferStorage->VarStoreId == FormSetContext->DefaultVarStoreId) && (FormSetContext->OriginalDefaultVarStoreName != NULL)) { + VarStoreName = FormSetContext->OriginalDefaultVarStoreName; + } else { + VarStoreName = BufferStorage->Name; + } - if (ConfigAccess->ThunkContext->NvMapOverride == NULL) { + // + // First Set ConfigRequestHdr string. + // + ConfigRequestHdr = HiiConstructConfigHdr (&BufferStorage->Guid, VarStoreName, ConfigAccess->ThunkContext->UefiHiiDriverHandle); + ASSERT (ConfigRequestHdr != NULL); + + // + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator + // + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); + ASSERT (ConfigRequest != NULL); + AllocatedRequest = TRUE; + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)DataSize); + FreePool (ConfigRequestHdr); + } + Status = mHiiConfigRoutingProtocol->BlockToConfig ( + mHiiConfigRoutingProtocol, + ConfigRequest, + Data, + DataSize, + &SingleResult, + Progress + ); + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest = NULL; + } + } // - // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback. + // Free the allocated Data // - if (ConfigAccess->FormCallbackProtocol == NULL || - ConfigAccess->FormCallbackProtocol->NvRead == NULL) { - Status = GetUefiVariable ( - BufferStorage, - &Data, - &DataSize - ); - } else { - Status = CallFormCallBack ( - BufferStorage, - ConfigAccess->FormCallbackProtocol, - &Data, - &DataSize - ); + if (Data != NULL) { + FreePool (Data); } - } else { // - // Use the NvMapOverride. + // Directly return when meet with error // - DataSize = BufferStorage->Size; - Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride); - - if (Data != NULL) { - Status = EFI_SUCCESS; + if (EFI_ERROR (Status)) { + break; + } + // + // Merge result into the final results. + // + if (FinalResults == NULL) { + FinalResults = SingleResult; + SingleResult = NULL; } else { - Status = EFI_OUT_OF_RESOURCES; + Size = StrLen (FinalResults); + Size = Size + 1; + Size = Size + StrLen (SingleResult) + 1; + StrPointer = AllocateZeroPool (Size * sizeof (CHAR16)); + ASSERT (StrPointer != NULL); + StrCpy (StrPointer, FinalResults); + FreePool (FinalResults); + FinalResults = StrPointer; + StrPointer = StrPointer + StrLen (StrPointer); + *StrPointer = L'&'; + StrCpy (StrPointer + 1, SingleResult); + FreePool (SingleResult); } - } - + } while (Request == NULL); + if (!EFI_ERROR (Status)) { - Status = mHiiConfigRoutingProtocol->BlockToConfig ( - mHiiConfigRoutingProtocol, - Request, - Data, - DataSize, - Results, - Progress - ); + *Results = FinalResults; + } else { + if (FinalResults != NULL) { + FreePool (FinalResults); + } } - - if (Data != NULL) { - FreePool (Data); + // + // Set Progress string to the original request string. + // + if (Request == NULL) { + *Progress = NULL; + } else if (StrStr (Request, L"OFFSET") == NULL) { + *Progress = Request + StrLen (Request); } + return Status; } -- cgit v1.2.3