diff options
-rw-r--r-- | NetworkPkg/HttpBootDxe/HttpBootSupport.c | 43 | ||||
-rw-r--r-- | NetworkPkg/HttpDxe/HttpImpl.c | 9 | ||||
-rw-r--r-- | NetworkPkg/HttpDxe/HttpProto.c | 268 | ||||
-rw-r--r-- | NetworkPkg/HttpDxe/HttpProto.h | 33 | ||||
-rw-r--r-- | NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h | 94 | ||||
-rw-r--r-- | NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf | 3 | ||||
-rw-r--r-- | NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesImpl.c | 279 | ||||
-rw-r--r-- | NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c | 27 |
8 files changed, 35 insertions, 721 deletions
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c index f30d9f7fb0..e678379bf4 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c @@ -2,8 +2,9 @@ Support functions implementation for UEFI HTTP boot driver.
Copyright (c) 2015 - 2016, 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 that accompanies this distribution.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
@@ -548,44 +549,10 @@ HttpBootFreeHeader ( }
/**
- Find a specified header field according to the field name.
-
- @param[in] HeaderCount Number of HTTP header structures in Headers list.
- @param[in] Headers Array containing list of HTTP headers.
- @param[in] FieldName Null terminated string which describes a field name.
-
- @return Pointer to the found header or NULL.
-
-**/
-EFI_HTTP_HEADER *
-HttpBootFindHeader (
- IN UINTN HeaderCount,
- IN EFI_HTTP_HEADER *Headers,
- IN CHAR8 *FieldName
- )
-{
- UINTN Index;
-
- if (HeaderCount == 0 || Headers == NULL || FieldName == NULL) {
- return NULL;
- }
-
- for (Index = 0; Index < HeaderCount; Index++){
- //
- // Field names are case-insensitive (RFC 2616).
- //
- if (AsciiStriCmp (Headers[Index].FieldName, FieldName) == 0) {
- return &Headers[Index];
- }
- }
- return NULL;
-}
-
-/**
Set or update a HTTP header with the field name and corresponding value.
@param[in] HttpIoHeader Point to the HTTP header holder.
- @param[in] FieldName Null terminated string which describes a field name.
+ @param[in] FieldName Null terminated string which describes a field name.
@param[in] FieldValue Null terminated string which describes the corresponding field value.
@retval EFI_SUCCESS The HTTP header has been set or updated.
@@ -609,7 +576,7 @@ HttpBootSetHeader ( return EFI_INVALID_PARAMETER;
}
- Header = HttpBootFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);
+ Header = HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);
if (Header == NULL) {
//
// Add a new header.
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index a068cfb76b..63b683e7e5 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -2,7 +2,7 @@ Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+ (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -497,9 +497,10 @@ EfiHttpRequest ( goto Error3;
}
}
- RequestStr = HttpGenRequestString (HttpInstance, HttpMsg, FileUrl);
- if (RequestStr == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+
+ Status = HttpGenRequestString (HttpMsg, FileUrl, &RequestStr);
+
+ if (EFI_ERROR (Status)) {
goto Error3;
}
diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 579b9e4662..156f138f56 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1376,107 +1376,6 @@ HttpTransmitTcp ( }
/**
- Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
- in UEFI 2.5 specification.
-
- @param[in] StatusCode The status code value in HTTP message.
-
- @return Value defined in EFI_HTTP_STATUS_CODE .
-
-**/
-EFI_HTTP_STATUS_CODE
-HttpMappingToStatusCode (
- IN UINTN StatusCode
- )
-{
- switch (StatusCode) {
- case 100:
- return HTTP_STATUS_100_CONTINUE;
- case 101:
- return HTTP_STATUS_101_SWITCHING_PROTOCOLS;
- case 200:
- return HTTP_STATUS_200_OK;
- case 201:
- return HTTP_STATUS_201_CREATED;
- case 202:
- return HTTP_STATUS_202_ACCEPTED;
- case 203:
- return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION;
- case 204:
- return HTTP_STATUS_204_NO_CONTENT;
- case 205:
- return HTTP_STATUS_205_RESET_CONTENT;
- case 206:
- return HTTP_STATUS_206_PARTIAL_CONTENT;
- case 300:
- return HTTP_STATUS_300_MULTIPLE_CHIOCES;
- case 301:
- return HTTP_STATUS_301_MOVED_PERMANENTLY;
- case 302:
- return HTTP_STATUS_302_FOUND;
- case 303:
- return HTTP_STATUS_303_SEE_OTHER;
- case 304:
- return HTTP_STATUS_304_NOT_MODIFIED;
- case 305:
- return HTTP_STATUS_305_USE_PROXY;
- case 307:
- return HTTP_STATUS_307_TEMPORARY_REDIRECT;
- case 400:
- return HTTP_STATUS_400_BAD_REQUEST;
- case 401:
- return HTTP_STATUS_401_UNAUTHORIZED;
- case 402:
- return HTTP_STATUS_402_PAYMENT_REQUIRED;
- case 403:
- return HTTP_STATUS_403_FORBIDDEN;
- case 404:
- return HTTP_STATUS_404_NOT_FOUND;
- case 405:
- return HTTP_STATUS_405_METHOD_NOT_ALLOWED;
- case 406:
- return HTTP_STATUS_406_NOT_ACCEPTABLE;
- case 407:
- return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED;
- case 408:
- return HTTP_STATUS_408_REQUEST_TIME_OUT;
- case 409:
- return HTTP_STATUS_409_CONFLICT;
- case 410:
- return HTTP_STATUS_410_GONE;
- case 411:
- return HTTP_STATUS_411_LENGTH_REQUIRED;
- case 412:
- return HTTP_STATUS_412_PRECONDITION_FAILED;
- case 413:
- return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE;
- case 414:
- return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE;
- case 415:
- return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE;
- case 416:
- return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED;
- case 417:
- return HTTP_STATUS_417_EXPECTATION_FAILED;
- case 500:
- return HTTP_STATUS_500_INTERNAL_SERVER_ERROR;
- case 501:
- return HTTP_STATUS_501_NOT_IMPLEMENTED;
- case 502:
- return HTTP_STATUS_502_BAD_GATEWAY;
- case 503:
- return HTTP_STATUS_503_SERVICE_UNAVAILABLE;
- case 504:
- return HTTP_STATUS_504_GATEWAY_TIME_OUT;
- case 505:
- return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED;
-
- default:
- return HTTP_STATUS_UNSUPPORTED_STATUS;
- }
-}
-
-/**
Check whether the user's token or event has already
been enqueue on HTTP Tx or Rx Token list.
@@ -1584,14 +1483,15 @@ HttpTcpTransmit ( //
// Create request message.
//
- RequestStr = HttpGenRequestString (
- ValueInItem->HttpInstance,
+ Status = HttpGenRequestString (
ValueInItem->HttpToken->Message,
- Url
+ Url,
+ &RequestStr
);
FreePool (Url);
- if (RequestStr == NULL) {
- return EFI_OUT_OF_RESOURCES;
+
+ if (EFI_ERROR (Status)){
+ return Status;
}
//
@@ -1942,159 +1842,3 @@ HttpTcpTokenCleanup ( }
}
-
-/**
- Generate HTTP request string.
-
- @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
- @param[in] Message Pointer to storage containing HTTP message data.
- @param[in] Url The URL of a remote host.
-
- @return Pointer to the created HTTP request string.
- @return NULL if any error occured.
-
-**/
-CHAR8 *
-HttpGenRequestString (
- IN HTTP_PROTOCOL *HttpInstance,
- IN EFI_HTTP_MESSAGE *Message,
- IN CHAR8 *Url
- )
-{
- EFI_STATUS Status;
- UINTN StrLength;
- UINT8 *Request;
- UINT8 *RequestPtr;
- UINTN HttpHdrSize;
- UINTN MsgSize;
- BOOLEAN Success;
- VOID *HttpHdr;
- EFI_HTTP_HEADER **AppendList;
- UINTN Index;
-
- ASSERT (HttpInstance != NULL);
- ASSERT (Message != NULL);
-
- DEBUG ((EFI_D_ERROR, "HttpMethod - %x\n", Message->Data.Request->Method));
-
- Request = NULL;
- Success = FALSE;
- HttpHdr = NULL;
- AppendList = NULL;
-
- //
- // Build AppendList
- //
- AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * (Message->HeaderCount));
- if (AppendList == NULL) {
- return NULL;
- }
-
- for(Index = 0; Index < Message->HeaderCount; Index++){
- 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 = mHttpUtilities->Build (
- mHttpUtilities,
- 0,
- NULL,
- 0,
- NULL,
- Message->HeaderCount,
- AppendList,
- &HttpHdrSize,
- &HttpHdr
- );
- FreePool (AppendList);
- if (EFI_ERROR (Status) || HttpHdr == NULL) {
- return NULL;
- }
-
- //
- // Calculate HTTP message length.
- //
- MsgSize = Message->BodyLength + HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (Url) +
- AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
- Request = AllocateZeroPool (MsgSize);
- if (Request == NULL) {
- goto Exit;
- }
-
- RequestPtr = Request;
- //
- // Construct header request
- //
- switch (Message->Data.Request->Method) {
- case HttpMethodGet:
- StrLength = sizeof (HTTP_METHOD_GET) - 1;
- CopyMem (RequestPtr, HTTP_METHOD_GET, StrLength);
- RequestPtr += StrLength;
- break;
- case HttpMethodHead:
- StrLength = sizeof (HTTP_METHOD_HEAD) - 1;
- CopyMem (RequestPtr, HTTP_METHOD_HEAD, StrLength);
- RequestPtr += StrLength;
- break;
- default:
- ASSERT (FALSE);
- goto Exit;
- }
-
- StrLength = AsciiStrLen(" ");
- CopyMem (RequestPtr, " ", StrLength);
- RequestPtr += StrLength;
-
- StrLength = AsciiStrLen (Url);
- CopyMem (RequestPtr, Url, StrLength);
- RequestPtr += StrLength;
-
- StrLength = sizeof (HTTP_VERSION_CRLF_STR) - 1;
- CopyMem (RequestPtr, HTTP_VERSION_CRLF_STR, StrLength);
- RequestPtr += StrLength;
-
- //
- // Construct header
- //
- CopyMem (RequestPtr, HttpHdr, HttpHdrSize);
- RequestPtr += HttpHdrSize;
-
- //
- // Construct body
- //
- if (Message->Body != NULL) {
- CopyMem (RequestPtr, Message->Body, Message->BodyLength);
- RequestPtr += Message->BodyLength;
- }
-
- //
- // Done
- //
- *RequestPtr = 0;
- Success = TRUE;
-
-Exit:
-
- if (!Success) {
- if (Request != NULL) {
- FreePool (Request);
- }
-
- Request = NULL;
- }
-
- if (HttpHdr != NULL) {
- FreePool (HttpHdr);
- }
-
- return (CHAR8*) Request;
-}
diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h index 3a574949de..7b4b343b2a 100644 --- a/NetworkPkg/HttpDxe/HttpProto.h +++ b/NetworkPkg/HttpDxe/HttpProto.h @@ -2,6 +2,7 @@ The header files of miscellaneous routines for HttpDxe driver.
Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -399,20 +400,6 @@ HttpTransmitTcp ( );
/**
- Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
- in UEFI 2.5 specification.
-
- @param[in] StatusCode The status code value in HTTP message.
-
- @return Value defined in EFI_HTTP_STATUS_CODE .
-
-**/
-EFI_HTTP_STATUS_CODE
-HttpMappingToStatusCode (
- IN UINTN StatusCode
- );
-
-/**
Check whether the user's token or event has already
been enqueue on HTTP Tx or Rx Token list.
@@ -557,24 +544,6 @@ HttpTcpTokenCleanup ( );
/**
- Generate HTTP request string.
-
- @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
- @param[in] Message Pointer to storage containing HTTP message data.
- @param[in] Url The URL of a remote host.
-
- @return Pointer to the created HTTP request string.
- @return NULL if any error occured.
-
-**/
-CHAR8 *
-HttpGenRequestString (
- IN HTTP_PROTOCOL *HttpInstance,
- IN EFI_HTTP_MESSAGE *Message,
- IN CHAR8 *Url
- );
-
-/**
The work function of EfiHttpResponse().
@param[in] Wrap Pointer to HTTP token's wrap data.
diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h index 70e993546c..7f719558a2 100644 --- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h +++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h @@ -2,6 +2,7 @@ The header files of Http Utilities functions for HttpUtilities driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -27,6 +28,7 @@ #include <Library/BaseLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
+#include <Library/HttpLib.h>
//
// Consumed Protocols
@@ -39,98 +41,6 @@ //
extern EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol;
-
-/**
- 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
- );
-
-
-/**
- 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
- );
-
-
-/**
- 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
- );
-
-
-/**
- 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
- );
-
-
-/**
- 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
- );
-
-
/**
Create HTTP header based on a combination of seed header, fields
to delete, and fields to append.
diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf index ffdbcd54e5..3f7551a302 100644 --- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf +++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf @@ -2,6 +2,7 @@ # Implementation of EFI Http Utilities Protocol interfaces.
#
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -30,7 +31,6 @@ [Sources]
HttpUtilitiesDxe.h
HttpUtilitiesDxe.c
- HttpUtilitiesImpl.c
HttpUtilitiesProtocol.c
[LibraryClasses]
@@ -41,6 +41,7 @@ BaseLib
UefiLib
DebugLib
+ HttpLib
[Protocols]
gEfiHttpUtilitiesProtocolGuid ## PRODUCES
diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesImpl.c b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesImpl.c deleted file mode 100644 index adb50af393..0000000000 --- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesImpl.c +++ /dev/null @@ -1,279 +0,0 @@ -/** @file
- The functions for HttpUtilities 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.
-
-**/
-
-#include "HttpUtilitiesDxe.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) {
- 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;
- }
-
- //
- // Replace ':' with 0
- //
- *(FieldValueStr - 1) = 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;
-}
-
diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c index a83c9633fc..739d3b753c 100644 --- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c +++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c @@ -2,6 +2,7 @@ Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -122,8 +123,8 @@ HttpUtilitiesBuild ( //
// Check whether each SeedHeaderFields member is in DeleteList
//
- if (IsValidHttpHeader( DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) {
- Status = SetFieldNameAndValue (
+ if (HttpIsValidHttpHeader( DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) {
+ Status = HttpSetFieldNameAndValue (
&TempHeaderFields[TempFieldCount],
SeedHeaderFields[Index].FieldName,
SeedHeaderFields[Index].FieldValue
@@ -149,7 +150,7 @@ HttpUtilitiesBuild ( }
for (Index = 0; Index < TempFieldCount; Index++) {
- Status = SetFieldNameAndValue (
+ Status = HttpSetFieldNameAndValue (
&NewHeaderFields[Index],
TempHeaderFields[Index].FieldName,
TempHeaderFields[Index].FieldValue
@@ -162,9 +163,9 @@ HttpUtilitiesBuild ( NewFieldCount = TempFieldCount;
for (Index = 0; Index < AppendCount; Index++) {
- HttpHeader = FindHttpHeader (NewHeaderFields, NewFieldCount, AppendList[Index]->FieldName);
+ HttpHeader = HttpFindHeader (NewFieldCount, NewHeaderFields, AppendList[Index]->FieldName);
if (HttpHeader != NULL) {
- Status = SetFieldNameAndValue (
+ Status = HttpSetFieldNameAndValue (
HttpHeader,
AppendList[Index]->FieldName,
AppendList[Index]->FieldValue
@@ -173,7 +174,7 @@ HttpUtilitiesBuild ( goto ON_EXIT;
}
} else {
- Status = SetFieldNameAndValue (
+ Status = HttpSetFieldNameAndValue (
&NewHeaderFields[NewFieldCount],
AppendList[Index]->FieldName,
AppendList[Index]->FieldValue
@@ -251,15 +252,15 @@ HttpUtilitiesBuild ( //
ON_EXIT:
if (SeedHeaderFields != NULL) {
- FreeHeaderFields(SeedHeaderFields, SeedFieldCount);
+ HttpFreeHeaderFields(SeedHeaderFields, SeedFieldCount);
}
if (TempHeaderFields != NULL) {
- FreeHeaderFields(TempHeaderFields, TempFieldCount);
+ HttpFreeHeaderFields(TempHeaderFields, TempFieldCount);
}
if (NewHeaderFields != NULL) {
- FreeHeaderFields(NewHeaderFields, NewFieldCount);
+ HttpFreeHeaderFields(NewHeaderFields, NewFieldCount);
}
return Status;
@@ -332,7 +333,7 @@ HttpUtilitiesParse ( while (TRUE) {
FieldName = NULL;
FieldValue = NULL;
- NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue);
+ NextToken = HttpGetFieldNameAndValue (Token, &FieldName, &FieldValue);
Token = NextToken;
if (FieldName == NULL || FieldValue == NULL) {
break;
@@ -365,16 +366,16 @@ HttpUtilitiesParse ( while (Index < *FieldCount) {
FieldName = NULL;
FieldValue = NULL;
- NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue);
+ NextToken = HttpGetFieldNameAndValue (Token, &FieldName, &FieldValue);
Token = NextToken;
if (FieldName == NULL || FieldValue == NULL) {
break;
}
- Status = SetFieldNameAndValue (&(*HeaderFields)[Index], FieldName, FieldValue);
+ Status = HttpSetFieldNameAndValue (&(*HeaderFields)[Index], FieldName, FieldValue);
if (EFI_ERROR (Status)) {
*FieldCount = 0;
- FreeHeaderFields (*HeaderFields, Index);
+ HttpFreeHeaderFields (*HeaderFields, Index);
goto ON_EXIT;
}
|