From nobody Sat Apr 27 21:08:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69206+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69206+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1608303355; cv=none; d=zohomail.com; s=zohoarc; b=lzFWObnXMYABvnSpVsc4s2p7lWhbYs2cwrqJXJsDfqaaae4ezzkhkCxQa69FTkEvaWVHg/LGHinLsMcGPyh00YsuXCS1R7QDI4BpcTBkhOgdCJonjPU2xTKq/O/PbVrtpSdxFoccRGpYeBj1bD8mkOmyLMTV/zV3S5RQp+MH0gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608303355; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=clwXMUNoEykoqu1sXSkrWLlzKqmA84Ls72HMxj9wvyg=; b=j6JZ96z1td6AfXLLJUrCmKCZwbMTf24X43808614klHbKUSgCOJ2qf9jerRP9RUfbHWCpWoE6KXTvMLuljRQjxXTuvt+FAvcKcj2pDD9Ds8t3Ia4LvgdJuh9VfSrwRlPwc5M8qzCpBTcv7cZ/Zv3cWwBrELQ5Y12Lh+dnckBMZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69206+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608303355516283.754673841343; Fri, 18 Dec 2020 06:55:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0CgmYY1788612xefXkfJrSOW; Fri, 18 Dec 2020 06:55:55 -0800 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web10.11228.1608303348537051053 for ; Fri, 18 Dec 2020 06:55:48 -0800 X-Received: from pps.filterd (m0134421.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BIEr2KI016539; Fri, 18 Dec 2020 14:55:47 GMT X-Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) by mx0b-002e3701.pphosted.com with ESMTP id 35g9yn0w71-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Dec 2020 14:55:47 +0000 X-Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g9t5008.houston.hpe.com (Postfix) with ESMTP id 4838268; Fri, 18 Dec 2020 14:55:46 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 671B047; Fri, 18 Dec 2020 14:55:44 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Maciej Rabeda , Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao , Nickle Wang , Peter O'Hanley Subject: [edk2-devel] [PATCH] NetworkPkg/DxeHttpLib: Migrate HTTP header manipulation APIs Date: Fri, 18 Dec 2020 10:39:31 +0800 Message-Id: <20201218023931.20445-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: NaLzyF2Gz948Dm3vTdIQQH8Zx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608303355; bh=uWNckAkm74fZiuPrCQ2u+7Fdt0LOyYSYVWHS5BfHpIw=; h=Cc:Date:From:Reply-To:Subject:To; b=HsKApvN/oCIRZ3VVHXXcPOzWdoWmLBne7deMAF6qUAUCOqwtVJ6fzjsr6RdavJL2cBX ommOCbJXiYQvJojivFdcp4eOuHQGmfGi1vF/AXAkX3VsC44JnUx1XbDZBRpZnEaHVHh0G NUcnJAHXvnWU2udin4TZmqV7l6za945ndRQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move HTTP header manipulation functions to DxeHttpLib from HttpBootSupport.c. These general functions are used by both Http BOOT and RedfishLib (patches will be sent later). Signed-off-by: Abner Chang Cc: Maciej Rabeda Cc: Jiaxin Wu Cc: Siyuan Fu Cc: Fan Wang Cc: Jiewen Yao Cc: Nickle Wang Cc: Peter O'Hanley --- NetworkPkg/HttpBootDxe/HttpBootSupport.h | 53 -------- NetworkPkg/Include/Library/HttpLib.h | 53 ++++++++ NetworkPkg/HttpBootDxe/HttpBootClient.c | 10 +- NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c | 135 ++++++++++++++++++++- 4 files changed, 192 insertions(+), 59 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.h index 1a2d32dd5a..c2ac1b785a 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h @@ -87,59 +87,6 @@ HttpBootPrintErrorMessage ( EFI_HTTP_STATUS_CODE StatusCode ); =20 -// -// A wrapper structure to hold the HTTP headers. -// -typedef struct { - UINTN MaxHeaderCount; - UINTN HeaderCount; - EFI_HTTP_HEADER *Headers; -} HTTP_IO_HEADER; - -/** - Create a HTTP_IO_HEADER to hold the HTTP header items. - - @param[in] MaxHeaderCount The maximum number of HTTP header in = this holder. - - @return A pointer of the HTTP header holder or NULL if failed. - -**/ -HTTP_IO_HEADER * -HttpBootCreateHeader ( - IN UINTN MaxHeaderCount - ); - -/** - Destroy the HTTP_IO_HEADER and release the resources. - - @param[in] HttpIoHeader Point to the HTTP header holder to be des= troyed. - -**/ -VOID -HttpBootFreeHeader ( - IN HTTP_IO_HEADER *HttpIoHeader - ); - -/** - Set or update a HTTP header with the field name and corresponding value. - - @param[in] HttpIoHeader Point to the HTTP header holder. - @param[in] FieldName Null terminated string which describes a = field name. - @param[in] FieldValue Null terminated string which describes th= e corresponding field value. - - @retval EFI_SUCCESS The HTTP header has been set or updated. - @retval EFI_INVALID_PARAMETER Any input parameter is invalid. - @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the ope= ration. - @retval Other Unexpected error happened. - -**/ -EFI_STATUS -HttpBootSetHeader ( - IN HTTP_IO_HEADER *HttpIoHeader, - IN CHAR8 *FieldName, - IN CHAR8 *FieldValue - ); - /** Retrieve the host address using the EFI_DNS6_PROTOCOL. =20 diff --git a/NetworkPkg/Include/Library/HttpLib.h b/NetworkPkg/Include/Libr= ary/HttpLib.h index a906126b3d..2c3367fb01 100644 --- a/NetworkPkg/Include/Library/HttpLib.h +++ b/NetworkPkg/Include/Library/HttpLib.h @@ -476,6 +476,59 @@ HttpIsValidHttpHeader ( IN CHAR8 *FieldName ); =20 +// +// A wrapper structure to hold the HTTP headers. +// +typedef struct { + UINTN MaxHeaderCount; + UINTN HeaderCount; + EFI_HTTP_HEADER *Headers; +} HTTP_IO_HEADER; + + +/** + Create a HTTP_IO_HEADER to hold the HTTP header items. + + @param[in] MaxHeaderCount The maximun number of HTTP header in = this holder. + + @return A pointer of the HTTP header holder or NULL if failed. + +**/ +HTTP_IO_HEADER * +HttpIoCreateHeader ( + UINTN MaxHeaderCount + ); + +/** + Destroy the HTTP_IO_HEADER and release the resources. + + @param[in] HttpIoHeader Point to the HTTP header holder to be des= troyed. + +**/ +VOID +HttpIoFreeHeader ( + IN HTTP_IO_HEADER *HttpIoHeader + ); + +/** + Set or update a HTTP header with the field name and corresponding value. + + @param[in] HttpIoHeader Point to the HTTP header holder. + @param[in] FieldName Null terminated string which describes a = field name. + @param[in] FieldValue Null terminated string which describes th= e corresponding field value. + + @retval EFI_SUCCESS The HTTP header has been set or updated. + @retval EFI_INVALID_PARAMETER Any input parameter is invalid. + @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the ope= ration. + @retval Other Unexpected error happened. + +**/ +EFI_STATUS +HttpIoSetHeader ( + IN HTTP_IO_HEADER *HttpIoHeader, + IN CHAR8 *FieldName, + IN CHAR8 *FieldValue + ); =20 #endif =20 diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootD= xe/HttpBootClient.c index 30ac15889b..8f21f7766e 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -977,7 +977,7 @@ HttpBootGetBootFile ( // Accept // User-Agent // - HttpIoHeader =3D HttpBootCreateHeader (3); + HttpIoHeader =3D HttpIoCreateHeader (3); if (HttpIoHeader =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ERROR_2; @@ -995,7 +995,7 @@ HttpBootGetBootFile ( if (EFI_ERROR (Status)) { goto ERROR_3; } - Status =3D HttpBootSetHeader ( + Status =3D HttpIoSetHeader ( HttpIoHeader, HTTP_HEADER_HOST, HostName @@ -1008,7 +1008,7 @@ HttpBootGetBootFile ( // // Add HTTP header field 2: Accept // - Status =3D HttpBootSetHeader ( + Status =3D HttpIoSetHeader ( HttpIoHeader, HTTP_HEADER_ACCEPT, "*/*" @@ -1020,7 +1020,7 @@ HttpBootGetBootFile ( // // Add HTTP header field 3: User-Agent // - Status =3D HttpBootSetHeader ( + Status =3D HttpIoSetHeader ( HttpIoHeader, HTTP_HEADER_USER_AGENT, HTTP_USER_AGENT_EFI_HTTP_BOOT @@ -1291,7 +1291,7 @@ ERROR_4: FreePool (RequestData); } ERROR_3: - HttpBootFreeHeader (HttpIoHeader); + HttpIoFreeHeader (HttpIoHeader); ERROR_2: if (Cache !=3D NULL) { FreePool (Cache); diff --git a/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c b/NetworkPkg/Librar= y/DxeHttpLib/DxeHttpLib.c index daec1e0226..7354e0170f 100644 --- a/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c @@ -3,7 +3,7 @@ It provides the helper routines to parse the HTTP message byte stream. =20 Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
-(C) Copyright 2016 Hewlett Packard Enterprise Development LP
+(C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -2095,3 +2095,136 @@ HttpIsValidHttpHeader ( return TRUE; } =20 + +/** + Create a HTTP_IO_HEADER to hold the HTTP header items. + + @param[in] MaxHeaderCount The maximun number of HTTP header in = this holder. + + @return A pointer of the HTTP header holder or NULL if failed. + +**/ +HTTP_IO_HEADER * +HttpIoCreateHeader ( + UINTN MaxHeaderCount + ) +{ + HTTP_IO_HEADER *HttpIoHeader; + + if (MaxHeaderCount =3D=3D 0) { + return NULL; + } + + HttpIoHeader =3D AllocateZeroPool (sizeof (HTTP_IO_HEADER) + MaxHeaderCo= unt * sizeof (EFI_HTTP_HEADER)); + if (HttpIoHeader =3D=3D NULL) { + return NULL; + } + + HttpIoHeader->MaxHeaderCount =3D MaxHeaderCount; + HttpIoHeader->Headers =3D (EFI_HTTP_HEADER *) (HttpIoHeader + 1); + + return HttpIoHeader; +} + +/** + Destroy the HTTP_IO_HEADER and release the resources. + + @param[in] HttpIoHeader Point to the HTTP header holder to be des= troyed. + +**/ +VOID +HttpIoFreeHeader ( + IN HTTP_IO_HEADER *HttpIoHeader + ) +{ + UINTN Index; + + if (HttpIoHeader !=3D NULL) { + if (HttpIoHeader->HeaderCount !=3D 0) { + for (Index =3D 0; Index < HttpIoHeader->HeaderCount; Index++) { + FreePool (HttpIoHeader->Headers[Index].FieldName); + ZeroMem (HttpIoHeader->Headers[Index].FieldValue, AsciiStrSize (Ht= tpIoHeader->Headers[Index].FieldValue)); + FreePool (HttpIoHeader->Headers[Index].FieldValue); + } + } + FreePool (HttpIoHeader); + } +} + +/** + Set or update a HTTP header with the field name and corresponding value. + + @param[in] HttpIoHeader Point to the HTTP header holder. + @param[in] FieldName Null terminated string which describes a = field name. + @param[in] FieldValue Null terminated string which describes th= e corresponding field value. + + @retval EFI_SUCCESS The HTTP header has been set or updated. + @retval EFI_INVALID_PARAMETER Any input parameter is invalid. + @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the ope= ration. + @retval Other Unexpected error happened. + +**/ +EFI_STATUS +HttpIoSetHeader ( + IN HTTP_IO_HEADER *HttpIoHeader, + IN CHAR8 *FieldName, + IN CHAR8 *FieldValue + ) +{ + EFI_HTTP_HEADER *Header; + UINTN StrSize; + CHAR8 *NewFieldValue; + + if (HttpIoHeader =3D=3D NULL || FieldName =3D=3D NULL || FieldValue =3D= =3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Header =3D HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Head= ers, FieldName); + if (Header =3D=3D NULL) { + // + // Add a new header. + // + if (HttpIoHeader->HeaderCount >=3D HttpIoHeader->MaxHeaderCount) { + return EFI_OUT_OF_RESOURCES; + } + Header =3D &HttpIoHeader->Headers[HttpIoHeader->HeaderCount]; + + StrSize =3D AsciiStrSize (FieldName); + Header->FieldName =3D AllocatePool (StrSize); + if (Header->FieldName =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (Header->FieldName, FieldName, StrSize); + Header->FieldName[StrSize -1] =3D '\0'; + + StrSize =3D AsciiStrSize (FieldValue); + Header->FieldValue =3D AllocatePool (StrSize); + if (Header->FieldValue =3D=3D NULL) { + FreePool (Header->FieldName); + return EFI_OUT_OF_RESOURCES; + } + CopyMem (Header->FieldValue, FieldValue, StrSize); + Header->FieldValue[StrSize -1] =3D '\0'; + + HttpIoHeader->HeaderCount++; + } else { + // + // Update an existing one. + // + StrSize =3D AsciiStrSize (FieldValue); + NewFieldValue =3D AllocatePool (StrSize); + if (NewFieldValue =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (NewFieldValue, FieldValue, StrSize); + NewFieldValue[StrSize -1] =3D '\0'; + + if (Header->FieldValue !=3D NULL) { + FreePool (Header->FieldValue); + } + Header->FieldValue =3D NewFieldValue; + } + + return EFI_SUCCESS; +} + --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69206): https://edk2.groups.io/g/devel/message/69206 Mute This Topic: https://groups.io/mt/79062472/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-