From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id A0E51D80550 for ; Tue, 27 Feb 2024 00:45:21 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=jCFoER2l8KUKoAcjFg7Wcjt275Kit9AGqnKHPpX7fjA=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1708994720; v=1; b=lzhag422LnHK9NuwdYu2+d7SjPSJMfN3OHHxsJ+41zYOqn6dkgEJkJIid0mBGSLbLz2JwDnr 1WDKXMbRDnzhe8VXy+wexEhH/Ma+oEF/nYfoqRf/p/mL9G+A1a6Cw0ZuwapC1GDckoYm5icb7Ay sFJFEd4wFcPs+csB87E7w7J8= X-Received: by 127.0.0.2 with SMTP id ROwYYY7687511xl4AEa3LKWe; Mon, 26 Feb 2024 16:45:20 -0800 X-Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.75]) by mx.groups.io with SMTP id smtpd.web10.1884.1708994719518242956 for ; Mon, 26 Feb 2024 16:45:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R8rR0let3qpV/oFkdJV1AnsVGNTWVhpBZoj32KaDHVNFLV2CHJmOhmOm6qbalQXcMBlbtL3MYguMCJURdAhY66Oz+Gm/xHNxmZqrM91c7GQpQ04sI+c/KoIJ0OH9tJVsXYHjsrrNBSdkMrjs1eystBxKWBPcOEdAqkzfSHXZtmXYB6mTs4CIH8wWZrWW0iqbBzlyddsOh8+heDdRvvoAv9EJsBMQ+6WSY4BoHSrbQtPYjTupJZ5NAkL4PZXB/ZGVzvY764tv9UBemgoUfwRPJhZdbiEEmtZrrzluqS8CWGuN3SpaK4ytv2p+t+yhcwkq7WHikxyubEIXzdSoNqLzxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VRUjUVQ+oEBc3ILdwQ1SP0UfdL3z5SIaWLEAUDfEu7M=; b=BPKYdVYwhiUyKYcS3k1i4N6FE+bsk4T5z+EHR4LKuhsUxEnkg1EoAzqxIJE6p+1QOaNjTgVeL93NngjIZINd7A+zcDtcDExsdsiL8BhPlF4oHDOmYjXydd9Q+mDrTl9zuI5v5sLDB9fsBC0a/+o3IbBKtiwiXbB2iDnup0T5F7aP82nlQa0gKsaUzA5/l2XzvLoPkegdZDoQ/+io+9C+MJitwF/8qvQv8QdZR7BXTr3ly6Khw8gWWkuS3fIwhZN7EXiveiGvtxIFgFGLvKoLFQKQhLk225iJ+5q45MDmggmbod+OCZT747Tu6sFkT4mff6UZDkR1jPL3+1DdgWPs7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) X-Received: from CY8PR19CA0041.namprd19.prod.outlook.com (2603:10b6:930:6::19) by BL3PR12MB6545.namprd12.prod.outlook.com (2603:10b6:208:38c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 00:45:15 +0000 X-Received: from CY4PEPF0000FCC2.namprd03.prod.outlook.com (2603:10b6:930:6:cafe::12) by CY8PR19CA0041.outlook.office365.com (2603:10b6:930:6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.49 via Frontend Transport; Tue, 27 Feb 2024 00:45:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000FCC2.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 00:45:14 +0000 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 26 Feb 2024 16:45:00 -0800 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 26 Feb 2024 16:45:00 -0800 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Mon, 26 Feb 2024 16:44:58 -0800 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH v3 3/6] RedfishPkg: introduce RedfishHttpLib Date: Tue, 27 Feb 2024 08:44:58 +0800 Message-ID: <20240227004458.3385-1-nicklew@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC2:EE_|BL3PR12MB6545:EE_ X-MS-Office365-Filtering-Correlation-Id: 47b1818d-e632-40ba-58cf-08dc372d5ccf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: w9btBj4BqrOX0wzTmoS+H8eIju9jvQ+RSHFWbAXMPFtDq/s+Yy2FiUueeAktJW/yVSM+8cqIRlisGEPPmc1NQ7OzyvJiBFzCEY+yV0TgPI6vXYowh7cPg4XKxX5H0ubDPH4Hliut+qkSjtN3ATBtUMbbbrBey2jQHQTEAzaaZKREwNjSkX9lbD5jEXrPvcJzxhFXjGPJQnyVWHuZb8jdB9NhAOi+MBJd6xw1ed/pQMLT1qZBogH/iVl180qBPFwhnCrA3iAhHwLC5ySYGTMgXdFVywkqZuJMYyMOdiWfh0NLwlYlXcHP2jUVHfmyI07ZHYEvpDUDFikdhuHWO8MlWE43l6N5dXp0oTzhEwLWEiG3+QLEoxbEYoXjMIrjIst1eyNjnQR3UHBTGqILJQYTgML5FWB9XwZLSbsUBBrTOzEvk3v+TQ6Eu2/k2+SlykP2bbMepHLQgcTMrU67g6q+lcJCr8JY/Bwba/ZJjQbX+dpF28WNlIOxDfz3G48+a+sqoEXVZfc/+g3x+qyBF84hhux3t7+VwGNWHt/6ch7qPj2BxfTzNGdP2Rvb8/J8lrc5bhRDXa+ocLScWDOVq5NPm5nS2xNQAD579tOiEXsZIn4LhEn8Pg/Ee375+H/UM46Rfq/fcdf28/lxjgd7z4caJuX7mzMkg51VKrAUy0CEhsmvMSQYeQBVYcW0B44/FfkYUKJJHhjnuGeKRrtcynLgGN06e70bpYzugqlymgktaj7dIofrLEtcmhfDp/62coWA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 00:45:14.7885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47b1818d-e632-40ba-58cf-08dc372d5ccf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6545 Precedence: Bulk List-Subscribe: List-Help: 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,nicklew@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: F0y3sfZwpODvTQ1QWk3gaW6Ux7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Spam-Flag: yes X-Spam-Level: ************ X-GND-Spam-Score: 190 X-GND-Status: SPAM Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=lzhag422; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=pass (policy=none) header.from=groups.io; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") RedfishHttpLib is a wrapper library for Redfish feature drivers to call Redfish HTTP Protocol easily. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez Reviewed-by: Abner Chang Reviewed-by: Igor Kulchytskyy --- RedfishPkg/RedfishPkg.dec | 5 + RedfishPkg/RedfishLibs.dsc.inc | 3 +- RedfishPkg/RedfishPkg.dsc | 3 +- .../Library/RedfishHttpLib/RedfishHttpLib.inf | 43 ++ RedfishPkg/Include/Library/RedfishHttpLib.h | 326 ++++++++++ .../Library/RedfishHttpLib/RedfishHttpLib.c | 585 ++++++++++++++++++ 6 files changed, 963 insertions(+), 2 deletions(-) create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf create mode 100644 RedfishPkg/Include/Library/RedfishHttpLib.h create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index 114f8d2ad8..1a9c9ed7bc 100644 --- a/RedfishPkg/RedfishPkg.dec +++ b/RedfishPkg/RedfishPkg.dec @@ -69,6 +69,11 @@ # RedfishPlatformConfigLib|Include/Library/RedfishPlatformConfigLib.h =20 + ## @libraryclass Provides the library functions to access Redfish HTTP + # protocol. + # + RedfishHttpLib|Include/Library/RedfishHttpLib.h + [LibraryClasses.Common.Private] ## @libraryclass Provides the private C runtime library functions. # CRT library is currently used by edk2 JsonLib (open source diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.in= c index 5426957da8..55846aaa9d 100644 --- a/RedfishPkg/RedfishLibs.dsc.inc +++ b/RedfishPkg/RedfishLibs.dsc.inc @@ -6,7 +6,7 @@ # of EDKII network library classes. # # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . +# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -21,5 +21,6 @@ RedfishPlatformCredentialLib|RedfishPkg/Library/RedfishPlatformCredentia= lIpmiLib/RedfishPlatformCredentialIpmiLib.inf HiiUtilityLib|RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/Red= fishPlatformConfigLib.inf + RedfishHttpLib|RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf !endif =20 diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index 5849e7cf9e..b0150043a9 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -4,7 +4,7 @@ # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. -# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . +# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -74,5 +74,6 @@ RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf + RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf =20 !include RedfishPkg/Redfish.dsc.inc diff --git a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf b/Redfish= Pkg/Library/RedfishHttpLib/RedfishHttpLib.inf new file mode 100644 index 0000000000..fd53b8c2ed --- /dev/null +++ b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf @@ -0,0 +1,43 @@ +## @file +# Redfish HTTP library is wrapper library for application to call Redfish +# HTTP protocol easily. +# +# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights re= served. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D RedfishHttpLib + FILE_GUID =3D 62855D9B-441B-436B-9CA6-B7FEB7ABF54E + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishHttpLib| DXE_DRIVER UEFI_DRIVE= R + CONSTRUCTOR =3D RedfishHttpConstructor + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + RedfishHttpLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiLib + UefiBootServicesTableLib + +[Protocols] + gEdkIIRedfishHttpProtocolGuid ## CONSUMES ## + +[depex] + TRUE + diff --git a/RedfishPkg/Include/Library/RedfishHttpLib.h b/RedfishPkg/Inclu= de/Library/RedfishHttpLib.h new file mode 100644 index 0000000000..39b2098139 --- /dev/null +++ b/RedfishPkg/Include/Library/RedfishHttpLib.h @@ -0,0 +1,326 @@ +/** @file + This file defines the Redfish HTTP library interface. + + Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_HTTP_LIB_H_ +#define REDFISH_HTTP_LIB_H_ + +#include + +/** + This function create Redfish service. It's caller's responsibility to fr= ee returned + Redfish service by calling FreeService (). + + @param[in] RedfishConfigServiceInfo Redfish config service informatio= n. + + @retval REDFISH_SERVICE Redfish service is created. + @retval NULL Errors occur. + +**/ +REDFISH_SERVICE +RedfishCreateService ( + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ); + +/** + This function free resources in Redfish service. RedfishService is no lo= nger available + after this function returns successfully. + + @param[in] RedfishService Pointer to Redfish service to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishCleanupService ( + IN REDFISH_SERVICE RedfishService + ); + +/** + This function returns JSON value in given RedfishPayload. Returned JSON = value + is a reference to the JSON value in RedfishPayload. Any modification to = returned + JSON value will change JSON value in RedfishPayload. + + @param[in] RedfishPayload Pointer to Redfish payload. + + @retval EDKII_JSON_VALUE JSON value is returned. + @retval NULL Errors occur. + +**/ +EDKII_JSON_VALUE +RedfishJsonInPayload ( + IN REDFISH_PAYLOAD RedfishPayload + ); + +/** + This function free resources in Request. Request is no longer available + after this function returns successfully. + + @param[in] Request HTTP request to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpFreeRequest ( + IN REDFISH_REQUEST *Request + ); + +/** + This function free resources in Response. Response is no longer availabl= e + after this function returns successfully. + + @param[in] Response HTTP response to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpFreeResponse ( + IN REDFISH_RESPONSE *Response + ); + +/** + This function expire the cached response of given URI. + + @param[in] Uri Target response of URI. + + @retval EFI_SUCCESS Target response is expired successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpExpireResponse ( + IN EFI_STRING Uri + ); + +/** + Get redfish resource from given resource URI with cache mechanism + supported. It's caller's responsibility to Response by calling + RedfishHttpFreeResponse (). + + @param[in] Service Redfish service instance to perform HTTP GET. + @param[in] Uri Target resource URI. + @param[in] Request Additional request context. This is optional. + @param[out] Response HTTP response from redfish service. + @param[in] UseCache If it is TRUE, this function will search for + cache first. If it is FALSE, this function + will query Redfish URI directly. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpGetResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN REDFISH_REQUEST *Request OPTIONAL, + OUT REDFISH_RESPONSE *Response, + IN BOOLEAN UseCache + ); + +/** + Perform HTTP PATCH to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PATCH= . + @param[in] Uri Target resource URI. + @param[in] Content Data to patch. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPatchResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP PATCH to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PATCH= . + @param[in] Uri Target resource URI. + @param[in] Content Data to patch. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPatchResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP PUT to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PUT. + @param[in] Uri Target resource URI. + @param[in] Content Data to put. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPutResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP PUT to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PUT. + @param[in] Uri Target resource URI. + @param[in] Content Data to put. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPutResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP POST to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP POST. + @param[in] Uri Target resource URI. + @param[in] Content Data to post. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPostResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP POST to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP POST. + @param[in] Uri Target resource URI. + @param[in] Content Data to post. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPostResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP DELETE to delete redfish resource on given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP DELET= E. + @param[in] Uri Target resource URI. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpDeleteResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + OUT REDFISH_RESPONSE *Response + ); + +/** + Perform HTTP DELETE to delete redfish resource on given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP DELET= E. + @param[in] Uri Target resource URI. + @param[in] Content JSON represented properties to be deleted. Thi= s is + optional. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content if Content is not NULL. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpDeleteResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content OPTIONAL, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ); + +#endif diff --git a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c b/RedfishPk= g/Library/RedfishHttpLib/RedfishHttpLib.c new file mode 100644 index 0000000000..e199527ba6 --- /dev/null +++ b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c @@ -0,0 +1,585 @@ +/** @file + Redfish HTTP cache library helps Redfish application to get Redfish reso= urce + from BMC with cache mechanism enabled. + + Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +EDKII_REDFISH_HTTP_PROTOCOL *mRedfishHttpProtocol =3D NULL; + +/** + This function create Redfish service. It's caller's responsibility to fr= ee returned + Redfish service by calling FreeService (). + + @param[in] RedfishConfigServiceInfo Redfish config service informatio= n. + + @retval REDFISH_SERVICE Redfish service is created. + @retval NULL Errors occur. + +**/ +REDFISH_SERVICE +RedfishCreateService ( + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return NULL; + } + + return mRedfishHttpProtocol->CreateService ( + mRedfishHttpProtocol, + RedfishConfigServiceInfo + ); +} + +/** + This function free resources in Redfish service. RedfishService is no lo= nger available + after this function returns successfully. + + @param[in] RedfishService Pointer to Redfish service to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishCleanupService ( + IN REDFISH_SERVICE RedfishService + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->FreeService ( + mRedfishHttpProtocol, + RedfishService + ); +} + +/** + This function returns JSON value in given RedfishPayload. Returned JSON = value + is a reference to the JSON value in RedfishPayload. Any modification to = returned + JSON value will change JSON value in RedfishPayload. + + @param[in] RedfishPayload Pointer to Redfish payload. + + @retval EDKII_JSON_VALUE JSON value is returned. + @retval NULL Errors occur. + +**/ +EDKII_JSON_VALUE +RedfishJsonInPayload ( + IN REDFISH_PAYLOAD RedfishPayload + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return NULL; + } + + return mRedfishHttpProtocol->JsonInPayload ( + mRedfishHttpProtocol, + RedfishPayload + ); +} + +/** + This function free resources in Request. Request is no longer available + after this function returns successfully. + + @param[in] Request HTTP request to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpFreeRequest ( + IN REDFISH_REQUEST *Request + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->FreeRequest ( + mRedfishHttpProtocol, + Request + ); +} + +/** + This function free resources in Response. Response is no longer availabl= e + after this function returns successfully. + + @param[in] Response HTTP response to be released. + + @retval EFI_SUCCESS Resource is released successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpFreeResponse ( + IN REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->FreeResponse ( + mRedfishHttpProtocol, + Response + ); +} + +/** + This function expire the cached response of given URI. + + @param[in] Uri Target response of URI. + + @retval EFI_SUCCESS Target response is expired successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpExpireResponse ( + IN EFI_STRING Uri + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->ExpireResponse ( + mRedfishHttpProtocol, + Uri + ); +} + +/** + Get redfish resource from given resource URI with cache mechanism + supported. It's caller's responsibility to Response by calling + RedfishHttpFreeResponse (). + + @param[in] Service Redfish service instance to perform HTTP GET. + @param[in] Uri Target resource URI. + @param[in] Request Additional request context. This is optional. + @param[out] Response HTTP response from redfish service. + @param[in] UseCache If it is TRUE, this function will search for + cache first. If it is FALSE, this function + will query Redfish URI directly. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpGetResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN REDFISH_REQUEST *Request OPTIONAL, + OUT REDFISH_RESPONSE *Response, + IN BOOLEAN UseCache + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->GetResource ( + mRedfishHttpProtocol, + Service, + Uri, + Request, + Response, + UseCache + ); +} + +/** + Perform HTTP PATCH to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PATCH= . + @param[in] Uri Target resource URI. + @param[in] Content Data to patch. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPatchResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PatchResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + 0, + NULL, + Response + ); +} + +/** + Perform HTTP PATCH to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PATCH= . + @param[in] Uri Target resource URI. + @param[in] Content Data to patch. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPatchResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PatchResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + ContentSize, + ContentType, + Response + ); +} + +/** + Perform HTTP PUT to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PUT. + @param[in] Uri Target resource URI. + @param[in] Content Data to put. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPutResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PutResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + 0, + NULL, + Response + ); +} + +/** + Perform HTTP PUT to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP PUT. + @param[in] Uri Target resource URI. + @param[in] Content Data to put. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPutResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PutResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + ContentSize, + ContentType, + Response + ); +} + +/** + Perform HTTP POST to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP POST. + @param[in] Uri Target resource URI. + @param[in] Content Data to post. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPostResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PostResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + 0, + NULL, + Response + ); +} + +/** + Perform HTTP POST to send redfish resource to given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP POST. + @param[in] Uri Target resource URI. + @param[in] Content Data to post. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpPostResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->PostResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + ContentSize, + ContentType, + Response + ); +} + +/** + Perform HTTP DELETE to delete redfish resource on given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP DELET= E. + @param[in] Uri Target resource URI. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpDeleteResource ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->DeleteResource ( + mRedfishHttpProtocol, + Service, + Uri, + NULL, + 0, + NULL, + Response + ); +} + +/** + Perform HTTP DELETE to delete redfish resource on given resource URI. + It's caller's responsibility to free Response by calling RedfishHttpFree= Response (). + + @param[in] Service Redfish service instance to perform HTTP DELET= E. + @param[in] Uri Target resource URI. + @param[in] Content JSON represented properties to be deleted. Thi= s is + optional. + @param[in] ContentSize Size of the Content to be send to Redfish serv= ice. + This is optional. When ContentSize is 0, Conte= ntSize + is the size of Content if Content is not NULL. + @param[in] ContentType Type of the Content to be send to Redfish serv= ice. + This is optional. + @param[out] Response HTTP response from redfish service. + + @retval EFI_SUCCESS Resource is returned successfully. + @retval Others Errors occur. + +**/ +EFI_STATUS +RedfishHttpDeleteResourceEx ( + IN REDFISH_SERVICE Service, + IN EFI_STRING Uri, + IN CHAR8 *Content OPTIONAL, + IN UINTN ContentSize OPTIONAL, + IN CHAR8 *ContentType OPTIONAL, + OUT REDFISH_RESPONSE *Response + ) +{ + if (mRedfishHttpProtocol =3D=3D NULL) { + return EFI_NOT_READY; + } + + return mRedfishHttpProtocol->DeleteResource ( + mRedfishHttpProtocol, + Service, + Uri, + Content, + ContentSize, + ContentType, + Response + ); +} + +/** + Callback function when gEdkIIRedfishHttpProtocolGuid is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +RedfishHttpProtocolIsReady ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + if (mRedfishHttpProtocol !=3D NULL) { + gBS->CloseEvent (Event); + return; + } + + Status =3D gBS->LocateProtocol ( + &gEdkIIRedfishHttpProtocolGuid, + NULL, + (VOID **)&mRedfishHttpProtocol + ); + if (EFI_ERROR (Status)) { + return; + } + + gBS->CloseEvent (Event); +} + +/** + + Initial HTTP library instance. + + @param[in] ImageHandle The image handle. + @param[in] SystemTable The system table. + + @retval EFI_SUCCESS Initial library successfully. + @retval Other Return error status. + +**/ +EFI_STATUS +EFIAPI +RedfishHttpConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + VOID *Registration; + + EfiCreateProtocolNotifyEvent ( + &gEdkIIRedfishHttpProtocolGuid, + TPL_CALLBACK, + RedfishHttpProtocolIsReady, + NULL, + &Registration + ); + + return EFI_SUCCESS; +} --=20 2.34.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 (#115986): https://edk2.groups.io/g/devel/message/115986 Mute This Topic: https://groups.io/mt/104594899/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-