]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg: Add URI configuration form to HTTP boot driver.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootSupport.c
index f9bbe4b1a0e7ddf8d97666f24ab6802118af929e..f30d9f7fb0db7475f2293ac6cb4f4d48219dae94 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support functions implementation for UEFI HTTP boot driver.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<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
@@ -930,7 +930,6 @@ HttpIoRecvResponse (
 {\r
   EFI_STATUS                 Status;\r
   EFI_HTTP_PROTOCOL          *Http;\r
-  EFI_HTTP_STATUS_CODE       StatusCode;\r
 \r
   if (HttpIo == NULL || HttpIo->Http == NULL || ResponseData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -971,17 +970,73 @@ HttpIoRecvResponse (
   //\r
   // Store the received data into the wrapper.\r
   //\r
-  Status = HttpIo->RspToken.Status;\r
-  if (!EFI_ERROR (Status)) {\r
-    ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;\r
-    ResponseData->Headers     = HttpIo->RspToken.Message->Headers;\r
-    ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;\r
-  }\r
+  ResponseData->Status = HttpIo->RspToken.Status;\r
+  ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;\r
+  ResponseData->Headers     = HttpIo->RspToken.Message->Headers;\r
+  ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Get the URI address string from the input device path.\r
+\r
+  Caller need to free the buffer in the UriAddress pointer.\r
   \r
-  if (RecvMsgHeader) {\r
-    StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;\r
-    HttpBootPrintErrorMessage (StatusCode);\r
+  @param[in]   FilePath         Pointer to the device path which contains a URI device path node.\r
+  @param[in]   UriAddress       The URI address string extract from the device path.\r
+  \r
+  @retval EFI_SUCCESS            The URI string is returned.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootParseFilePath (\r
+  IN     EFI_DEVICE_PATH_PROTOCOL     *FilePath,\r
+     OUT CHAR8                        **UriAddress\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  URI_DEVICE_PATH           *UriDevicePath;\r
+  CHAR8                     *Uri;\r
+  UINTN                     UriStrLength;\r
+\r
+  if (FilePath == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  return Status;\r
+  *UriAddress = NULL;\r
+\r
+  //\r
+  // Extract the URI address from the FilePath\r
+  //\r
+  TempDevicePath = FilePath;\r
+  while (!IsDevicePathEnd (TempDevicePath)) {\r
+    if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
+        (DevicePathSubType (TempDevicePath) == MSG_URI_DP)) {\r
+      UriDevicePath = (URI_DEVICE_PATH*) TempDevicePath;\r
+      //\r
+      // UEFI Spec doesn't require the URI to be a NULL-terminated string\r
+      // So we allocate a new buffer and always append a '\0' to it.\r
+      //\r
+      UriStrLength = DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
+      if (UriStrLength == 0) {\r
+        //\r
+        // return a NULL UriAddress if it's a empty URI device path node.\r
+        //\r
+        break;\r
+      }\r
+      Uri = AllocatePool (UriStrLength + 1);\r
+      if (Uri == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      CopyMem (Uri, UriDevicePath->Uri, DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL));\r
+      Uri[DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL)] = '\0';\r
+\r
+      *UriAddress = Uri;\r
+    }\r
+    TempDevicePath = NextDevicePathNode (TempDevicePath);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r