Reviewed-by: Samer El-Haj-Mahmoud <[email protected]>

-----Original Message-----
From: edk2-devel [mailto:[email protected]] On Behalf Of Jiaxin Wu
Sent: Monday, August 24, 2015 12:47 AM
To: [email protected]
Cc: Ye Ting <[email protected]>; Siyuan Fu <[email protected]>
Subject: [edk2] [Patch] NetworkPkg: Update HttpDxe to consume 
EFI_HTTP_UTILITIES_PROTOCOL

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 <[email protected]>
Cc: Siyuan Fu <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <[email protected]>
---
 NetworkPkg/HttpDxe/HttpDriver.h    |   4 +-
 NetworkPkg/HttpDxe/HttpDxe.inf     |   3 +-
 NetworkPkg/HttpDxe/HttpImpl.c      |  21 +-
 NetworkPkg/HttpDxe/HttpProto.c     |  33 +-
 NetworkPkg/HttpDxe/HttpUtilities.c | 622 -------------------------------------
 NetworkPkg/HttpDxe/HttpUtilities.h |  82 -----
 6 files changed, 46 insertions(+), 719 deletions(-)  delete mode 100644 
NetworkPkg/HttpDxe/HttpUtilities.c
 delete mode 100644 NetworkPkg/HttpDxe/HttpUtilities.h

diff --git a/NetworkPkg/HttpDxe/HttpDriver.h b/NetworkPkg/HttpDxe/HttpDriver.h 
index 5bad705..d95b05b 100644
--- a/NetworkPkg/HttpDxe/HttpDriver.h
+++ b/NetworkPkg/HttpDxe/HttpDriver.h
@@ -39,10 +39,11 @@
 #include <Protocol/ComponentName.h>
 
 //
 // Consumed Protocols
 //
+#include <Protocol/HttpUtilities.h>
 #include <Protocol/Tcp4.h>
 #include <Protocol/Dns4.h>
 #include <Protocol/Ip4Config2.h>
 
 //
@@ -60,18 +61,19 @@
 //
 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  //  #include "ComponentName.h"
 #include "HttpImpl.h"
 #include "HttpProto.h"
 #include "HttpDns.h"
-#include "HttpUtilities.h"
 
 typedef struct {
   EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;
   UINTN                         NumberOfChildren;
   EFI_HANDLE                    *ChildHandleBuffer;
diff --git a/NetworkPkg/HttpDxe/HttpDxe.inf b/NetworkPkg/HttpDxe/HttpDxe.inf 
index 4632934..d9652b3 100644
--- a/NetworkPkg/HttpDxe/HttpDxe.inf
+++ b/NetworkPkg/HttpDxe/HttpDxe.inf
@@ -36,12 +36,10 @@
   HttpDriver.c
   HttpImpl.h
   HttpImpl.c
   HttpProto.h
   HttpProto.c
-  HttpUtilities.h
-  HttpUtilities.c
 
 [LibraryClasses]
   UefiDriverEntryPoint
   UefiBootServicesTableLib
   MemoryAllocationLib
@@ -52,10 +50,11 @@
   HttpLib
 
 [Protocols]
   gEfiHttpServiceBindingProtocolGuid               ## BY_START
   gEfiHttpProtocolGuid                             ## BY_START
+  gEfiHttpUtilitiesProtocolGuid                    ## TO_START
   gEfiTcp4ServiceBindingProtocolGuid               ## TO_START
   gEfiTcp4ProtocolGuid                             ## TO_START
   gEfiDns4ServiceBindingProtocolGuid               ## SOMETIMES_CONSUMES
   gEfiDns4ProtocolGuid                             ## SOMETIMES_CONSUMES
   gEfiIp4Config2ProtocolGuid                       ## SOMETIMES_CONSUMES
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c 
index 80e8192..37d1c83 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -13,10 +13,12 @@
 
 **/
 
 #include "HttpDriver.h"
 
+EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
+
 EFI_HTTP_PROTOCOL  mEfiHttpTemplate = {
   EfiHttpGetModeData,
   EfiHttpConfigure,
   EfiHttpRequest,
   EfiHttpCancel,
@@ -951,14 +953,31 @@ HttpResponseWorker (
     }
 
     CopyMem (HeaderTmp, Tmp, SizeofHeaders);
     FreePool (HttpHeaders);
     HttpHeaders = HeaderTmp;
+
+    //
+    // Locate and check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
+    //
+    if (mHttpUtilities == NULL) {
+      Status = gBS->LocateProtocol (&gEfiHttpUtilitiesProtocolGuid, NULL, 
(VOID **) &mHttpUtilities);
+      if (EFI_ERROR (Status) || mHttpUtilities == NULL) {
+        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;
     }
 
     FreePool (HttpHeaders);
diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c 
index 50ade4c..06e1b9d 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1070,22 +1070,33 @@ HttpGenRequestString (
   for(Index = 0; Index < Message->HeaderCount; Index++){
     AppendList[Index] = &Message->Headers[Index];
   }
 
   //
+  // Locate and check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
+  //
+  if (mHttpUtilities == NULL) {
+    gBS->LocateProtocol (&gEfiHttpUtilitiesProtocolGuid, NULL, (VOID **) 
&mHttpUtilities);
+    if (mHttpUtilities == NULL) {
+      return NULL;
+    }
+  }
+
+  //
   // Build raw unformatted HTTP headers.
-  //
-  Status = HttpUtilitiesBuild (
-             0,
-             NULL,
-             0,
-             NULL,
-             Message->HeaderCount,
-             AppendList,
-             &HttpHdrSize,
-             &HttpHdr
-             );
+  //
+  Status = mHttpUtilities->Build (
+                             mHttpUtilities,
+                             0,
+                             NULL,
+                             0,
+                             NULL,
+                             Message->HeaderCount,
+                             AppendList,
+                             &HttpHdrSize,
+                             &HttpHdr
+                             );
   FreePool (AppendList);
   if (EFI_ERROR (Status) || HttpHdr == NULL) {
     return NULL;
   }
 
diff --git a/NetworkPkg/HttpDxe/HttpUtilities.c 
b/NetworkPkg/HttpDxe/HttpUtilities.c
deleted file mode 100644
index c2a99a4..0000000
--- a/NetworkPkg/HttpDxe/HttpUtilities.c
+++ /dev/null
@@ -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;
-}
diff --git a/NetworkPkg/HttpDxe/HttpUtilities.h 
b/NetworkPkg/HttpDxe/HttpUtilities.h
deleted file mode 100644
index bd4ef0b..0000000
--- a/NetworkPkg/HttpDxe/HttpUtilities.h
+++ /dev/null
@@ -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
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to