summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Lubo <lubo.zhang@intel.com>2015-08-12 12:44:31 +0000
committerluobozhang <luobozhang@Edk2>2015-08-12 12:44:31 +0000
commit0cd1ecea673160417e30e46009a54d361a131235 (patch)
treec008966e3dc63bcee9d7cd26917c32f8225534e8
parent64ffb95441efad61aac023942f26b5c7f0868396 (diff)
downloadedk2-0cd1ecea673160417e30e46009a54d361a131235.tar.gz
edk2-0cd1ecea673160417e30e46009a54d361a131235.tar.bz2
edk2-0cd1ecea673160417e30e46009a54d361a131235.zip
MdeModulePkg: Add codes to support trailer parse in HttpLib.
In HttpLib, the Event BodyParseComplete should return to the callback function when the whole message body has been parsed including the trailer if it has. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo <lubo.zhang@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18213 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 3b0d9c9604..4a76bff780 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -818,6 +818,9 @@ typedef enum {
BodyParserChunkDataStart,
BodyParserChunkDataEnd,
BodyParserChunkDataEndCR,
+ BodyParserTrailer,
+ BodyParserLastCRLF,
+ BodyParserLastCRLFEnd,
BodyParserComplete,
BodyParserStateMax
} HTTP_BODY_PARSE_STATE;
@@ -1212,21 +1215,52 @@ HttpParseMessageBody (
Parser->State = BodyParserStateMax;
break;
}
- Parser->State = BodyParserChunkDataStart;
- Parser->CurrentChunkParsedSize = 0;
Char++;
- break;
-
- case BodyParserChunkDataStart:
if (Parser->CurrentChunkSize == 0) {
//
- // This is the last chunk, the trailer header is unsupported.
+ // The last chunk has been parsed and now assumed the state
+ // of HttpBodyParse is ParserLastCRLF. So it need to decide
+ // whether the rest message is trailer or last CRLF in the next round.
//
Parser->ContentLengthIsValid = TRUE;
+ Parser->State = BodyParserLastCRLF;
+ break;
+ }
+ Parser->State = BodyParserChunkDataStart;
+ Parser->CurrentChunkParsedSize = 0;
+ break;
+
+ case BodyParserLastCRLF:
+ //
+ // Judge the byte is belong to the Last CRLF or trailer, and then
+ // configure the state of HttpBodyParse to corresponding state.
+ //
+ 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:
//
// First byte of chunk-data, the chunk data also might be truncated.
//