]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/DxeHttpLib: Migrate HTTP header manipulation APIs
authorAbner Chang <abner.chang@hpe.com>
Thu, 7 Jan 2021 06:57:02 +0000 (14:57 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 14 Jan 2021 14:54:12 +0000 (14:54 +0000)
Move HTTP header manipulation functions to DxeHttpLib from
HttpBootSupport.c. These general functions are used by both
Http BOOT and RedfishLib (patches will be sent later).

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Fan Wang <fan.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Peter O'Hanley <peter.ohanley@hpe.com>
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg/HttpBootDxe/HttpBootSupport.h
NetworkPkg/Include/Library/HttpLib.h
NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c

index 30ac15889b06b88be25c577f5f8a071d15e73e08..8f21f7766ed1fe34bd585455cfd184374f33bda5 100644 (file)
@@ -977,7 +977,7 @@ HttpBootGetBootFile (
   //       Accept\r
   //       User-Agent\r
   //\r
-  HttpIoHeader = HttpBootCreateHeader (3);\r
+  HttpIoHeader = HttpIoCreateHeader (3);\r
   if (HttpIoHeader == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ERROR_2;\r
@@ -995,7 +995,7 @@ HttpBootGetBootFile (
   if (EFI_ERROR (Status)) {\r
     goto ERROR_3;\r
   }\r
-  Status = HttpBootSetHeader (\r
+  Status = HttpIoSetHeader (\r
              HttpIoHeader,\r
              HTTP_HEADER_HOST,\r
              HostName\r
@@ -1008,7 +1008,7 @@ HttpBootGetBootFile (
   //\r
   // Add HTTP header field 2: Accept\r
   //\r
-  Status = HttpBootSetHeader (\r
+  Status = HttpIoSetHeader (\r
              HttpIoHeader,\r
              HTTP_HEADER_ACCEPT,\r
              "*/*"\r
@@ -1020,7 +1020,7 @@ HttpBootGetBootFile (
   //\r
   // Add HTTP header field 3: User-Agent\r
   //\r
-  Status = HttpBootSetHeader (\r
+  Status = HttpIoSetHeader (\r
              HttpIoHeader,\r
              HTTP_HEADER_USER_AGENT,\r
              HTTP_USER_AGENT_EFI_HTTP_BOOT\r
@@ -1291,7 +1291,7 @@ ERROR_4:
     FreePool (RequestData);\r
   }\r
 ERROR_3:\r
-  HttpBootFreeHeader (HttpIoHeader);\r
+  HttpIoFreeHeader (HttpIoHeader);\r
 ERROR_2:\r
   if (Cache != NULL) {\r
     FreePool (Cache);\r
index 93d9dfc4643d224094008de65a1c1dd08d9a5537..37a95e031e9ccbba75580ae1506472360ac0cfa3 100644 (file)
@@ -491,136 +491,6 @@ Exit:
 \r
   return Status;\r
 }\r
-/**\r
-  Create a HTTP_IO_HEADER to hold the HTTP header items.\r
-\r
-  @param[in]  MaxHeaderCount         The maximum number of HTTP header in this holder.\r
-\r
-  @return    A pointer of the HTTP header holder or NULL if failed.\r
-\r
-**/\r
-HTTP_IO_HEADER *\r
-HttpBootCreateHeader (\r
-  UINTN                     MaxHeaderCount\r
-  )\r
-{\r
-  HTTP_IO_HEADER        *HttpIoHeader;\r
-\r
-  if (MaxHeaderCount == 0) {\r
-    return NULL;\r
-  }\r
-\r
-  HttpIoHeader = AllocateZeroPool (sizeof (HTTP_IO_HEADER) + MaxHeaderCount * sizeof (EFI_HTTP_HEADER));\r
-  if (HttpIoHeader == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  HttpIoHeader->MaxHeaderCount = MaxHeaderCount;\r
-  HttpIoHeader->Headers = (EFI_HTTP_HEADER *) (HttpIoHeader + 1);\r
-\r
-  return HttpIoHeader;\r
-}\r
-\r
-/**\r
-  Destroy the HTTP_IO_HEADER and release the resources.\r
-\r
-  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.\r
-\r
-**/\r
-VOID\r
-HttpBootFreeHeader (\r
-  IN  HTTP_IO_HEADER       *HttpIoHeader\r
-  )\r
-{\r
-  UINTN      Index;\r
-\r
-  if (HttpIoHeader != NULL) {\r
-    if (HttpIoHeader->HeaderCount != 0) {\r
-      for (Index = 0; Index < HttpIoHeader->HeaderCount; Index++) {\r
-        FreePool (HttpIoHeader->Headers[Index].FieldName);\r
-        FreePool (HttpIoHeader->Headers[Index].FieldValue);\r
-      }\r
-    }\r
-    FreePool (HttpIoHeader);\r
-  }\r
-}\r
-\r
-/**\r
-  Set or update a HTTP header with the field name and corresponding value.\r
-\r
-  @param[in]  HttpIoHeader       Point to the HTTP header holder.\r
-  @param[in]  FieldName          Null terminated string which describes a field name.\r
-  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.\r
-\r
-  @retval  EFI_SUCCESS           The HTTP header has been set or updated.\r
-  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.\r
-  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.\r
-  @retval  Other                 Unexpected error happened.\r
-\r
-**/\r
-EFI_STATUS\r
-HttpBootSetHeader (\r
-  IN  HTTP_IO_HEADER       *HttpIoHeader,\r
-  IN  CHAR8                *FieldName,\r
-  IN  CHAR8                *FieldValue\r
-  )\r
-{\r
-  EFI_HTTP_HEADER       *Header;\r
-  UINTN                 StrSize;\r
-  CHAR8                 *NewFieldValue;\r
-\r
-  if (HttpIoHeader == NULL || FieldName == NULL || FieldValue == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Header = HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);\r
-  if (Header == NULL) {\r
-    //\r
-    // Add a new header.\r
-    //\r
-    if (HttpIoHeader->HeaderCount >= HttpIoHeader->MaxHeaderCount) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    Header = &HttpIoHeader->Headers[HttpIoHeader->HeaderCount];\r
-\r
-    StrSize = AsciiStrSize (FieldName);\r
-    Header->FieldName = AllocatePool (StrSize);\r
-    if (Header->FieldName == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    CopyMem (Header->FieldName, FieldName, StrSize);\r
-    Header->FieldName[StrSize -1] = '\0';\r
-\r
-    StrSize = AsciiStrSize (FieldValue);\r
-    Header->FieldValue = AllocatePool (StrSize);\r
-    if (Header->FieldValue == NULL) {\r
-      FreePool (Header->FieldName);\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    CopyMem (Header->FieldValue, FieldValue, StrSize);\r
-    Header->FieldValue[StrSize -1] = '\0';\r
-\r
-    HttpIoHeader->HeaderCount++;\r
-  } else {\r
-    //\r
-    // Update an existing one.\r
-    //\r
-    StrSize = AsciiStrSize (FieldValue);\r
-    NewFieldValue = AllocatePool (StrSize);\r
-    if (NewFieldValue == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    CopyMem (NewFieldValue, FieldValue, StrSize);\r
-    NewFieldValue[StrSize -1] = '\0';\r
-\r
-    if (Header->FieldValue != NULL) {\r
-      FreePool (Header->FieldValue);\r
-    }\r
-    Header->FieldValue = NewFieldValue;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
 \r
 /**\r
   This function checks the HTTP(S) URI scheme.\r
index 1a2d32dd5a548bd2d4d2246bcd604217483d68c2..c2ac1b785a8f7d56c6a6b20890c91cd2abe7b39a 100644 (file)
@@ -87,59 +87,6 @@ HttpBootPrintErrorMessage (
   EFI_HTTP_STATUS_CODE            StatusCode\r
   );\r
 \r
-//\r
-// A wrapper structure to hold the HTTP headers.\r
-//\r
-typedef struct {\r
-  UINTN                       MaxHeaderCount;\r
-  UINTN                       HeaderCount;\r
-  EFI_HTTP_HEADER             *Headers;\r
-} HTTP_IO_HEADER;\r
-\r
-/**\r
-  Create a HTTP_IO_HEADER to hold the HTTP header items.\r
-\r
-  @param[in]  MaxHeaderCount         The maximum number of HTTP header in this holder.\r
-\r
-  @return    A pointer of the HTTP header holder or NULL if failed.\r
-\r
-**/\r
-HTTP_IO_HEADER *\r
-HttpBootCreateHeader (\r
-  IN  UINTN                MaxHeaderCount\r
-  );\r
-\r
-/**\r
-  Destroy the HTTP_IO_HEADER and release the resources.\r
-\r
-  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.\r
-\r
-**/\r
-VOID\r
-HttpBootFreeHeader (\r
-  IN  HTTP_IO_HEADER       *HttpIoHeader\r
-  );\r
-\r
-/**\r
-  Set or update a HTTP header with the field name and corresponding value.\r
-\r
-  @param[in]  HttpIoHeader       Point to the HTTP header holder.\r
-  @param[in]  FieldName          Null terminated string which describes a field name.\r
-  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.\r
-\r
-  @retval  EFI_SUCCESS           The HTTP header has been set or updated.\r
-  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.\r
-  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.\r
-  @retval  Other                 Unexpected error happened.\r
-\r
-**/\r
-EFI_STATUS\r
-HttpBootSetHeader (\r
-  IN  HTTP_IO_HEADER       *HttpIoHeader,\r
-  IN  CHAR8                *FieldName,\r
-  IN  CHAR8                *FieldValue\r
-  );\r
-\r
 /**\r
   Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
 \r
index a906126b3d6e590143a6f2409f09f0cb09565703..2c3367fb01976e91f25a9ee9f8127b1596d5a9a0 100644 (file)
@@ -476,6 +476,59 @@ HttpIsValidHttpHeader (
   IN  CHAR8            *FieldName\r
   );\r
 \r
+//\r
+// A wrapper structure to hold the HTTP headers.\r
+//\r
+typedef struct {\r
+  UINTN                       MaxHeaderCount;\r
+  UINTN                       HeaderCount;\r
+  EFI_HTTP_HEADER             *Headers;\r
+} HTTP_IO_HEADER;\r
+\r
+\r
+/**\r
+  Create a HTTP_IO_HEADER to hold the HTTP header items.\r
+\r
+  @param[in]  MaxHeaderCount         The maximun number of HTTP header in this holder.\r
+\r
+  @return    A pointer of the HTTP header holder or NULL if failed.\r
+\r
+**/\r
+HTTP_IO_HEADER *\r
+HttpIoCreateHeader (\r
+  UINTN                     MaxHeaderCount\r
+  );\r
+\r
+/**\r
+  Destroy the HTTP_IO_HEADER and release the resources.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.\r
+\r
+**/\r
+VOID\r
+HttpIoFreeHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader\r
+  );\r
+\r
+/**\r
+  Set or update a HTTP header with the field name and corresponding value.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder.\r
+  @param[in]  FieldName          Null terminated string which describes a field name.\r
+  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.\r
+\r
+  @retval  EFI_SUCCESS           The HTTP header has been set or updated.\r
+  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.\r
+  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.\r
+  @retval  Other                 Unexpected error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpIoSetHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader,\r
+  IN  CHAR8                *FieldName,\r
+  IN  CHAR8                *FieldValue\r
+  );\r
 \r
 #endif\r
 \r
index daec1e02265683520bff74cbe226067a86997aa0..0bbe0fc5d7ce1fa61dcedc853a96b68a280a05eb 100644 (file)
@@ -3,7 +3,7 @@
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
 Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+(C) Copyright 2016 - 2020  Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -2095,3 +2095,135 @@ HttpIsValidHttpHeader (
   return TRUE;\r
 }\r
 \r
+\r
+/**\r
+  Create a HTTP_IO_HEADER to hold the HTTP header items.\r
+\r
+  @param[in]  MaxHeaderCount         The maximun number of HTTP header in this holder.\r
+\r
+  @return    A pointer of the HTTP header holder or NULL if failed.\r
+\r
+**/\r
+HTTP_IO_HEADER *\r
+HttpIoCreateHeader (\r
+  UINTN                     MaxHeaderCount\r
+  )\r
+{\r
+  HTTP_IO_HEADER        *HttpIoHeader;\r
+\r
+  if (MaxHeaderCount == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  HttpIoHeader = AllocateZeroPool (sizeof (HTTP_IO_HEADER) + MaxHeaderCount * sizeof (EFI_HTTP_HEADER));\r
+  if (HttpIoHeader == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  HttpIoHeader->MaxHeaderCount = MaxHeaderCount;\r
+  HttpIoHeader->Headers = (EFI_HTTP_HEADER *) (HttpIoHeader + 1);\r
+\r
+  return HttpIoHeader;\r
+}\r
+\r
+/**\r
+  Destroy the HTTP_IO_HEADER and release the resources.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.\r
+\r
+**/\r
+VOID\r
+HttpIoFreeHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader\r
+  )\r
+{\r
+  UINTN      Index;\r
+\r
+  if (HttpIoHeader != NULL) {\r
+    if (HttpIoHeader->HeaderCount != 0) {\r
+      for (Index = 0; Index < HttpIoHeader->HeaderCount; Index++) {\r
+        FreePool (HttpIoHeader->Headers[Index].FieldName);\r
+        ZeroMem (HttpIoHeader->Headers[Index].FieldValue, AsciiStrSize (HttpIoHeader->Headers[Index].FieldValue));\r
+        FreePool (HttpIoHeader->Headers[Index].FieldValue);\r
+      }\r
+    }\r
+    FreePool (HttpIoHeader);\r
+  }\r
+}\r
+\r
+/**\r
+  Set or update a HTTP header with the field name and corresponding value.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder.\r
+  @param[in]  FieldName          Null terminated string which describes a field name.\r
+  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.\r
+\r
+  @retval  EFI_SUCCESS           The HTTP header has been set or updated.\r
+  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.\r
+  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.\r
+  @retval  Other                 Unexpected error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpIoSetHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader,\r
+  IN  CHAR8                *FieldName,\r
+  IN  CHAR8                *FieldValue\r
+  )\r
+{\r
+  EFI_HTTP_HEADER       *Header;\r
+  UINTN                 StrSize;\r
+  CHAR8                 *NewFieldValue;\r
+\r
+  if (HttpIoHeader == NULL || FieldName == NULL || FieldValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Header = HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);\r
+  if (Header == NULL) {\r
+    //\r
+    // Add a new header.\r
+    //\r
+    if (HttpIoHeader->HeaderCount >= HttpIoHeader->MaxHeaderCount) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Header = &HttpIoHeader->Headers[HttpIoHeader->HeaderCount];\r
+\r
+    StrSize = AsciiStrSize (FieldName);\r
+    Header->FieldName = AllocatePool (StrSize);\r
+    if (Header->FieldName == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (Header->FieldName, FieldName, StrSize);\r
+    Header->FieldName[StrSize -1] = '\0';\r
+\r
+    StrSize = AsciiStrSize (FieldValue);\r
+    Header->FieldValue = AllocatePool (StrSize);\r
+    if (Header->FieldValue == NULL) {\r
+      FreePool (Header->FieldName);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (Header->FieldValue, FieldValue, StrSize);\r
+    Header->FieldValue[StrSize -1] = '\0';\r
+\r
+    HttpIoHeader->HeaderCount++;\r
+  } else {\r
+    //\r
+    // Update an existing one.\r
+    //\r
+    StrSize = AsciiStrSize (FieldValue);\r
+    NewFieldValue = AllocatePool (StrSize);\r
+    if (NewFieldValue == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (NewFieldValue, FieldValue, StrSize);\r
+    NewFieldValue[StrSize -1] = '\0';\r
+\r
+    if (Header->FieldValue != NULL) {\r
+      FreePool (Header->FieldValue);\r
+    }\r
+    Header->FieldValue = NewFieldValue;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r