]> 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 db2af780a10a6d00895f9b6acaa9ac3bce0321b4..f30d9f7fb0db7475f2293ac6cb4f4d48219dae94 100644 (file)
@@ -977,3 +977,66 @@ HttpIoRecvResponse (
 \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
+  @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
+  *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