]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg: Use the New Functions from HttpLib
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootClient.c
index f0817e92e21e38b3d7ef4ccf606947ce2efbf605..aae452729c8ebd4e0c27b7d3bbdc342221158817 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Implementation of the boot file download function.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, 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
@@ -167,18 +168,35 @@ HttpBootDhcp4ExtractUriInfo (
   // HttpOffer contains the boot file URL.\r
   //\r
   SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp4;\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
-    HttpOffer = SelectOffer;\r
+  if (Private->FilePathUri == NULL) {\r
+    //\r
+    // In Corporate environment, we need a HttpOffer.\r
+    //\r
+    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || \r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
+      HttpOffer = SelectOffer;\r
+    } else {\r
+      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
+      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
+      HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4;\r
+    }\r
+    Private->BootFileUriParser = HttpOffer->UriParser;\r
+    Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data;\r
   } else {\r
-    ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
-    ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
-    HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4;\r
+    //\r
+    // In Home environment the BootFileUri comes from the FilePath.\r
+    //\r
+    Private->BootFileUriParser = Private->FilePathUriParser;\r
+    Private->BootFileUri = Private->FilePathUri;\r
   }\r
 \r
   //\r
   // Configure the default DNS server if server assigned.\r
   //\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) {\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
     ASSERT (Option != NULL);\r
     Status = HttpBootRegisterIp4Dns (\r
@@ -195,21 +213,14 @@ HttpBootDhcp4ExtractUriInfo (
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
   //\r
   Status = HttpUrlGetPort (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &Private->Port\r
              );\r
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
   \r
-  //\r
-  // Record the URI of boot file from the selected HTTP offer.\r
-  //\r
-  Private->BootFileUriParser = HttpOffer->UriParser;\r
-  Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data;\r
-\r
-  \r
   //\r
   // All boot informations are valid here.\r
   //\r
@@ -259,12 +270,27 @@ HttpBootDhcp6ExtractUriInfo (
   // HttpOffer contains the boot file URL.\r
   //\r
   SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp6;\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
-    HttpOffer = SelectOffer;\r
+  if (Private->FilePathUri == NULL) {\r
+    //\r
+    // In Corporate environment, we need a HttpOffer.\r
+    //\r
+    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
+      HttpOffer = SelectOffer;\r
+    } else {\r
+      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
+      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
+      HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6;\r
+    }\r
+    Private->BootFileUriParser = HttpOffer->UriParser;\r
+    Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data;\r
   } else {\r
-    ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
-    ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
-    HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6;\r
+    //\r
+    // In Home environment the BootFileUri comes from the FilePath.\r
+    //\r
+    Private->BootFileUriParser = Private->FilePathUriParser;\r
+    Private->BootFileUri = Private->FilePathUri;\r
   }\r
 \r
   //\r
@@ -278,7 +304,9 @@ HttpBootDhcp6ExtractUriInfo (
   //\r
   // Configure the default DNS server if server assigned.\r
   //\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) {\r
+  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || \r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||\r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {\r
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER];\r
     ASSERT (Option != NULL);\r
     Status = HttpBootSetIp6Dns (\r
@@ -296,8 +324,8 @@ HttpBootDhcp6ExtractUriInfo (
   // whether can send message to HTTP Server Ip through the GateWay.\r
   //\r
   Status = HttpUrlGetIp6 (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &IpAddr\r
              );\r
   \r
@@ -306,8 +334,8 @@ HttpBootDhcp6ExtractUriInfo (
     // The Http server address is expressed by Name Ip, so perform DNS resolution\r
     //\r
     Status = HttpUrlGetHostName (\r
-               (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-               HttpOffer->UriParser,\r
+               Private->BootFileUri,\r
+               Private->BootFileUriParser,\r
                &HostName\r
                );\r
     if (EFI_ERROR (Status)) {\r
@@ -342,21 +370,14 @@ HttpBootDhcp6ExtractUriInfo (
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
   //\r
   Status = HttpUrlGetPort (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &Private->Port\r
              );\r
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
   \r
-  //\r
-  // Record the URI of boot file from the selected HTTP offer.\r
-  //\r
-  Private->BootFileUriParser = HttpOffer->UriParser;\r
-  Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data;\r
-\r
-  \r
   //\r
   // All boot informations are valid here.\r
   //\r
@@ -569,10 +590,6 @@ HttpBootGetFileFromCache (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //\r
-  // Search file in the cache list, the cache entry will be released upon a successful\r
-  // match.\r
-  //\r
   NET_LIST_FOR_EACH (Entry, &Private->CacheList) {\r
     Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link);\r
     //\r
@@ -606,12 +623,6 @@ HttpBootGetFileFromCache (
         }\r
       }\r
       *BufferSize = CopyedSize;\r
-\r
-      //\r
-      // On success, free the cached data to release the memory resource.\r
-      //\r
-      RemoveEntryList (&Cache->Link);\r
-      HttpBootFreeCache (Cache);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -717,6 +728,7 @@ HttpBootGetBootFile (
   )\r
 {\r
   EFI_STATUS                 Status;\r
+  EFI_HTTP_STATUS_CODE       StatusCode;\r
   CHAR8                      *HostName;\r
   EFI_HTTP_REQUEST_DATA      *RequestData;\r
   HTTP_IO_RESPONSE_DATA      *ResponseData;\r
@@ -806,7 +818,7 @@ HttpBootGetBootFile (
   }\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_HOST,\r
+             HTTP_HEADER_HOST,\r
              HostName\r
              );\r
   FreePool (HostName);\r
@@ -819,7 +831,7 @@ HttpBootGetBootFile (
   //\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_ACCEPT,\r
+             HTTP_HEADER_ACCEPT,\r
              "*/*"\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -831,7 +843,7 @@ HttpBootGetBootFile (
   //\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_USER_AGENT,\r
+             HTTP_HEADER_USER_AGENT,\r
              HTTP_USER_AGENT_EFI_HTTP_BOOT\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -894,7 +906,12 @@ HttpBootGetBootFile (
              TRUE,\r
              ResponseData\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || EFI_ERROR (ResponseData->Status)) {\r
+    if (EFI_ERROR (ResponseData->Status)) {\r
+      StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;\r
+      HttpBootPrintErrorMessage (StatusCode);\r
+      Status = ResponseData->Status;\r
+    }\r
     goto ERROR_5;\r
   }\r
 \r
@@ -1076,3 +1093,4 @@ ERROR_1:
 \r
   return Status;\r
 }\r
+\r