Got your opinion, I will modify it later, thanks 

-----Original Message-----
From: Ye, Ting 
Sent: Tuesday, August 11, 2015 1:33 PM
To: Zhang, Lubo; edk2-devel@lists.01.org
Cc: Wu, Jiaxin
Subject: RE: [patch] MdeModulePkg: HttpLib BodyParseComplete Event should 
indicate the end of message body

I suggest to update the comments below "The last chunk has been parsed, then 
need to decide last message is Trailer or CRLF", in order to make it easier for 
user to understand the code logic. Other parts are good to me.

Reviewed-by: Ye Ting <ting...@intel.com> 

-----Original Message-----
From: Zhang, Lubo 
Sent: Monday, August 10, 2015 9:20 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting; Wu, Jiaxin
Subject: [patch] MdeModulePkg: HttpLib BodyParseComplete Event should indicate 
the end of message body

In HttpLib, the Event BodyParseComplete should return to the callback function 
when the whole message body has been parsed

Cc: Ye Ting<ting...@intel.com>
CC: Wu Jiaxin <jiaxin...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zh...@intel.com>
---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 44 ++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c 
b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 3b0d9c9..3b9048e 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -816,10 +816,13 @@ typedef enum {
   BodyParserChunkSizeEndCR,
   BodyParserChunkExtStart,
   BodyParserChunkDataStart,
   BodyParserChunkDataEnd,
   BodyParserChunkDataEndCR,
+  BodyParserTrailer,
+  BodyParserLastCRLF,
+  BodyParserLastCRLFEnd,
   BodyParserComplete,
   BodyParserStateMax
 } HTTP_BODY_PARSE_STATE;
 
 typedef struct {
@@ -1210,25 +1213,48 @@ HttpParseMessageBody (
     case BodyParserChunkSizeEndCR:
       if (*Char != '\n') {
         Parser->State = BodyParserStateMax;
         break;
       }
+      Char++;
+      if (Parser->CurrentChunkSize == 0) {
+        //
+       // The last chunk has been parsed, then need to decide last message is 
Trailer or CRLF.
+       //          
+         Parser->ContentLengthIsValid = TRUE;
+         Parser->State = BodyParserLastCRLF;
+         break;
+      }
       Parser->State = BodyParserChunkDataStart;
       Parser->CurrentChunkParsedSize = 0;
+      break;
+    case BodyParserLastCRLF:
+       if (*Char == '\r'){
+          Char++;
+          Parser->State = BodyParserLastCRLFEnd;
+          break;
+         } else {
+            Parser->State = BodyParserTrailer;
+            break;
+         }
+    case BodyParserLastCRLFEnd:
+      if (*Char == '\n'){
+          Parser->State = BodyParserComplete;
+          break;
+       } else {
+          Parser->State = BodyParserStateMax;
+          break;
+       }
+    case BodyParserTrailer:
+      if (*Char == '\r') {
+        Parser->State = BodyParserChunkSizeEndCR;
+      }
       Char++;
       break;
+      
 
     case BodyParserChunkDataStart:
-      if (Parser->CurrentChunkSize == 0) {
-        //
-        // This is the last chunk, the trailer header is unsupported.
-        //
-        Parser->ContentLengthIsValid = TRUE;
-        Parser->State = BodyParserComplete;
-        break;
-      }
-      
       //
       // First byte of chunk-data, the chunk data also might be truncated.
       //
       RemainderLengthInThis = BodyLength - (Char - Body);
       LengthForCallback = MIN (Parser->CurrentChunkSize - 
Parser->CurrentChunkParsedSize, RemainderLengthInThis);
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to