Looks good!
Reviewed-by: Jiaxin Wu <jiaxin...@intel.com>

-----Original Message-----
From: Zhang, Lubo 
Sent: Tuesday, February 2, 2016 2:52 PM
To: edk2-devel@lists.01.org
Cc: Fu, Siyuan; Ye, Ting; Wu, Jiaxin
Subject: [PATCH v4] NetworkPkg:Add a new error status code EFI_HTTP_ERROR

v4:
* Update macro HTTP_ERROR_STATUS to HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
Update copyright year.
When the Error Status of ResponseData returned from HttpIoRecvResponse function 
during the Http HEAD method, it should also return error status to Load file 
protocol.

Cc: Fu Siyuan <siyuan...@intel.com>
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>
---
 NetworkPkg/HttpBootDxe/HttpBootClient.c  | 10 ++++++++--  
NetworkPkg/HttpBootDxe/HttpBootSupport.c | 18 +++++-------------  
NetworkPkg/HttpBootDxe/HttpBootSupport.h | 14 +++++++++++++-
 NetworkPkg/HttpDxe/HttpImpl.c            | 19 +++++++++++++++----
 NetworkPkg/HttpDxe/HttpImpl.h            |  4 +++-
 NetworkPkg/HttpDxe/HttpProto.h           |  4 +++-
 6 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c 
