From nobody Thu Mar 28 12:01:39 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+69905+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+69905+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1610005502; cv=none; d=zohomail.com; s=zohoarc; b=gCcLG9VGKUAX/MxKaxaX3j64b666450u8iuberrJqrchmRrxUbi0cptl5hN7mYcHyH+OfQ6pVf1n7Fpupx7LoACKasbxNVQMVJhpcKTyvrtbsmUG4eSJT2YT27xw+r/yA2yAMs8hEDCzgVj6bt5xAfRO1r/dH3ZHfXbnmh+vXJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610005502; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=PruyXKFp2RnaUGO+t+8yyHirnZHtrWZg0HeEtqMjFqQ=; b=byri8lp/2YrybcW3PyoA0w0SmJZEjTvFgIBoSs4zI0rGYPc2Vk991IoGWeEkx7jMFcW4tfLI7o9oYOhLZQjMEGMSnOWfIL6FlXeijBXM1pOccMjmBRVxj9PE6Xt4eub8dD+PVOfJfvbmKs3gGio08G66CBKtwl3H1hxD1Y0JyU0= 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+69905+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 1610005502296409.00903779826297; Wed, 6 Jan 2021 23:45:02 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jzJeYY1788612xazxZqnKRk5; Wed, 06 Jan 2021 23:45:01 -0800 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.5338.1610005496343496662 for ; Wed, 06 Jan 2021 23:44:56 -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 1077h65O008944; Thu, 7 Jan 2021 07:44:55 GMT X-Received: from g4t3427.houston.hpe.com (g4t3427.houston.hpe.com [15.241.140.73]) by mx0b-002e3701.pphosted.com with ESMTP id 35wt7h1atf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Jan 2021 07:44:55 +0000 X-Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3427.houston.hpe.com (Postfix) with ESMTP id C47F066; Thu, 7 Jan 2021 07:44:54 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id DB8904A; Thu, 7 Jan 2021 07:44:52 +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 v2] NetworkPkg/DxeHttpLib: Migrate HTTP header manipulation APIs Date: Thu, 7 Jan 2021 14:57:02 +0800 Message-Id: <20210107065702.3523-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: d91ZQCiQwXojDXVkDyON47CSx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610005501; bh=Tbwa7CB5VxABAh37YIrz3Vw4Hwb5HaJa7nD5oguuZDQ=; h=Cc:Date:From:Reply-To:Subject:To; b=BQ6LwXZdb+/YuJKAnv4XzU15exJQXWihU89c9Ml56+6s7zMSWow2tqGTzxmJkaMtbUT 7JmfCTr9Jgcdk1XFX5PjodwCKFEDZ3CxSpHkg5RXLc7rPHoRfnnp+6WOLEWfyV0lbDjKs SqLCvh/jBC/DyCeJQi6x/azUhPiLO10X/7Y= 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 Reviewed-by: Maciej Rabeda --- NetworkPkg/HttpBootDxe/HttpBootSupport.h | 53 -------- NetworkPkg/Include/Library/HttpLib.h | 53 ++++++++ NetworkPkg/HttpBootDxe/HttpBootClient.c | 10 +- NetworkPkg/HttpBootDxe/HttpBootSupport.c | 130 -------------------- NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c | 135 ++++++++++++++++++++- 5 files changed, 192 insertions(+), 189 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/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.c index 93d9dfc464..37a95e031e 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c @@ -491,136 +491,6 @@ Exit: =20 return Status; } -/** - 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 ( - 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 -HttpBootFreeHeader ( - 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); - 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 -HttpBootSetHeader ( - 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 /** This function checks the HTTP(S) URI scheme. 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 (#69905): https://edk2.groups.io/g/devel/message/69905 Mute This Topic: https://groups.io/mt/79494666/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-