]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
MdeModulePkg: Add new API HttpUrlGetPath() to HttpLib.h
[mirror_edk2.git] / MdeModulePkg / Library / DxeHttpLib / DxeHttpLib.c
index 040d874063dc8f8c86de1d4d4f4eff56e6498914..49c2b9c99e92c5c29be874cf2a85eabe7d02084a 100644 (file)
@@ -2,7 +2,7 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\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\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at<BR>\r
@@ -784,6 +784,65 @@ HttpUrlGetPort (
   return  EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Get the Path from a HTTP URL.\r
+\r
+  This function will return the Path according to the Url and previous parse result,and\r
+  it is the caller's responsibility to free the buffer returned in *Path.\r
+\r
+  @param[in]    Url                The pointer to a HTTP URL string.\r
+  @param[in]    UrlParser          URL Parse result returned by NetHttpParseUrl().\r
+  @param[out]   Path               Pointer to a buffer to store the Path.\r
+\r
+  @retval EFI_SUCCESS              Successfully get the required component.\r
+  @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
+  @retval EFI_NOT_FOUND            No hostName component in the URL.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpUrlGetPath (\r
+  IN      CHAR8              *Url,\r
+  IN      VOID               *UrlParser,\r
+     OUT  CHAR8              **Path\r
+  )\r
+{\r
+  CHAR8                *PathStr;\r
+  EFI_STATUS           Status;\r
+  UINT32               ResultLength;\r
+  HTTP_URL_PARSER      *Parser;\r
+\r
+  if (Url == NULL || UrlParser == NULL || Path == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+\r
+  if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  PathStr = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PATH].Length + 1);\r
+  if (PathStr == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  Status = UriPercentDecode (\r
+             Url + Parser->FieldData[HTTP_URI_FIELD_PATH].Offset,\r
+             Parser->FieldData[HTTP_URI_FIELD_PATH].Length,\r
+             PathStr,\r
+             &ResultLength\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  PathStr[ResultLength] = '\0';\r
+  *Path = PathStr;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Release the resource of the URL parser.\r
 \r