summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFu Siyuan <siyuan.fu@intel.com>2016-02-29 13:51:02 +0800
committerFu Siyuan <siyuan.fu@intel.com>2016-03-01 10:41:45 +0800
commit6796629dbb5a69d5dd70304f8760fd532bff5c5f (patch)
tree2b4a5fd0bcd7d4dd11069862845dbbf14adf7983
parentcb1d0668a5e7554c7250581c47f69434674c7cbe (diff)
downloadedk2-6796629dbb5a69d5dd70304f8760fd532bff5c5f.zip
edk2-6796629dbb5a69d5dd70304f8760fd532bff5c5f.tar.gz
edk2-6796629dbb5a69d5dd70304f8760fd532bff5c5f.tar.bz2
MdeModulePkg: Add new API HttpUrlGetPath() to HttpLib.h
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>
-rw-r--r--MdeModulePkg/Include/Library/HttpLib.h26
-rw-r--r--MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c61
2 files changed, 85 insertions, 2 deletions
diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/Library/HttpLib.h
index ce5a839..cd97b64 100644
--- a/MdeModulePkg/Include/Library/HttpLib.h
+++ b/MdeModulePkg/Include/Library/HttpLib.h
@@ -2,7 +2,7 @@
This library is used to share code between UEFI network stack modules.
It provides the helper routines to parse the HTTP message byte stream.
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at<BR>
@@ -164,6 +164,30 @@ HttpUrlGetPort (
);
/**
+ Get the Path from a HTTP URL.
+
+ This function will return the Path according to the Url and previous parse result,and
+ it is the caller's responsibility to free the buffer returned in *Path.
+
+ @param[in] Url The pointer to a HTTP URL string.
+ @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
+ @param[out] Path Pointer to a buffer to store the Path.
+
+ @retval EFI_SUCCESS Successfully get the required component.
+ @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
+ @retval EFI_NOT_FOUND No hostName component in the URL.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+EFIAPI
+HttpUrlGetPath (
+ IN CHAR8 *Url,
+ IN VOID *UrlParser,
+ OUT CHAR8 **Path
+ );
+
+/**
Release the resource of the URL parser.
@param[in] UrlParser Pointer to the parser.
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 040d874..49c2b9c 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -2,7 +2,7 @@
This library is used to share code between UEFI network stack modules.
It provides the helper routines to parse the HTTP message byte stream.
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at<BR>
@@ -785,6 +785,65 @@ HttpUrlGetPort (
}
/**
+ Get the Path from a HTTP URL.
+
+ This function will return the Path according to the Url and previous parse result,and
+ it is the caller's responsibility to free the buffer returned in *Path.
+
+ @param[in] Url The pointer to a HTTP URL string.
+ @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
+ @param[out] Path Pointer to a buffer to store the Path.
+
+ @retval EFI_SUCCESS Successfully get the required component.
+ @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
+ @retval EFI_NOT_FOUND No hostName component in the URL.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+EFIAPI
+HttpUrlGetPath (
+ IN CHAR8 *Url,
+ IN VOID *UrlParser,
+ OUT CHAR8 **Path
+ )
+{
+ CHAR8 *PathStr;
+ EFI_STATUS Status;
+ UINT32 ResultLength;
+ HTTP_URL_PARSER *Parser;
+
+ if (Url == NULL || UrlParser == NULL || Path == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Parser = (HTTP_URL_PARSER*) UrlParser;
+
+ if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ PathStr = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PATH].Length + 1);
+ if (PathStr == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = UriPercentDecode (
+ Url + Parser->FieldData[HTTP_URI_FIELD_PATH].Offset,
+ Parser->FieldData[HTTP_URI_FIELD_PATH].Length,
+ PathStr,
+ &ResultLength
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ PathStr[ResultLength] = '\0';
+ *Path = PathStr;
+ return EFI_SUCCESS;
+}
+
+/**
Release the resource of the URL parser.
@param[in] UrlParser Pointer to the parser.