]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg:DxeHttpLib: Update to DxeHttpLib API
authorNagaraj Hegde <nagaraj-p.hegde@hpe.com>
Mon, 4 Apr 2016 10:09:27 +0000 (18:09 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Wed, 27 Apr 2016 02:43:08 +0000 (10:43 +0800)
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>
MdeModulePkg/Include/Library/HttpLib.h
MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c

index af9ab5f012c6b71e8353875bb10856ffee320bbc..853982025c25aeb215f1a1b38dc1a2372ad5a8cf 100644 (file)
@@ -417,12 +417,20 @@ HttpFreeHeaderFields (
   );\r
 \r
 /**\r
-  Generate HTTP request string.\r
+  Generate HTTP request message.\r
 \r
-  @param[in]   Message            Pointer to storage containing HTTP message data.\r
+  This function will allocate memory for the whole HTTP message and generate a\r
+  well formatted HTTP Request message in it, include the Request-Line, header\r
+  fields and also the message body. It is the caller's responsibility to free\r
+  the buffer returned in *RequestMsg.\r
+\r
+  @param[in]   Message            Pointer to the EFI_HTTP_MESSAGE structure which\r
+                                  contains the required information to generate\r
+                                  the HTTP request message.\r
   @param[in]   Url                The URL of a remote host.\r
-  @param[out]  RequestString      Pointer to the created HTTP request string.\r
+  @param[out]  RequestMsg         Pointer to the created HTTP request message.\r
                                   NULL if any error occured.\r
+  @param[out]  RequestMsgSize     Size of the RequestMsg (in bytes).\r
 \r
   @return EFI_SUCCESS             If HTTP request string was created successfully\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
@@ -431,10 +439,11 @@ HttpFreeHeaderFields (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HttpGenRequestString (\r
+HttpGenRequestMessage (\r
   IN     CONST EFI_HTTP_MESSAGE        *Message,\r
   IN     CONST CHAR8                   *Url,\r
-     OUT CHAR8                         **RequestString\r
+     OUT CHAR8                         **RequestMsg,\r
+     OUT UINTN                         *RequestMsgSize\r
   );\r
 \r
 /**\r
index 662c40c644b1e8f69f97f46915e0dff01b6ce4ea..8d61d0b40417ee92a177a1b89c3fcb4eeef0cce7 100644 (file)
@@ -1630,12 +1630,20 @@ HttpFreeHeaderFields (
 }\r
 \r
 /**\r
-  Generate HTTP request string.\r
+  Generate HTTP request message.\r
 \r
-  @param[in]   Message            Pointer to storage containing HTTP message data.\r
+  This function will allocate memory for the whole HTTP message and generate a\r
+  well formatted HTTP Request message in it, include the Request-Line, header\r
+  fields and also the message body. It is the caller's responsibility to free\r
+  the buffer returned in *RequestMsg.\r
+\r
+  @param[in]   Message            Pointer to the EFI_HTTP_MESSAGE structure which\r
+                                  contains the required information to generate\r
+                                  the HTTP request message.\r
   @param[in]   Url                The URL of a remote host.\r
-  @param[out]  RequestString      Pointer to the created HTTP request string.\r
+  @param[out]  RequestMsg         Pointer to the created HTTP request message.\r
                                   NULL if any error occured.\r
+  @param[out]  RequestMsgSize     Size of the RequestMsg (in bytes).\r
 \r
   @return EFI_SUCCESS             If HTTP request string was created successfully\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
@@ -1644,10 +1652,11 @@ HttpFreeHeaderFields (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HttpGenRequestString (\r
+HttpGenRequestMessage (\r
   IN     CONST EFI_HTTP_MESSAGE        *Message,\r
   IN     CONST CHAR8                   *Url,\r
-     OUT CHAR8                         **Request\r
+     OUT CHAR8                         **RequestMsg,\r
+     OUT UINTN                         *RequestMsgSize\r
   )\r
 {\r
   EFI_STATUS                       Status;\r
@@ -1664,7 +1673,7 @@ HttpGenRequestString (
 \r
   ASSERT (Message != NULL);\r
 \r
-  *Request = NULL;\r
+  *RequestMsg = NULL;\r
   MsgSize = 0;\r
   Success = FALSE;\r
   HttpHdr = NULL;\r
@@ -1727,13 +1736,13 @@ HttpGenRequestString (
             AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;\r
 \r
 \r
-  *Request = AllocateZeroPool (MsgSize);\r
-  if (*Request == NULL) {\r
+  *RequestMsg = AllocateZeroPool (MsgSize);\r
+  if (*RequestMsg == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Exit;\r
   }\r
 \r
-  RequestPtr = *Request;\r
+  RequestPtr = *RequestMsg;\r
   //\r
   // Construct header request\r
   //\r
@@ -1792,19 +1801,27 @@ HttpGenRequestString (
   CopyMem (RequestPtr, HttpHdr, HttpHdrSize);\r
   RequestPtr += HttpHdrSize;\r
 \r
+  //\r
+  // Construct body\r
+  //\r
+  if (Message->Body != NULL) {\r
+    CopyMem (RequestPtr, Message->Body, Message->BodyLength);\r
+    RequestPtr += Message->BodyLength;\r
+  }\r
+\r
   //\r
   // Done\r
   //\r
-  *RequestPtr = 0;\r
+  (*RequestMsgSize) = (UINTN)(RequestPtr) - (UINTN)(*RequestMsg);\r
   Success     = TRUE;\r
 \r
 Exit:\r
 \r
   if (!Success) {\r
-    if (*Request != NULL) {\r
-      FreePool (*Request);\r
+    if (*RequestMsg != NULL) {\r
+      FreePool (*RequestMsg);\r
     }\r
-    *Request = NULL;\r
+    *RequestMsg = NULL;\r
     return Status;\r
   }\r
 \r