b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index f0817e9..dd835c4 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -1,9 +1,9 @@
 /** @file
   Implementation of the boot file download function.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available 
under  the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.                                
          
     
@@ -715,10 +715,11 @@ HttpBootGetBootFile (
   IN OUT UINTN                    *BufferSize,
      OUT UINT8                    *Buffer
   )
 {
   EFI_STATUS                 Status;
+  EFI_HTTP_STATUS_CODE       StatusCode;
   CHAR8                      *HostName;
   EFI_HTTP_REQUEST_DATA      *RequestData;
   HTTP_IO_RESPONSE_DATA      *ResponseData;
   HTTP_IO_RESPONSE_DATA      ResponseBody;
   HTTP_IO                    *HttpIo;
@@ -892,11 +893,16 @@ HttpBootGetBootFile (
   Status = HttpIoRecvResponse (
              &Private->HttpIo,
              TRUE,
              ResponseData
              );
-  if (EFI_ERROR (Status)) {
+  if (EFI_ERROR (Status) || EFI_ERROR (ResponseData->Status)) {
+    if (EFI_ERROR (ResponseData->Status)) {
+      StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;
+      HttpBootPrintErrorMessage (StatusCode);
+      Status = ResponseData->Status;
+    }
     goto ERROR_5;
   }
 
   //
   // 3.2 Cache the response header.
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c 
b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index f9bbe4b..db2af78 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -1,9 +1,9 @@
 /** @file
   Support functions implementation for UEFI HTTP boot driver.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available 
under  the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.                                
          
     
@@ -928,11 +928,10 @@ HttpIoRecvResponse (
      OUT  HTTP_IO_RESPONSE_DATA    *ResponseData
   )
 {
   EFI_STATUS                 Status;
   EFI_HTTP_PROTOCOL          *Http;
-  EFI_HTTP_STATUS_CODE       StatusCode;
 
   if (HttpIo == NULL || HttpIo->Http == NULL || ResponseData == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -969,19 +968,12 @@ HttpIoRecvResponse (
   }
 
   //
   // Store the received data into the wrapper.
   //
-  Status = HttpIo->RspToken.Status;
-  if (!EFI_ERROR (Status)) {
-    ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;
-    ResponseData->Headers     = HttpIo->RspToken.Message->Headers;
-    ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;
-  }
-
-  if (RecvMsgHeader) {
-    StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;
-    HttpBootPrintErrorMessage (StatusCode);
-  }
+  ResponseData->Status = HttpIo->RspToken.Status;  
+ ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;
+  ResponseData->Headers     = HttpIo->RspToken.Message->Headers;
+  ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;
 
   return Status;
 }
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h 
b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
index 2eba14e..8e0fc37 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
@@ -1,9 +1,9 @@
 /** @file
   Support functions declaration for UEFI HTTP boot driver.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available 
under  the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.                                
          
     
@@ -79,10 +79,21 @@ HttpBootShowIp4Addr (  VOID  HttpBootShowIp6Addr (
   IN EFI_IPv6_ADDRESS   *Ip
   );
 
+/**
+  This function is to display the HTTP error status.
+
+  @param[in]      StatusCode      The status code value in HTTP message.
+
+**/
+VOID
+HttpBootPrintErrorMessage (
+  EFI_HTTP_STATUS_CODE            StatusCode
+  );
+
 //
 // A wrapper structure to hold the HTTP headers.
 //
 typedef struct {
   UINTN                       MaxHeaderCount;
@@ -194,10 +205,11 @@ typedef struct {
   EFI_HTTP_RESPONSE_DATA      Response;
   UINTN                       HeaderCount;
   EFI_HTTP_HEADER             *Headers;
   UINTN                       BodyLength;
   CHAR8                       *Body;
+  EFI_STATUS                  Status;
 } HTTP_IO_RESPONSE_DATA;
 
 /**
   Retrieve the host address using the EFI_DNS6_PROTOCOL.
 
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c 
index b46f0ae..a068cfb 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -1,9 +1,9 @@
 /** @file
   Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
 
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2016, Intel Corporation. All rights 
+ reserved.<BR>
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at @@ -974,11 +974,11 @@ HttpResponseWorker (
 
     FreePool (HttpHeaders);
     HttpHeaders = NULL;
     
     HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);
-
+    HttpInstance->StatusCode = StatusCode;
     //
     // Init message-body parser by header information.  
     //
     Status = EFI_NOT_READY;
     ValueInItem = NULL;
@@ -1109,11 +1109,17 @@ HttpResponseWorker (
 Exit:
   Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);
   if (Item != NULL) {
     NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);
   }
-  Token->Status = Status;
+
+  if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {
+    Token->Status = EFI_HTTP_ERROR;
+  } else {
+    Token->Status = Status;
+  }
+
   gBS->SignalEvent (Token->Event);
   HttpCloseTcpRxEvent (Wrap);
   FreePool (Wrap);
   return Status;
 
@@ -1134,11 +1140,16 @@ Error:
   if (HttpInstance->CacheBody != NULL) {
     FreePool (HttpInstance->CacheBody);
     HttpInstance->CacheBody = NULL;
   }
 
-  Token->Status = Status;
+  if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {
+    Token->Status = EFI_HTTP_ERROR;
+  } else {
+    Token->Status = Status;
+  }
+
   gBS->SignalEvent (Token->Event);
 
   return Status;  
 
 }
diff --git a/NetworkPkg/HttpDxe/HttpImpl.h b/NetworkPkg/HttpDxe/HttpImpl.h 
index bfbaecc..3822842 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.h
+++ b/NetworkPkg/HttpDxe/HttpImpl.h
@@ -1,9 +1,9 @@
 /** @file
   The header files of implementation of EFI_HTTP_PROTOCOL protocol interfaces.
 
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2016, Intel Corporation. All rights 
+ reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -21,10 +21,12 @@
 #define HTTP_CRLF_STR            "\r\n"
 #define HTTP_VERSION_STR         "HTTP/1.1"
 #define HTTP_VERSION_CRLF_STR    " HTTP/1.1\r\n"
 #define HTTP_GET_STR             "GET "
 #define HTTP_HEAD_STR            "HEAD "
+#define HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE         300
+
 //
 // Connect method has maximum length according to EFI_HTTP_METHOD defined in  
// UEFI2.5 spec so use this.
 //
 #define HTTP_MAXIMUM_METHOD_LEN  sizeof ("CONNECT") diff --git 
a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h index 
e43a2dc..3a57494 100644
--- a/NetworkPkg/HttpDxe/HttpProto.h
+++ b/NetworkPkg/HttpDxe/HttpProto.h
@@ -1,9 +1,9 @@
 /** @file
   The header files of miscellaneous routines for HttpDxe driver.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available 
under the terms and conditions of the BSD License  which accompanies this 
distribution.  The full text of the license may be found at  
http://opensource.org/licenses/bsd-license.php
 
@@ -88,10 +88,12 @@ typedef struct _HTTP_PROTOCOL {
   HTTP_SERVICE                  *Service;
   LIST_ENTRY                    Link;   // Link to all HTTP instance from the 
service.
   BOOLEAN                       InDestroy;
   INTN                          State;
 
+  UINTN                         StatusCode;
+
   EFI_HANDLE                    Tcp4ChildHandle;
   EFI_TCP4_PROTOCOL             *Tcp4;
   EFI_TCP4_CONFIG_DATA          Tcp4CfgData;
   EFI_TCP4_OPTION               Tcp4Option;
 
--
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