summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/HttpUtilitiesDxe
diff options
context:
space:
mode:
authorGhazi Belaam <Ghazi.belaam@hpe.com>2016-03-05 06:07:50 +0800
committerFu Siyuan <siyuan.fu@intel.com>2016-03-10 10:01:42 +0800
commitf58554fc3f3eaf0ca132d0880ec05fbee4b36edf (patch)
tree4fe697144433948976ec4f19760404583ca1cebb /NetworkPkg/HttpUtilitiesDxe
parent558b99a6a31ac883539779ffc112c64ada32aaee (diff)
downloadedk2-f58554fc3f3eaf0ca132d0880ec05fbee4b36edf.tar.gz
edk2-f58554fc3f3eaf0ca132d0880ec05fbee4b36edf.tar.bz2
edk2-f58554fc3f3eaf0ca132d0880ec05fbee4b36edf.zip
NetworkPkg: Use the New Functions from HttpLib
After submitting changes for HttpLib, other modules should be able to use those functions 1 remove the private function and their calls 2 update it with the functions from httpLib Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ghazi Belaam <Ghazi.belaam@hpe.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Samer EL-Haj-Mahmoud <elhaj@hpe.com> Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Diffstat (limited to 'NetworkPkg/HttpUtilitiesDxe')
-rw-r--r--NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h94
-rw-r--r--NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf3
-rw-r--r--NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesImpl.c279
-rw-r--r--NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c27
4 files changed, 18 insertions, 385 deletions
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;
}