summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNagaraj Hegde <nagaraj-p.hegde@hpe.com>2016-04-04 18:09:27 +0800
committerFu Siyuan <siyuan.fu@intel.com>2016-04-27 10:43:08 +0800
commite297a0a498139cedca232aff69c41c8996151f0b (patch)
treef88024dbac07681cf9197642dd5a0b3f2427857b
parent0aa0beca37c686c028da47a801b0db6c770b81e8 (diff)
downloadedk2-e297a0a498139cedca232aff69c41c8996151f0b.tar.gz
edk2-e297a0a498139cedca232aff69c41c8996151f0b.tar.bz2
edk2-e297a0a498139cedca232aff69c41c8996151f0b.zip
MdeModulePkg:DxeHttpLib: Update to DxeHttpLib API
Rename and update the logic of HttpGenRequestString API provided by DxeHttpLib. The RequestString size is returned as an argument. The user is not expected to do a AsciiStrLen anymore, and is not logical too, since request string can contain message body and using AsciiStrLen on such a string can provide truncated lengths. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Nagaraj Hegde <nagaraj-p.hegde@hpe.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
-rw-r--r--MdeModulePkg/Include/Library/HttpLib.h19
-rw-r--r--MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c43
2 files changed, 44 insertions, 18 deletions
diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/Library/HttpLib.h
index af9ab5f012..853982025c 100644
--- a/MdeModulePkg/Include/Library/HttpLib.h
+++ b/MdeModulePkg/Include/Library/HttpLib.h
@@ -417,12 +417,20 @@ HttpFreeHeaderFields (
);
/**
- Generate HTTP request string.
+ Generate HTTP request message.
- @param[in] Message Pointer to storage containing HTTP message data.
+ This function will allocate memory for the whole HTTP message and generate a
+ well formatted HTTP Request message in it, include the Request-Line, header
+ fields and also the message body. It is the caller's responsibility to free
+ the buffer returned in *RequestMsg.
+
+ @param[in] Message Pointer to the EFI_HTTP_MESSAGE structure which
+ contains the required information to generate
+ the HTTP request message.
@param[in] Url The URL of a remote host.
- @param[out] RequestString Pointer to the created HTTP request string.
+ @param[out] RequestMsg Pointer to the created HTTP request message.
NULL if any error occured.
+ @param[out] RequestMsgSize Size of the RequestMsg (in bytes).
@return EFI_SUCCESS If HTTP request string was created successfully
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@@ -431,10 +439,11 @@ HttpFreeHeaderFields (
**/
EFI_STATUS
EFIAPI
-HttpGenRequestString (
+HttpGenRequestMessage (
IN CONST EFI_HTTP_MESSAGE *Message,
IN CONST CHAR8 *Url,
- OUT CHAR8 **RequestString
+ OUT CHAR8 **RequestMsg,
+ OUT UINTN *RequestMsgSize
);
/**
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 662c40c644..8d61d0b404 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1630,12 +1630,20 @@ HttpFreeHeaderFields (
}
/**
- Generate HTTP request string.
+ Generate HTTP request message.
- @param[in] Message Pointer to storage containing HTTP message data.
+ This function will allocate memory for the whole HTTP message and generate a
+ well formatted HTTP Request message in it, include the Request-Line, header
+ fields and also the message body. It is the caller's responsibility to free
+ the buffer returned in *RequestMsg.
+
+ @param[in] Message Pointer to the EFI_HTTP_MESSAGE structure which
+ contains the required information to generate
+ the HTTP request message.
@param[in] Url The URL of a remote host.
- @param[out] RequestString Pointer to the created HTTP request string.
+ @param[out] RequestMsg Pointer to the created HTTP request message.
NULL if any error occured.
+ @param[out] RequestMsgSize Size of the RequestMsg (in bytes).
@return EFI_SUCCESS If HTTP request string was created successfully
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@@ -1644,10 +1652,11 @@ HttpFreeHeaderFields (
**/
EFI_STATUS
EFIAPI
-HttpGenRequestString (
+HttpGenRequestMessage (
IN CONST EFI_HTTP_MESSAGE *Message,
IN CONST CHAR8 *Url,
- OUT CHAR8 **Request
+ OUT CHAR8 **RequestMsg,
+ OUT UINTN *RequestMsgSize
)
{
EFI_STATUS Status;
@@ -1664,7 +1673,7 @@ HttpGenRequestString (
ASSERT (Message != NULL);
- *Request = NULL;
+ *RequestMsg = NULL;
MsgSize = 0;
Success = FALSE;
HttpHdr = NULL;
@@ -1727,13 +1736,13 @@ HttpGenRequestString (
AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
- *Request = AllocateZeroPool (MsgSize);
- if (*Request == NULL) {
+ *RequestMsg = AllocateZeroPool (MsgSize);
+ if (*RequestMsg == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
- RequestPtr = *Request;
+ RequestPtr = *RequestMsg;
//
// Construct header request
//
@@ -1793,18 +1802,26 @@ HttpGenRequestString (
RequestPtr += HttpHdrSize;
//
+ // Construct body
+ //
+ if (Message->Body != NULL) {
+ CopyMem (RequestPtr, Message->Body, Message->BodyLength);
+ RequestPtr += Message->BodyLength;
+ }
+
+ //
// Done
//
- *RequestPtr = 0;
+ (*RequestMsgSize) = (UINTN)(RequestPtr) - (UINTN)(*RequestMsg);
Success = TRUE;
Exit:
if (!Success) {
- if (*Request != NULL) {
- FreePool (*Request);
+ if (*RequestMsg != NULL) {
+ FreePool (*RequestMsg);
}
- *Request = NULL;
+ *RequestMsg = NULL;
return Status;
}