NetworkPkg: Update HttpDxe driver to consume EFI_HTTP_UTILITIES_PROTOCOL

v2:
* Register a notification function to be executed for Http utilities protocol
in the drivers entry points.

Since we add EFI_HTTP_UTILITIES_PROTOCOL support, HttpDxe driver should
be updated to remove internal http utilities functions and consume this
protocol directly.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Samer El-Haj-Mahmoud <elhaj@hp.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18316 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jiaxin Wu 2015-08-26 06:19:53 +00:00 committed by jiaxinwu
parent d36e65a045
commit 5ca29abe52
7 changed files with 94 additions and 721 deletions

View File

@ -15,6 +15,8 @@
#include "HttpDriver.h"
EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
///
/// Driver Binding Protocol instance
///
@ -100,6 +102,35 @@ HttpCleanService (
}
}
/**
The event process routine when the http utilities protocol is installed
in the system.
@param[in] Event Not used.
@param[in] Context The pointer to the IP4 config2 instance data.
**/
VOID
EFIAPI
HttpUtilitiesInstalledCallback (
IN EFI_EVENT Event,
IN VOID *Context
)
{
gBS->LocateProtocol (
&gEfiHttpUtilitiesProtocolGuid,
NULL,
(VOID **) &mHttpUtilities
);
//
// Close the event if Http utilities protocol is loacted.
//
if (mHttpUtilities != NULL && Event != NULL) {
gBS->CloseEvent (Event);
}
}
/**
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
@ -119,6 +150,27 @@ HttpDxeDriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
VOID *Registration;
gBS->LocateProtocol (
&gEfiHttpUtilitiesProtocolGuid,
NULL,
(VOID **) &mHttpUtilities
);
if (mHttpUtilities == NULL) {
//
// No Http utilities protocol, register a notify.
//
EfiCreateProtocolNotifyEvent (
&gEfiHttpUtilitiesProtocolGuid,
TPL_CALLBACK,
HttpUtilitiesInstalledCallback,
NULL,
&Registration
);
}
//
// Install UEFI Driver Model protocol(s).
//

View File

@ -41,6 +41,7 @@
//
// Consumed Protocols
//
#include <Protocol/HttpUtilities.h>
#include <Protocol/Tcp4.h>
#include <Protocol/Dns4.h>
#include <Protocol/Ip4Config2.h>
@ -62,6 +63,8 @@ extern EFI_DRIVER_BINDING_PROTOCOL gHttpDxeDriverBinding;
extern EFI_COMPONENT_NAME2_PROTOCOL gHttpDxeComponentName2;
extern EFI_COMPONENT_NAME_PROTOCOL gHttpDxeComponentName;
extern EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities;
//
// Include files with function prototypes
//
@ -69,7 +72,6 @@ extern EFI_COMPONENT_NAME_PROTOCOL gHttpDxeComponentName;
#include "HttpImpl.h"
#include "HttpProto.h"
#include "HttpDns.h"
#include "HttpUtilities.h"
typedef struct {
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;

View File

@ -38,8 +38,6 @@
HttpImpl.c
HttpProto.h
HttpProto.c
HttpUtilities.h
HttpUtilities.c
[LibraryClasses]
UefiDriverEntryPoint
@ -54,6 +52,7 @@
[Protocols]
gEfiHttpServiceBindingProtocolGuid ## BY_START
gEfiHttpProtocolGuid ## BY_START
gEfiHttpUtilitiesProtocolGuid ## CONSUMES
gEfiTcp4ServiceBindingProtocolGuid ## TO_START
gEfiTcp4ProtocolGuid ## TO_START
gEfiDns4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES

View File

@ -757,7 +757,8 @@ HttpBodyParserCallback (
@retval EFI_SUCCESS Allocation succeeded.
@retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
@retval EFI_NOT_READY Can't find a corresponding TxToken.
@retval EFI_NOT_READY Can't find a corresponding TxToken or
the EFI_HTTP_UTILITIES_PROTOCOL is not available.
**/
EFI_STATUS
@ -953,10 +954,25 @@ HttpResponseWorker (
CopyMem (HeaderTmp, Tmp, SizeofHeaders);
FreePool (HttpHeaders);
HttpHeaders = HeaderTmp;
//
// Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
//
if (mHttpUtilities == NULL) {
Status = EFI_NOT_READY;
goto Error;
}
//
// Parse the HTTP header into array of key/value pairs.
//
Status = HttpUtilitiesParse (HttpHeaders, SizeofHeaders, &HttpMsg->Headers, &HttpMsg->HeaderCount);
Status = mHttpUtilities->Parse (
mHttpUtilities,
HttpHeaders,
SizeofHeaders,
&HttpMsg->Headers,
&HttpMsg->HeaderCount
);
if (EFI_ERROR (Status)) {
goto Error;
}

View File

@ -1071,10 +1071,18 @@ HttpGenRequestString (
AppendList[Index] = &Message->Headers[Index];
}
//
// Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
//
if (mHttpUtilities == NULL) {
return NULL;
}
//
// Build raw unformatted HTTP headers.
//
Status = HttpUtilitiesBuild (
Status = mHttpUtilities->Build (
mHttpUtilities,
0,
NULL,
0,

View File

@ -1,622 +0,0 @@
/** @file
Implementation of help functions to parse HTTP message header.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
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 "HttpDriver.h"
/**
Get the next string, which is distinguished by specified seperator.
@param[in] String Pointer to the string.
@param[in] Seperator Specified seperator used to distinguish where is the beginning
of next string.
@return Pointer to the next string.
@return NULL if not find or String is NULL.
**/
CHAR8 *
AsciiStrGetNextToken (
IN CONST CHAR8 *String,
IN CHAR8 Seperator
)
{
CONST CHAR8 *Token;
Token = String;
while (TRUE) {
if (*Token == 0) {
return NULL;
}
if (*Token == Seperator) {
return (CHAR8 *) (Token + 1);
}
Token++;
}
}
/**
Free existing HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
@param[in] FieldCount The number of header pairs in HeaderFields.
**/
VOID
FreeHeaderFields (
IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount
)
{
UINTN Index;
if (HeaderFields != NULL) {
for (Index = 0; Index < FieldCount; Index++) {
if(HeaderFields[Index].FieldName != NULL) {
FreePool (HeaderFields[Index].FieldName);
}
if(HeaderFields[Index].FieldValue != NULL) {
FreePool (HeaderFields[Index].FieldValue);
}
}
FreePool (HeaderFields);
}
}
/**
Find required header field in HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs.
@param[in] FieldCount The number of header pairs.
@param[in] FieldName Pointer to header field's name.
@return Pointer to the queried header field.
@return NULL if not find this required header field.
**/
EFI_HTTP_HEADER *
FindHttpHeader (
IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount,
IN CHAR8 *FieldName
)
{
UINTN Index;
for (Index = 0; Index < FieldCount; Index++) {
if (AsciiStrCmp (FieldName, HeaderFields[Index].FieldName) == 0) {
//
// Find the required header field.
//
return &HeaderFields[Index];
}
}
return NULL;
}
/**
Check whether header field called FieldName is in DeleteList.
@param[in] DeleteList Pointer to array of key/value header pairs.
@param[in] DeleteCount The number of header pairs.
@param[in] FieldName Pointer to header field's name.
@return TRUE if FieldName is not in DeleteList, that means this header field is valid.
@return FALSE if FieldName is in DeleteList, that means this header field is invalid.
**/
BOOLEAN
IsValidHttpHeader (
IN CHAR8 *DeleteList[],
IN UINTN DeleteCount,
IN CHAR8 *FieldName
)
{
UINTN Index;
for (Index = 0; Index < DeleteCount; Index++) {
if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {
return FALSE;
}
}
return TRUE;
}
/**
Set FieldName and FieldValue into specified HttpHeader.
@param[in] HttpHeader Specified HttpHeader.
@param[in] FieldName FieldName of this HttpHeader.
@param[in] FieldValue FieldValue of this HttpHeader.
@retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
**/
EFI_STATUS
SetFieldNameAndValue (
IN EFI_HTTP_HEADER *HttpHeader,
IN CHAR8 *FieldName,
IN CHAR8 *FieldValue
)
{
UINTN FieldNameSize;
UINTN FieldValueSize;
if (HttpHeader->FieldName != NULL) {
FreePool (HttpHeader->FieldName);
}
if (HttpHeader->FieldValue != NULL) {
FreePool (HttpHeader->FieldValue);
}
FieldNameSize = AsciiStrSize (FieldName);
HttpHeader->FieldName = AllocateZeroPool (FieldNameSize);
if (HttpHeader->FieldName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyMem (HttpHeader->FieldName, FieldName, FieldNameSize);
HttpHeader->FieldName[FieldNameSize - 1] = 0;
FieldValueSize = AsciiStrSize (FieldValue);
HttpHeader->FieldValue = AllocateZeroPool (FieldValueSize);
if (HttpHeader->FieldValue == NULL) {
FreePool (HttpHeader->FieldName);
return EFI_OUT_OF_RESOURCES;
}
CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize);
HttpHeader->FieldValue[FieldValueSize - 1] = 0;
return EFI_SUCCESS;
}
/**
Get one key/value header pair from the raw string.
@param[in] String Pointer to the raw string.
@param[out] FieldName Pointer to header field's name.
@param[out] FieldValue Pointer to header field's value.
@return Pointer to the next raw string.
@return NULL if no key/value header pair from this raw string.
**/
CHAR8 *
GetFieldNameAndValue (
IN CHAR8 *String,
OUT CHAR8 **FieldName,
OUT CHAR8 **FieldValue
)
{
CHAR8 *FieldNameStr;
CHAR8 *FieldValueStr;
CHAR8 *StrPtr;
if (String == NULL || FieldName == NULL || FieldValue == NULL) {
return NULL;
}
*FieldName = NULL;
*FieldValue = NULL;
FieldNameStr = NULL;
FieldValueStr = NULL;
StrPtr = NULL;
//
// Each header field consists of a name followed by a colon (":") and the field value.
//
FieldNameStr = String;
FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':');
if (FieldValueStr == NULL) {
return NULL;
}
*(FieldValueStr - 1) = 0; /// Replace ':' with 0
//
// The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
//
while (TRUE) {
if(*FieldValueStr == ' ' || *FieldValueStr == '\t') {
FieldValueStr ++;
} else if (*FieldValueStr == '\r' && *(FieldValueStr + 1) == '\n' &&
(*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) {
FieldValueStr = FieldValueStr + 3;
} else {
break;
}
}
//
// Header fields can be extended over multiple lines by preceding each extra
// line with at least one SP or HT.
//
StrPtr = FieldValueStr;
do {
StrPtr = AsciiStrGetNextToken (StrPtr, '\r');
if (StrPtr == NULL || *StrPtr != '\n') {
return NULL;
}
StrPtr++;
} while (*StrPtr == ' ' || *StrPtr == '\t');
//
// Replace '\r' with 0.
//
*(StrPtr - 2) = 0;
//
// Get FieldName and FieldValue.
//
*FieldName = FieldNameStr;
*FieldValue = FieldValueStr;
return StrPtr;
}
/**
This 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] SeedMessageSize Size in bytes of the initial HTTP header. This can be zero.
@param[in] SeedMessage Initial raw unformatted HTTP header to be used as a base for
building a new unformatted HTTP header. If NULL, SeedMessageSize
is ignored. The buffer containing this message will be allocated
and released by the caller.
@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. If NULL, DeleteCount is ignored. The buffer containing the
list will be allocated and released by the caller.
@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 the size in bytes of the new unformatted HTTP header in NewMessage.
@param[out] NewMessage Pointer to a new unformatted HTTP header. The storage for this NewMessage is
allocated by the driver publishing this protocol, and must be freed by the caller.
@retval EFI_SUCCESS Add, remove, and replace operations succeeded.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage.
**/
EFI_STATUS
HttpUtilitiesBuild(
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 (SeedMessage != NULL) {
Status = HttpUtilitiesParse (
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 (IsValidHttpHeader(DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) {
Status = SetFieldNameAndValue(
&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 = SetFieldNameAndValue(
&NewHeaderFields[Index],
TempHeaderFields[Index].FieldName,
TempHeaderFields[Index].FieldValue
);
if (EFI_ERROR (Status)){
goto ON_EXIT;
}
}
NewFieldCount = TempFieldCount;
for (Index = 0; Index < AppendCount; Index++) {
HttpHeader = FindHttpHeader(NewHeaderFields, NewFieldCount, AppendList[Index]->FieldName);
if(HttpHeader != NULL) {
Status = SetFieldNameAndValue(
HttpHeader,
AppendList[Index]->FieldName,
AppendList[Index]->FieldValue
);
if (EFI_ERROR (Status)){
goto ON_EXIT;
}
} else {
Status = SetFieldNameAndValue
(&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(HTTP_CRLF_STR) - 1;
*NewMessageSize += StrLength;
}
StrLength = sizeof(HTTP_CRLF_STR) - 1;
*NewMessageSize += StrLength;
//
// Final 0 for end flag.
//
*NewMessageSize += 1;
*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(HTTP_CRLF_STR) - 1;
CopyMem (NewMessagePtr, HTTP_CRLF_STR, StrLength);
NewMessagePtr += StrLength;
}
StrLength = sizeof(HTTP_CRLF_STR) - 1;
CopyMem (NewMessagePtr, HTTP_CRLF_STR, StrLength);
NewMessagePtr += StrLength;
*NewMessagePtr = 0;
ASSERT (*NewMessageSize == (UINTN) NewMessagePtr - (UINTN) (*NewMessage) + 1);
//
// Free allocated buffer
//
ON_EXIT:
if(SeedHeaderFields != NULL) {
FreeHeaderFields(SeedHeaderFields, SeedFieldCount);
}
if(TempHeaderFields != NULL) {
FreeHeaderFields(TempHeaderFields, TempFieldCount);
}
if(NewHeaderFields != NULL) {
FreeHeaderFields(NewHeaderFields, NewFieldCount);
}
return Status;
}
/**
This function is used to transform data stored in HttpMessage into a list of fields
paired with their corresponding values.
@param[in] HttpMessage Contains raw unformatted HTTP header string. The buffer for this string will
be allocated and released by the caller.
@param[in] HttpMessageSize Size in bytes of raw unformatted HTTP header.
@param[out] HeaderFields Array of key/value header pairs. The storage for all header pairs is allocated
by the driver publishing this protocol, and must be freed by the caller.
@param[out] FieldCount Number of headers in HeaderFields.
@retval EFI_SUCCESS Parse HTTP header into array of key/value pairs 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:
HttpMessage is NULL.
HeaderFields is NULL.
FieldCount is NULL.
**/
EFI_STATUS
HttpUtilitiesParse(
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;
if (HttpMessage == NULL || HeaderFields == NULL || FieldCount == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = EFI_SUCCESS;
TempHttpMessage = NULL;
*FieldCount = 0;
Token = NULL;
NextToken = NULL;
FieldName = NULL;
FieldValue = NULL;
Index = 0;
TempHttpMessage = AllocateZeroPool (HttpMessageSize);
if (TempHttpMessage == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize);
//
// Get header number
//
Token = TempHttpMessage;
while (TRUE) {
FieldName = NULL;
FieldValue = NULL;
NextToken = GetFieldNameAndValue (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 = GetFieldNameAndValue (Token, &FieldName, &FieldValue);
Token = NextToken;
if (FieldName == NULL || FieldValue == NULL) {
break;
}
Status = SetFieldNameAndValue(&(*HeaderFields)[Index], FieldName, FieldValue);
if(EFI_ERROR(Status)){
*FieldCount = 0;
FreeHeaderFields (*HeaderFields, Index);
goto ON_EXIT;
}
Index++;
}
//
// Free allocated buffer
//
ON_EXIT:
if (TempHttpMessage != NULL) {
FreePool(TempHttpMessage);
}
return Status;
}

View File

@ -1,82 +0,0 @@
/** @file
The header files of HTTP helper functions for HttpDxe driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
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_H__
#define __EFI_HTTP_UTILITIES_H__
/**
This 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] SeedMessageSize Size in bytes of the initial HTTP header. This can be zero.
@param[in] SeedMessage Initial raw unformatted HTTP header to be used as a base for
building a new unformatted HTTP header. If NULL, SeedMessageSize
is ignored. The buffer containing this message will be allocated
and released by the caller.
@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. If NULL, DeleteCount is ignored. The buffer containing the
list will be allocated and released by the caller.
@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 the size in bytes of the new unformatted HTTP header in NewMessage.
@param[out] NewMessage Pointer to a new unformatted HTTP header. The storage for this NewMessage is
allocated by the driver publishing this protocol, and must be freed by the caller.
@retval EFI_SUCCESS Add, remove, and replace operations succeeded.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage.
**/
EFI_STATUS
HttpUtilitiesBuild(
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
);
/**
This function is used to transform data stored in HttpMessage into a list of fields
paired with their corresponding values.
@param[in] HttpMessage Contains raw unformatted HTTP header string. The buffer for this string will
be allocated and released by the caller.
@param[in] HttpMessageSize Size in bytes of raw unformatted HTTP header.
@param[out] HeaderFields Array of key/value header pairs. The storage for all header pairs is allocated
by the driver publishing this protocol, and must be freed by the caller.
@param[out] FieldCount Number of headers in HeaderFields.
@retval EFI_SUCCESS Parse HTTP header into array of key/value pairs 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:
HttpMessage is NULL.
HeaderFields is NULL.
FieldCount is NULL.
**/
EFI_STATUS
HttpUtilitiesParse(
IN CHAR8 *HttpMessage,
IN UINTN HttpMessageSize,
OUT EFI_HTTP_HEADER **HeaderFields,
OUT UINTN *FieldCount
);
#endif