From 098f8621634f1cbdd1253c9957eed09a505223f5 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Thu, 27 Apr 2017 11:16:34 +0800 Subject: NetWorkPkg: Move to new location Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- .../NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c | 126 +++++++ .../NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h | 122 +++++++ .../HttpUtilitiesDxe/HttpUtilitiesDxe.inf | 53 +++ .../HttpUtilitiesDxe/HttpUtilitiesDxe.uni | 23 ++ .../HttpUtilitiesDxe/HttpUtilitiesDxeExtra.uni | 20 ++ .../HttpUtilitiesDxe/HttpUtilitiesProtocol.c | 387 +++++++++++++++++++++ 6 files changed, 731 insertions(+) create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.uni create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxeExtra.uni create mode 100644 Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c (limited to 'Core/NetworkPkg/HttpUtilitiesDxe') diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c new file mode 100644 index 0000000000..8c54874b9f --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c @@ -0,0 +1,126 @@ +/** @file + The DriverEntryPoint and Unload for HttpUtilities driver. + + Copyright (c) 2015, 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 + 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. + +**/ + +#include "HttpUtilitiesDxe.h" + + +/** + Unloads an image. + + @param ImageHandle Handle that identifies the image to be unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesDxeUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + UINTN HandleNum; + EFI_HANDLE *HandleBuffer; + UINT32 Index; + EFI_HTTP_UTILITIES_PROTOCOL *HttpUtilitiesProtocol; + + + HandleBuffer = NULL; + + // + // Locate all the handles with HttpUtilities protocol. + // + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiHttpUtilitiesProtocolGuid, + NULL, + &HandleNum, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index = 0; Index < HandleNum; Index++) { + // + // Firstly, find HttpUtilitiesProtocol interface + // + Status = gBS->OpenProtocol ( + HandleBuffer[Index], + &gEfiHttpUtilitiesProtocolGuid, + (VOID **) &HttpUtilitiesProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Then, uninstall HttpUtilities interface + // + Status = gBS->UninstallMultipleProtocolInterfaces ( + HandleBuffer[Index], + &gEfiHttpUtilitiesProtocolGuid, HttpUtilitiesProtocol, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + + return EFI_SUCCESS; +} + + +/** + This is the declaration of an EFI image entry point. This entry point is + the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including + both device drivers and bus drivers. + + @param ImageHandle The firmware allocated handle for the UEFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesDxeDriverEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + EFI_HANDLE Handle; + + Handle = NULL; + + // + // Install the HttpUtilities Protocol onto Handle + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiHttpUtilitiesProtocolGuid, + &mHttpUtilitiesProtocol, + NULL + ); + + return Status; +} + diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h new file mode 100644 index 0000000000..7f719558a2 --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h @@ -0,0 +1,122 @@ +/** @file + The header files of Http Utilities functions for HttpUtilities driver. + + Copyright (c) 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. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __EFI_HTTP_UTILITIES_DXE_H__ +#define __EFI_HTTP_UTILITIES_DXE_H__ + +#include + +// +// Libraries +// +#include +#include +#include +#include +#include +#include +#include + +// +// Consumed Protocols +// +#include +#include + +// +// Protocol instances +// +extern EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol; + +/** + Create HTTP header based on a combination of seed header, fields + to delete, and fields to append. + + The Build() function is used to manage the headers portion of an + HTTP message by providing the ability to add, remove, or replace + HTTP headers. + + @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. + @param[in] SeedMessageSize Size of the initial HTTP header. This can be zero. + @param[in] SeedMessage Initial HTTP header to be used as a base for + building a new HTTP header. If NULL, + SeedMessageSize is ignored. + @param[in] DeleteCount Number of null-terminated HTTP header field names + in DeleteList. + @param[in] DeleteList List of null-terminated HTTP header field names to + remove from SeedMessage. Only the field names are + in this list because the field values are irrelevant + to this operation. + @param[in] AppendCount Number of header fields in AppendList. + @param[in] AppendList List of HTTP headers to populate NewMessage with. + If SeedMessage is not NULL, AppendList will be + appended to the existing list from SeedMessage in + NewMessage. + @param[out] NewMessageSize Pointer to number of header fields in NewMessage. + @param[out] NewMessage Pointer to a new list of HTTP headers based on. + + @retval EFI_SUCCESS Add, remove, and replace operations succeeded. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + This is NULL. +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesBuild ( + IN EFI_HTTP_UTILITIES_PROTOCOL *This, + IN UINTN SeedMessageSize, + IN VOID *SeedMessage, OPTIONAL + IN UINTN DeleteCount, + IN CHAR8 *DeleteList[], OPTIONAL + IN UINTN AppendCount, + IN EFI_HTTP_HEADER *AppendList[], OPTIONAL + OUT UINTN *NewMessageSize, + OUT VOID **NewMessage + ); + + +/** + Parses HTTP header and produces an array of key/value pairs. + + The Parse() function is used to transform data stored in HttpHeader + into a list of fields paired with their corresponding values. + + @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. + @param[in] HttpMessage Contains raw unformatted HTTP header string. + @param[in] HttpMessageSize Size of HTTP header. + @param[out] HeaderFields Array of key/value header pairs. + @param[out] FieldCount Number of headers in HeaderFields. + + @retval EFI_SUCCESS Allocation succeeded. + @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been + initialized. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + This is NULL. + HttpMessage is NULL. + HeaderFields is NULL. + FieldCount is NULL. +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesParse ( + IN EFI_HTTP_UTILITIES_PROTOCOL *This, + IN CHAR8 *HttpMessage, + IN UINTN HttpMessageSize, + OUT EFI_HTTP_HEADER **HeaderFields, + OUT UINTN *FieldCount + ); + +#endif diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf new file mode 100644 index 0000000000..3f7551a302 --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf @@ -0,0 +1,53 @@ +## @file +# Implementation of EFI Http Utilities Protocol interfaces. +# +# Copyright (c) 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. +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = HttpUtilitiesDxe + FILE_GUID = 22ea234f-e72a-11e4-91f9-28d2447c4829 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HttpUtilitiesDxeDriverEntryPoint + UNLOAD_IMAGE = HttpUtilitiesDxeUnload + MODULE_UNI_FILE = HttpUtilitiesDxe.uni + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + HttpUtilitiesDxe.h + HttpUtilitiesDxe.c + HttpUtilitiesProtocol.c + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + MemoryAllocationLib + BaseMemoryLib + BaseLib + UefiLib + DebugLib + HttpLib + +[Protocols] + gEfiHttpUtilitiesProtocolGuid ## PRODUCES + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + HttpUtilitiesDxeExtra.uni diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.uni b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.uni new file mode 100644 index 0000000000..0efdcd5429 --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.uni @@ -0,0 +1,23 @@ +// /** @file +// This module produces Http Utilities Protocol. +// +// This module produces Http Utilities Protocol. +// +// +// Copyright (c) 2015, 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 +// 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. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Produces Http Utilities Protocol" + +#string STR_MODULE_DESCRIPTION #language en-US "This module provides Http Utilities Protocol." + diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxeExtra.uni b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxeExtra.uni new file mode 100644 index 0000000000..a9194be736 --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxeExtra.uni @@ -0,0 +1,20 @@ +// /** @file +// HttpUtilitiesDxe Localized Strings and Content +// +// Copyright (c) 2015, 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 +// 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. +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"UEFI HTTP UTILITIES DXE" + + diff --git a/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c new file mode 100644 index 0000000000..645fca4084 --- /dev/null +++ b/Core/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c @@ -0,0 +1,387 @@ +/** @file + Implementation of EFI_HTTP_PROTOCOL protocol interfaces. + + Copyright (c) 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 + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "HttpUtilitiesDxe.h" + +EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol = { + HttpUtilitiesBuild, + HttpUtilitiesParse +}; + + +/** + Create HTTP header based on a combination of seed header, fields + to delete, and fields to append. + + The Build() function is used to manage the headers portion of an + HTTP message by providing the ability to add, remove, or replace + HTTP headers. + + @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. + @param[in] SeedMessageSize Size of the initial HTTP header. This can be zero. + @param[in] SeedMessage Initial HTTP header to be used as a base for + building a new HTTP header. If NULL, + SeedMessageSize is ignored. + @param[in] DeleteCount Number of null-terminated HTTP header field names + in DeleteList. + @param[in] DeleteList List of null-terminated HTTP header field names to + remove from SeedMessage. Only the field names are + in this list because the field values are irrelevant + to this operation. + @param[in] AppendCount Number of header fields in AppendList. + @param[in] AppendList List of HTTP headers to populate NewMessage with. + If SeedMessage is not NULL, AppendList will be + appended to the existing list from SeedMessage in + NewMessage. + @param[out] NewMessageSize Pointer to number of header fields in NewMessage. + @param[out] NewMessage Pointer to a new list of HTTP headers based on. + + @retval EFI_SUCCESS Add, remove, and replace operations succeeded. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + This is NULL. +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesBuild ( + IN EFI_HTTP_UTILITIES_PROTOCOL *This, + IN UINTN SeedMessageSize, + IN VOID *SeedMessage, OPTIONAL + IN UINTN DeleteCount, + IN CHAR8 *DeleteList[], OPTIONAL + IN UINTN AppendCount, + IN EFI_HTTP_HEADER *AppendList[], OPTIONAL + OUT UINTN *NewMessageSize, + OUT VOID **NewMessage + ) +{ + EFI_STATUS Status; + EFI_HTTP_HEADER *SeedHeaderFields; + UINTN SeedFieldCount; + UINTN Index; + EFI_HTTP_HEADER *TempHeaderFields; + UINTN TempFieldCount; + EFI_HTTP_HEADER *NewHeaderFields; + UINTN NewFieldCount; + EFI_HTTP_HEADER *HttpHeader; + UINTN StrLength; + UINT8 *NewMessagePtr; + + SeedHeaderFields = NULL; + SeedFieldCount = 0; + TempHeaderFields = NULL; + TempFieldCount = 0; + NewHeaderFields = NULL; + NewFieldCount = 0; + + HttpHeader = NULL; + StrLength = 0; + NewMessagePtr = NULL; + *NewMessageSize = 0; + Status = EFI_SUCCESS; + + if (This == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (SeedMessage != NULL) { + Status = This->Parse ( + This, + SeedMessage, + SeedMessageSize, + &SeedHeaderFields, + &SeedFieldCount + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + } + + // + // Handle DeleteList + // + if (SeedFieldCount != 0 && DeleteCount != 0) { + TempHeaderFields = AllocateZeroPool (SeedFieldCount * sizeof(EFI_HTTP_HEADER)); + if (TempHeaderFields == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + for (Index = 0, TempFieldCount = 0; Index < SeedFieldCount; Index++) { + // + // Check whether each SeedHeaderFields member is in DeleteList + // + if (HttpIsValidHttpHeader( DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) { + Status = HttpSetFieldNameAndValue ( + &TempHeaderFields[TempFieldCount], + SeedHeaderFields[Index].FieldName, + SeedHeaderFields[Index].FieldValue + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + TempFieldCount++; + } + } + } else { + TempHeaderFields = SeedHeaderFields; + TempFieldCount = SeedFieldCount; + } + + // + // Handle AppendList + // + NewHeaderFields = AllocateZeroPool ((TempFieldCount + AppendCount) * sizeof (EFI_HTTP_HEADER)); + if (NewHeaderFields == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + for (Index = 0; Index < TempFieldCount; Index++) { + Status = HttpSetFieldNameAndValue ( + &NewHeaderFields[Index], + TempHeaderFields[Index].FieldName, + TempHeaderFields[Index].FieldValue + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + } + + NewFieldCount = TempFieldCount; + + for (Index = 0; Index < AppendCount; Index++) { + HttpHeader = HttpFindHeader (NewFieldCount, NewHeaderFields, AppendList[Index]->FieldName); + if (HttpHeader != NULL) { + Status = HttpSetFieldNameAndValue ( + HttpHeader, + AppendList[Index]->FieldName, + AppendList[Index]->FieldValue + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + } else { + Status = HttpSetFieldNameAndValue ( + &NewHeaderFields[NewFieldCount], + AppendList[Index]->FieldName, + AppendList[Index]->FieldValue + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + NewFieldCount++; + } + } + + // + // Calculate NewMessageSize, then build NewMessage + // + for (Index = 0; Index < NewFieldCount; Index++) { + HttpHeader = &NewHeaderFields[Index]; + + StrLength = AsciiStrLen (HttpHeader->FieldName); + *NewMessageSize += StrLength; + + StrLength = sizeof(": ") - 1; + *NewMessageSize += StrLength; + + StrLength = AsciiStrLen (HttpHeader->FieldValue); + *NewMessageSize += StrLength; + + StrLength = sizeof("\r\n") - 1; + *NewMessageSize += StrLength; + } + StrLength = sizeof("\r\n") - 1; + *NewMessageSize += StrLength; + + *NewMessage = AllocateZeroPool (*NewMessageSize); + if (*NewMessage == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + NewMessagePtr = (UINT8 *)(*NewMessage); + + for (Index = 0; Index < NewFieldCount; Index++) { + HttpHeader = &NewHeaderFields[Index]; + + StrLength = AsciiStrLen (HttpHeader->FieldName); + CopyMem (NewMessagePtr, HttpHeader->FieldName, StrLength); + NewMessagePtr += StrLength; + + StrLength = sizeof(": ") - 1; + CopyMem (NewMessagePtr, ": ", StrLength); + NewMessagePtr += StrLength; + + StrLength = AsciiStrLen (HttpHeader->FieldValue); + CopyMem (NewMessagePtr, HttpHeader->FieldValue, StrLength); + NewMessagePtr += StrLength; + + StrLength = sizeof("\r\n") - 1; + CopyMem (NewMessagePtr, "\r\n", StrLength); + NewMessagePtr += StrLength; + } + StrLength = sizeof("\r\n") - 1; + CopyMem (NewMessagePtr, "\r\n", StrLength); + NewMessagePtr += StrLength; + + ASSERT (*NewMessageSize == (UINTN)NewMessagePtr - (UINTN)(*NewMessage)); + + // + // Free allocated buffer + // +ON_EXIT: + if (SeedHeaderFields != NULL) { + HttpFreeHeaderFields(SeedHeaderFields, SeedFieldCount); + } + + if (TempHeaderFields != NULL) { + HttpFreeHeaderFields(TempHeaderFields, TempFieldCount); + } + + if (NewHeaderFields != NULL) { + HttpFreeHeaderFields(NewHeaderFields, NewFieldCount); + } + + return Status; +} + + +/** + Parses HTTP header and produces an array of key/value pairs. + + The Parse() function is used to transform data stored in HttpHeader + into a list of fields paired with their corresponding values. + + @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. + @param[in] HttpMessage Contains raw unformatted HTTP header string. + @param[in] HttpMessageSize Size of HTTP header. + @param[out] HeaderFields Array of key/value header pairs. + @param[out] FieldCount Number of headers in HeaderFields. + + @retval EFI_SUCCESS Allocation succeeded. + @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been + initialized. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + This is NULL. + HttpMessage is NULL. + HeaderFields is NULL. + FieldCount is NULL. +**/ +EFI_STATUS +EFIAPI +HttpUtilitiesParse ( + IN EFI_HTTP_UTILITIES_PROTOCOL *This, + IN CHAR8 *HttpMessage, + IN UINTN HttpMessageSize, + OUT EFI_HTTP_HEADER **HeaderFields, + OUT UINTN *FieldCount + ) +{ + EFI_STATUS Status; + CHAR8 *TempHttpMessage; + CHAR8 *Token; + CHAR8 *NextToken; + CHAR8 *FieldName; + CHAR8 *FieldValue; + UINTN Index; + + Status = EFI_SUCCESS; + TempHttpMessage = NULL; + Token = NULL; + NextToken = NULL; + FieldName = NULL; + FieldValue = NULL; + Index = 0; + + if (This == NULL || HttpMessage == NULL || HeaderFields == NULL || FieldCount == NULL) { + return EFI_INVALID_PARAMETER; + } + + TempHttpMessage = AllocateZeroPool (HttpMessageSize); + if (TempHttpMessage == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize); + + // + // Get header number + // + *FieldCount = 0; + Token = TempHttpMessage; + while (TRUE) { + FieldName = NULL; + FieldValue = NULL; + NextToken = HttpGetFieldNameAndValue (Token, &FieldName, &FieldValue); + Token = NextToken; + if (FieldName == NULL || FieldValue == NULL) { + break; + } + + (*FieldCount)++; + } + + if (*FieldCount == 0) { + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + + // + // Allocate buffer for header + // + *HeaderFields = AllocateZeroPool ((*FieldCount) * sizeof(EFI_HTTP_HEADER)); + if (*HeaderFields == NULL) { + *FieldCount = 0; + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize); + + // + // Set Field and Value to each header + // + Token = TempHttpMessage; + while (Index < *FieldCount) { + FieldName = NULL; + FieldValue = NULL; + NextToken = HttpGetFieldNameAndValue (Token, &FieldName, &FieldValue); + Token = NextToken; + if (FieldName == NULL || FieldValue == NULL) { + break; + } + + Status = HttpSetFieldNameAndValue (&(*HeaderFields)[Index], FieldName, FieldValue); + if (EFI_ERROR (Status)) { + *FieldCount = 0; + HttpFreeHeaderFields (*HeaderFields, Index); + goto ON_EXIT; + } + + Index++; + } + + // + // Free allocated buffer + // +ON_EXIT: + if (TempHttpMessage != NULL) { + FreePool (TempHttpMessage); + } + + return Status; +} \ No newline at end of file -- cgit v1.2.3