]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg/DxeHttpLib: Migrate HTTP header manipulation APIs
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootClient.c
index 15e0ab9d698eefdccda425aaa046d8df81d6abc0..8f21f7766ed1fe34bd585455cfd184374f33bda5 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Implementation of the boot file download function.\r
 \r
-Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
-This program and the accompanying materials are licensed and made available under \r
-the terms and conditions of the BSD License that accompanies this distribution.  \r
-The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php.                                          \r
-    \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -23,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @retval EFI_SUCCESS              Device patch successfully updated.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval Others                   Unexpected error happened.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 HttpBootUpdateDevicePath (\r
@@ -39,7 +33,7 @@ HttpBootUpdateDevicePath (
 \r
   TmpIpDevicePath  = NULL;\r
   TmpDnsDevicePath = NULL;\r
-  \r
+\r
   //\r
   // Update the IP node with DHCP assigned information.\r
   //\r
@@ -67,13 +61,13 @@ HttpBootUpdateDevicePath (
     SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r
     Node->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;\r
     Node->Ipv6.RemotePort      = Private->Port;\r
-    Node->Ipv6.Protocol        = EFI_IP_PROTO_TCP; \r
+    Node->Ipv6.Protocol        = EFI_IP_PROTO_TCP;\r
     Node->Ipv6.IpAddressOrigin = 0;\r
     CopyMem (&Node->Ipv6.LocalIpAddress, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
     CopyMem (&Node->Ipv6.RemoteIpAddress, &Private->ServerIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
     CopyMem (&Node->Ipv6.GatewayIpAddress, &Private->GatewayIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
   }\r
-  \r
+\r
   TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r
   FreePool (Node);\r
   if (TmpIpDevicePath == NULL) {\r
@@ -95,7 +89,7 @@ HttpBootUpdateDevicePath (
     SetDevicePathNodeLength (Node, Length);\r
     Node->Dns.IsIPv6 = Private->UsingIpv6 ? 0x01 : 0x00;\r
     CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (EFI_IP_ADDRESS));\r
-    \r
+\r
     TmpDnsDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r
     FreePool (Node);\r
     FreePool (TmpIpDevicePath);\r
@@ -150,7 +144,7 @@ HttpBootUpdateDevicePath (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-    \r
+\r
     FreePool (Private->Ip4Nic->DevicePath);\r
     Private->Ip4Nic->DevicePath = NewDevicePath;\r
   } else {\r
@@ -169,7 +163,7 @@ HttpBootUpdateDevicePath (
     FreePool (Private->Ip6Nic->DevicePath);\r
     Private->Ip6Nic->DevicePath = NewDevicePath;\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -201,7 +195,7 @@ HttpBootDhcp4ExtractUriInfo (
   ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM);\r
 \r
   DnsServerIndex = 0;\r
-  \r
+\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
@@ -213,7 +207,7 @@ HttpBootDhcp4ExtractUriInfo (
     //\r
     // In Corporate environment, we need a HttpOffer.\r
     //\r
-    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || \r
+    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) ||\r
         (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||\r
         (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
       HttpOffer = SelectOffer;\r
@@ -246,7 +240,7 @@ HttpBootDhcp4ExtractUriInfo (
     return Status;\r
   }\r
 \r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || \r
+  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) ||\r
       (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||\r
       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {\r
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER];\r
@@ -265,10 +259,10 @@ HttpBootDhcp4ExtractUriInfo (
     for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) {\r
       CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS));\r
     }\r
-    \r
+\r
     //\r
     // Configure the default DNS server if server assigned.\r
-    //    \r
+    //\r
     Status = HttpBootRegisterIp4Dns (\r
                Private,\r
                Option->Length,\r
@@ -292,7 +286,7 @@ HttpBootDhcp4ExtractUriInfo (
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
-  \r
+\r
   //\r
   // All boot informations are valid here.\r
   //\r
@@ -402,7 +396,7 @@ HttpBootDhcp6ExtractUriInfo (
     return Status;\r
   }\r
 \r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || \r
+  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) ||\r
       (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||\r
       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {\r
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER];\r
@@ -434,9 +428,9 @@ HttpBootDhcp6ExtractUriInfo (
       goto Error;\r
     }\r
   }\r
-  \r
+\r
   //\r
-  // Extract the HTTP server Ip frome URL. This is used to Check route table \r
+  // Extract the HTTP server Ip from URL. This is used to Check route table\r
   // whether can send message to HTTP Server Ip through the GateWay.\r
   //\r
   Status = HttpUrlGetIp6 (\r
@@ -444,7 +438,7 @@ HttpBootDhcp6ExtractUriInfo (
              Private->BootFileUriParser,\r
              &IpAddr\r
              );\r
-  \r
+\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // The Http server address is expressed by Name Ip, so perform DNS resolution\r
@@ -464,22 +458,23 @@ HttpBootDhcp6ExtractUriInfo (
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Error;\r
     }\r
-    \r
+\r
     AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
 \r
     if (HostName != NULL) {\r
       FreePool (HostName);\r
     }\r
-    \r
+\r
     Status = HttpBootDns (Private, HostNameStr, &IpAddr);\r
     FreePool (HostNameStr);\r
     if (EFI_ERROR (Status)) {\r
+      AsciiPrint ("\n  Error: Could not retrieve the host address from DNS server.\n");\r
       goto Error;\r
-    }  \r
-  } \r
-  \r
+    }\r
+  }\r
+\r
   CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS));\r
-  \r
+\r
   //\r
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
   //\r
@@ -491,7 +486,7 @@ HttpBootDhcp6ExtractUriInfo (
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
-  \r
+\r
   //\r
   // All boot informations are valid here.\r
   //\r
@@ -503,7 +498,7 @@ HttpBootDhcp6ExtractUriInfo (
   if (EFI_ERROR (Status)) {\r
     goto Error;\r
   }\r
-  \r
+\r
   return Status;\r
 \r
 Error:\r
@@ -511,7 +506,7 @@ Error:
     FreePool (Private->DnsServerIp);\r
     Private->DnsServerIp = NULL;\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -531,7 +526,7 @@ HttpBootDiscoverBootInfo (
   )\r
 {\r
   EFI_STATUS              Status;\r
-  \r
+\r
   //\r
   // Start D.O.R.A/S.A.R.R exchange to acquire station ip address and\r
   // other Http boot information.\r
@@ -556,7 +551,7 @@ HttpBootDiscoverBootInfo (
   @param[in]    EventType      Indicate the Event type that occurs in the current callback.\r
   @param[in]    Message        HTTP message which will be send to, or just received from HTTP server.\r
   @param[in]    Context        The Callback Context pointer.\r
-  \r
+\r
   @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.\r
   @retval Others               Tells the HttpIo to abort the current HTTP process.\r
 **/\r
@@ -705,7 +700,7 @@ HttpBootFreeCacheList (
   LIST_ENTRY                  *Entry;\r
   LIST_ENTRY                  *NextEntry;\r
   HTTP_BOOT_CACHE_CONTENT     *Cache;\r
-  \r
+\r
   NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->CacheList) {\r
     Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link);\r
     RemoveEntryList (&Cache->Link);\r
@@ -745,8 +740,8 @@ HttpBootGetFileFromCache (
   HTTP_BOOT_CACHE_CONTENT     *Cache;\r
   HTTP_BOOT_ENTITY_DATA       *EntityData;\r
   UINTN                       CopyedSize;\r
-  \r
-  if (Uri == NULL || BufferSize == 0 || Buffer == NULL || ImageType == NULL) {\r
+\r
+  if (Uri == NULL || BufferSize == NULL || Buffer == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -757,8 +752,7 @@ HttpBootGetFileFromCache (
     //\r
     if ((Cache->RequestData != NULL) &&\r
         (Cache->RequestData->Url != NULL) &&\r
-        (StrCmp (Uri, Cache->RequestData->Url) == 0)) \r
-    {\r
+        (StrCmp (Uri, Cache->RequestData->Url) == 0)) {\r
       //\r
       // Hit in cache, record image type.\r
       //\r
@@ -808,7 +802,7 @@ HttpBootGetFileFromCache (
 \r
   @retval EFI_SUCCESS              Continue to parser the message body.\r
   @retval Others                   Abort the parse.\r
\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -878,7 +872,7 @@ HttpBootGetBootFileCallback (
 \r
 /**\r
   This function download the boot file by using UEFI HTTP protocol.\r
-  \r
+\r
   @param[in]       Private         The pointer to the driver's private data.\r
   @param[in]       HeaderOnly      Only request the response header, it could save a lot of time if\r
                                    the caller only want to know the size of the requested file.\r
@@ -926,7 +920,7 @@ HttpBootGetBootFile (
   CHAR16                     *Url;\r
   BOOLEAN                    IdentityMode;\r
   UINTN                      ReceivedSize;\r
-  \r
+\r
   ASSERT (Private != NULL);\r
   ASSERT (Private->HttpCreated);\r
 \r
@@ -947,7 +941,7 @@ HttpBootGetBootFile (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize);\r
-  if (!HeaderOnly) {\r
+  if (!HeaderOnly && Buffer != NULL) {\r
     Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType);\r
     if (Status != EFI_NOT_FOUND) {\r
       FreePool (Url);\r
@@ -983,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
@@ -1001,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
@@ -1014,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
@@ -1026,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
@@ -1116,7 +1110,7 @@ HttpBootGetBootFile (
     Cache->ResponseData = ResponseData;\r
     Cache->ImageType = *ImageType;\r
   }\r
-  \r
+\r
   //\r
   // 3.3 Init a message-body parser from the header information.\r
   //\r
@@ -1129,7 +1123,7 @@ HttpBootGetBootFile (
   Context.Cache      = Cache;\r
   Context.Private    = Private;\r
   Status = HttpInitMsgParser (\r
-             HeaderOnly? HttpMethodHead : HttpMethodGet,\r
+             HeaderOnly ? HttpMethodHead : HttpMethodGet,\r
              ResponseData->Response.StatusCode,\r
              ResponseData->HeaderCount,\r
              ResponseData->Headers,\r
@@ -1278,7 +1272,7 @@ HttpBootGetBootFile (
   }\r
 \r
   return Status;\r
-  \r
+\r
 ERROR_6:\r
   if (Parser != NULL) {\r
     HttpFreeMsgParser (Parser);\r
@@ -1287,7 +1281,7 @@ ERROR_6:
     FreePool (Context.Block);\r
   }\r
   HttpBootFreeCache (Cache);\r
-  \r
+\r
 ERROR_5:\r
   if (ResponseData != NULL) {\r
     FreePool (ResponseData);\r
@@ -1297,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