From nobody Fri May 3 01:47:36 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1501127044612563.6847904229227; Wed, 26 Jul 2017 20:44:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CD49C21D09193; Wed, 26 Jul 2017 20:41:58 -0700 (PDT) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1B00E21D09187 for ; Wed, 26 Jul 2017 20:41:57 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2017 20:44:00 -0700 Received: from sfu5-mobl.ccr.corp.intel.com ([10.239.193.13]) by fmsmga005.fm.intel.com with ESMTP; 26 Jul 2017 20:43:59 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,418,1496127600"; d="scan'208";a="131789159" From: Fu Siyuan To: edk2-devel@lists.01.org Date: Thu, 27 Jul 2017 11:43:56 +0800 Message-Id: <20170727034356.6320-1-siyuan.fu@intel.com> X-Mailer: git-send-email 2.13.0.windows.1 Subject: [edk2] [Patch] NetworkPkg: Display HTTP redirection info to the screen if need. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" HTTP defines a set of status code for redirecting a request to a different = URI in Section 6.4 of RFC7231 and also RFC7583. This patch updates the HTTP boot driver to display the redirection info to the screen so the user would have chance to know new URI address of the HTTP boot image. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan Cc: Ye Ting Cc: Wu Jiaxin Reviewed-by: Wu Jiaxin Reviewed-by: Ye Ting =20 --- NetworkPkg/HttpBootDxe/HttpBootDxe.h | 4 ++++ NetworkPkg/HttpBootDxe/HttpBootImpl.c | 21 ++++++++++++++++++++- NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25 ++++++++++++++++++++++++- NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/= HttpBootDxe.h index 8d89b3e..4632ee2 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h @@ -179,6 +179,10 @@ struct _HTTP_BOOT_PRIVATE_DATA { UINT32 Id; EFI_HTTP_BOOT_CALLBACK_PROTOCOL *HttpBootCallback; EFI_HTTP_BOOT_CALLBACK_PROTOCOL LoadFileCallback; + + // + // Data for the default HTTP Boot callback protocol + // UINT64 FileSize; UINT64 ReceivedSize; UINT32 Percentage; diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe= /HttpBootImpl.c index 63cf396..5cfb0f4 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c @@ -1,7 +1,7 @@ /** @file The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot. =20 -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made availabl= e under=20 the terms and conditions of the BSD License that accompanies this distribu= tion. =20 @@ -665,6 +665,25 @@ HttpBootCallback ( case HttpBootHttpResponse: if (Data !=3D NULL) { HttpMessage =3D (EFI_HTTP_MESSAGE *) Data; + =20 + if (HttpMessage->Data.Response !=3D NULL) { + if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->= StatusCode)) { + // + // Server indicates the resource has been redirected to a differ= ent URL + // according to the section 6.4 of RFC7231 and the RFC 7538. + // Display the redirect information on the screen. + // + HttpHeader =3D HttpFindHeader ( + HttpMessage->HeaderCount, + HttpMessage->Headers, + HTTP_HEADER_LOCATION + ); + if (HttpHeader !=3D NULL) { + Print (L"\n HTTP ERROR: Resource Redirected.\n New Location:= %a\n", HttpHeader->FieldValue); + } + } + } + =20 HttpHeader =3D HttpFindHeader ( HttpMessage->HeaderCount, HttpMessage->Headers, diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.c index 5024f2e..6d4edfc 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c @@ -1034,7 +1034,8 @@ HttpIoRecvResponse ( HttpIo->IsRxDone =3D FALSE; } =20 - if (!EFI_ERROR (HttpIo->RspToken.Status) && HttpIo->Callback !=3D NULL) { + if ((HttpIo->Callback !=3D NULL) &&=20 + (HttpIo->RspToken.Status =3D=3D EFI_SUCCESS || HttpIo->RspToken.Stat= us =3D=3D EFI_HTTP_ERROR)) { Status =3D HttpIo->Callback ( HttpIoResponse, HttpIo->RspToken.Message, @@ -1319,3 +1320,25 @@ HttpBootRegisterRamDisk ( return Status; } =20 +/** + Indicate if the HTTP status code indicates a redirection. + =20 + @param[in] StatusCode HTTP status code from server. + + @return TRUE if it's redirection. + +**/ +BOOLEAN +HttpBootIsHttpRedirectStatusCode ( + IN EFI_HTTP_STATUS_CODE StatusCode + ) +{ + if (StatusCode =3D=3D HTTP_STATUS_301_MOVED_PERMANENTLY || + StatusCode =3D=3D HTTP_STATUS_302_FOUND || + StatusCode =3D=3D HTTP_STATUS_307_TEMPORARY_REDIRECT || + StatusCode =3D=3D HTTP_STATUS_308_PERMANENT_REDIRECT) { + return TRUE; + } + + return FALSE; +} diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.h index f2b1846..c10b2cf 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h @@ -445,4 +445,17 @@ HttpBootRegisterRamDisk ( IN VOID *Buffer, IN HTTP_BOOT_IMAGE_TYPE ImageType ); + +/** + Indicate if the HTTP status code indicates a redirection. + =20 + @param[in] StatusCode HTTP status code from server. + + @return TRUE if it's redirection. + +**/ +BOOLEAN +HttpBootIsHttpRedirectStatusCode ( + IN EFI_HTTP_STATUS_CODE StatusCode + ); #endif --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel