]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add new API HttpUrlGetPath() to HttpLib.h
authorFu Siyuan <siyuan.fu@intel.com>
Mon, 29 Feb 2016 05:51:02 +0000 (13:51 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Tue, 1 Mar 2016 02:41:45 +0000 (10:41 +0800)
This patch is to add a new interface to get the "Path" component according to
the URI parse result, it would be helpful for the library user to extract the
file path value in a URI.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdeModulePkg/Include/Library/HttpLib.h
MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c

index ce5a839c9b6009c86bc32dfe0a03744d88099624..cd97b644f1e9a975c3da58c62e519e42c0a958cb 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
   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
 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
@@ -163,6 +163,30 @@ HttpUrlGetPort (
      OUT  UINT16             *Port\r
   );\r
 \r
      OUT  UINT16             *Port\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
 /**\r
   Release the resource of the URL parser.\r
 \r
 /**\r
   Release the resource of the URL parser.\r
 \r
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
   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
 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
   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
 /**\r
   Release the resource of the URL parser.\r
 \r