public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jiaxin Wu <jiaxin.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>, Fu Siyuan <siyuan.fu@intel.com>,
	Wang Fan <fan.wang@intel.com>, Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch 5/5] MdeModulePkg/DxeHttpLib: Refine some coding style.
Date: Tue, 26 Dec 2017 09:33:49 +0800	[thread overview]
Message-ID: <1514252029-12720-6-git-send-email-jiaxin.wu@intel.com> (raw)
In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com>

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Include/Library/HttpLib.h       |   4 +-
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 118 +++++++++++++--------------
 2 files changed, 60 insertions(+), 62 deletions(-)

diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/Library/HttpLib.h
index 285a831..9975aea 100644
--- a/MdeModulePkg/Include/Library/HttpLib.h
+++ b/MdeModulePkg/Include/Library/HttpLib.h
@@ -432,13 +432,13 @@ HttpFreeHeaderFields (
   @param[in]   Url                The URL of a remote host.
   @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_SUCCESS             If HTTP request string was created successfully.
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.
-  @retval EFI_INVALID_PARAMETER   The input arguments are invalid
+  @retval EFI_INVALID_PARAMETER   The input arguments are invalid.
 
 **/
 EFI_STATUS
 EFIAPI
 HttpGenRequestMessage (
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 327ca9e..4e5cf84 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -53,11 +53,12 @@ UriPercentDecode (
   Index = 0;
   Offset = 0;
   HexStr[2] = '\0';
   while (Index < BufferLength) {
     if (Buffer[Index] == '%') {
-      if (Index + 1 >= BufferLength || Index + 2 >= BufferLength || !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) {
+      if (Index + 1 >= BufferLength || Index + 2 >= BufferLength || 
+          !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) {
         return EFI_INVALID_PARAMETER;
       }
       HexStr[0] = Buffer[Index+1];
       HexStr[1] = Buffer[Index+2];
       ResultBuffer[Offset] = (CHAR8) AsciiStrHexToUintn (HexStr);
@@ -506,11 +507,11 @@ HttpUrlGetHostName (
 
   if (Url == NULL || UrlParser == NULL || HostName == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_URL_PARSER*) UrlParser;
+  Parser = (HTTP_URL_PARSER *) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -566,11 +567,11 @@ HttpUrlGetIp4 (
   
   if (Url == NULL || UrlParser == NULL || Ip4Address == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_URL_PARSER*) UrlParser;
+  Parser = (HTTP_URL_PARSER *) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -629,11 +630,11 @@ HttpUrlGetIp6 (
   
   if (Url == NULL || UrlParser == NULL || Ip6Address == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_URL_PARSER*) UrlParser;
+  Parser = (HTTP_URL_PARSER *) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -694,25 +695,25 @@ HttpUrlGetPort (
   IN      CHAR8              *Url,
   IN      VOID               *UrlParser,
      OUT  UINT16             *Port
   )
 {
-  CHAR8         *PortString;
-  EFI_STATUS    Status;
-  UINTN         Index;
-  UINTN         Data;
-  UINT32        ResultLength;
+  CHAR8                *PortString;
+  EFI_STATUS           Status;
+  UINTN                Index;
+  UINTN                Data;
+  UINT32               ResultLength;
   HTTP_URL_PARSER      *Parser;
 
   if (Url == NULL || UrlParser == NULL || Port == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
   *Port = 0;
   Index = 0;
 
-  Parser = (HTTP_URL_PARSER*) UrlParser;
+  Parser = (HTTP_URL_PARSER *) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -786,11 +787,11 @@ HttpUrlGetPath (
 
   if (Url == NULL || UrlParser == NULL || Path == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_URL_PARSER*) UrlParser;
+  Parser = (HTTP_URL_PARSER *) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -1156,21 +1157,21 @@ HttpParseMessageBody (
 
   if (MsgParser == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_BODY_PARSER*) MsgParser;
+  Parser = (HTTP_BODY_PARSER *) MsgParser;
 
   if (Parser->IgnoreBody) {
     Parser->State = BodyParserComplete;
     if (Parser->Callback != NULL) {
       Status = Parser->Callback (
-                 BodyParseEventOnComplete,
-                 Body,
-                 0,
-                 Parser->Context
-                 );
+                         BodyParseEventOnComplete,
+                         Body,
+                         0,
+                         Parser->Context
+                         );
       if (EFI_ERROR (Status)) {
         return Status;
       }
     }
     return EFI_SUCCESS;
@@ -1198,30 +1199,30 @@ HttpParseMessageBody (
       //
       // Identity transfer-coding, just notify user to save the body data.
       //
       if (Parser->Callback != NULL) {
         Status = Parser->Callback (
-                   BodyParseEventOnData,
-                   Char,
-                   MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength),
-                   Parser->Context
-                   );
+                           BodyParseEventOnData,
+                           Char,
+                           MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength),
+                           Parser->Context
+                           );
         if (EFI_ERROR (Status)) {
           return Status;
         }
       }
       Char += MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength);
       Parser->ParsedBodyLength += MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength);
       if (Parser->ParsedBodyLength == Parser->ContentLength) {
         Parser->State = BodyParserComplete;
         if (Parser->Callback != NULL) {
           Status = Parser->Callback (
-                     BodyParseEventOnComplete,
-                     Char,
-                     0,
-                     Parser->Context
-                     );
+                             BodyParseEventOnComplete,
+                             Char,
+                             0,
+                             Parser->Context
+                             );
           if (EFI_ERROR (Status)) {
             return Status;
           }
         }
       }
@@ -1302,15 +1303,15 @@ HttpParseMessageBody (
       if (*Char == '\n') {
         Parser->State = BodyParserComplete;
         Char++;
         if (Parser->Callback != NULL) {
           Status = Parser->Callback (
-                     BodyParseEventOnComplete,
-                     Char,
-                     0,
-                     Parser->Context
-                     );
+                             BodyParseEventOnComplete,
+                             Char,
+                             0,
+                             Parser->Context
+                             );
           if (EFI_ERROR (Status)) {
             return Status;
           }
         }
         break;
@@ -1332,15 +1333,15 @@ HttpParseMessageBody (
       //
       RemainderLengthInThis = BodyLength - (Char - Body);
       LengthForCallback = MIN (Parser->CurrentChunkSize - Parser->CurrentChunkParsedSize, RemainderLengthInThis);
       if (Parser->Callback != NULL) {
         Status = Parser->Callback (
-                   BodyParseEventOnData,
-                   Char,
-                   LengthForCallback,
-                   Parser->Context
-                   );
+                           BodyParseEventOnData,
+                           Char,
+                           LengthForCallback,
+                           Parser->Context
+                           );
         if (EFI_ERROR (Status)) {
           return Status;
         }
       }
       Char += LengthForCallback;
@@ -1401,11 +1402,11 @@ HttpIsMessageComplete (
 
   if (MsgParser == NULL) {
     return FALSE;
   }
 
-  Parser = (HTTP_BODY_PARSER*) MsgParser;
+  Parser = (HTTP_BODY_PARSER *) MsgParser;
 
   if (Parser->State == BodyParserComplete) {
     return TRUE;
   }
   return FALSE;
@@ -1435,11 +1436,11 @@ HttpGetEntityLength (
 
   if (MsgParser == NULL || ContentLength == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  Parser = (HTTP_BODY_PARSER*) MsgParser;
+  Parser = (HTTP_BODY_PARSER *) MsgParser;
 
   if (!Parser->ContentLengthIsValid) {
     return EFI_NOT_READY;
   }
 
@@ -1473,11 +1474,10 @@ HttpFreeMsgParser (
   @return     Pointer to the next string.
   @return     NULL if not find or String is NULL.
 
 **/
 CHAR8 *
-EFIAPI
 AsciiStrGetNextToken (
   IN CONST CHAR8 *String,
   IN       CHAR8 Separator
   )
 {
@@ -1618,20 +1618,20 @@ HttpGetFieldNameAndValue (
   while (TRUE) {
     if (*FieldValueStr == ' ' || *FieldValueStr == '\t') {
       //
       // Boundary condition check. 
       //
-      if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 1) {
+      if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 1) {
         return NULL;  
       }
       
       FieldValueStr ++;
     } else if (*FieldValueStr == '\r') {
       //
       // Boundary condition check. 
       //
-      if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 3) {
+      if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 3) {
         return NULL;  
       }
 
       if (*(FieldValueStr + 1) == '\n' && (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) {
         FieldValueStr = FieldValueStr + 3;
@@ -1713,13 +1713,13 @@ HttpFreeHeaderFields (
   @param[in]   Url                The URL of a remote host.
   @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_SUCCESS             If HTTP request string was created successfully.
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.
-  @retval EFI_INVALID_PARAMETER   The input arguments are invalid
+  @retval EFI_INVALID_PARAMETER   The input arguments are invalid.
 
 **/
 EFI_STATUS
 EFIAPI
 HttpGenRequestMessage (
@@ -1767,11 +1767,11 @@ HttpGenRequestMessage (
     // Locate the HTTP_UTILITIES protocol.
     //
     Status = gBS->LocateProtocol (
                     &gEfiHttpUtilitiesProtocolGuid,
                     NULL,
-                    (VOID **)&HttpUtilitiesProtocol
+                    (VOID **) &HttpUtilitiesProtocol
                     );
 
     if (EFI_ERROR (Status)) {
       DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Status = %r.\n", Status));
       return Status;
@@ -1791,24 +1791,22 @@ HttpGenRequestMessage (
 
     //
     // Build raw HTTP Headers
     //
     Status = HttpUtilitiesProtocol->Build (
-                HttpUtilitiesProtocol,
-                0,
-                NULL,
-                0,
-                NULL,
-                Message->HeaderCount,
-                AppendList,
-                &HttpHdrSize,
-                &HttpHdr
-                );
-
-    if (AppendList != NULL) {
-      FreePool (AppendList);
-    }
+                                      HttpUtilitiesProtocol,
+                                      0,
+                                      NULL,
+                                      0,
+                                      NULL,
+                                      Message->HeaderCount,
+                                      AppendList,
+                                      &HttpHdrSize,
+                                      &HttpHdr
+                                      );
+
+    FreePool (AppendList);
 
     if (EFI_ERROR (Status) || HttpHdr == NULL){
       return Status;
     }
   }
@@ -1834,11 +1832,11 @@ HttpGenRequestMessage (
   MsgSize += Message->BodyLength;
 
   //
   // memory for the string that needs to be sent to TCP
   //
-  *RequestMsg           = NULL;
+  *RequestMsg = NULL;
   *RequestMsg = AllocateZeroPool (MsgSize);
   if (*RequestMsg == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
     goto Exit;
   }
-- 
1.9.5.msysgit.1



  parent reply	other threads:[~2017-12-26  1:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26  1:33 [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Jiaxin Wu
2017-12-26  1:33 ` [Patch 1/5] MdeModulePkg/DxeHttpLib: Add boundary condition check Jiaxin Wu
2017-12-26  1:56   ` Gary Lin
2017-12-26  2:21     ` Wu, Jiaxin
2017-12-26  1:33 ` [Patch 2/5] MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen Jiaxin Wu
2017-12-26  1:33 ` [Patch 3/5] MdeModulePkg/DxeHttpLib: Check the input parameters for some APIs Jiaxin Wu
2017-12-26  1:33 ` [Patch 4/5] MdeModulePkg/DxeHttpLib: Correct some return Status Jiaxin Wu
2017-12-26  1:33 ` Jiaxin Wu [this message]
2017-12-26  1:40 ` [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Fu, Siyuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514252029-12720-6-git-send-email-jiaxin.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox