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 4C16A78003C for ; Tue, 20 Feb 2024 06:41:49 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=N7QA4iyEbNV1UwdSz1Euan9/165oWXyvMHNZ9u1ZLPo=; 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=1708411308; v=1; b=HbB1Y21VFzXH5ObKFJEdPRl6GxnhrqKRSH/m2EMNIx2ygc7aDz1WoTmJzHuVg42qGrLQCube 7BHlzU6pQ5cAlh9P5FyaitEtn0p+cHqGGmuuZU1rGO7isR1AdvWGdoXOKAHBIUD2A1pbzSl60Y7 /j6ZdgyKQ/Fg4Iw7GZLfzsak= X-Received: by 127.0.0.2 with SMTP id uP47YY7687511xonfIatzdxI; Mon, 19 Feb 2024 22:41:47 -0800 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.63]) by mx.groups.io with SMTP id smtpd.web11.8095.1708411307251894878 for ; Mon, 19 Feb 2024 22:41:47 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HvpKykViAFNCULjbN+qcxY7o/8kbTVAtM483b3fWy61oL9HdhwlBizPNgUB/1aIDthx1sm+JYm1Fi+x7YndfN9lGFJqswuXRWzUWsZQIBUisaY7lPlEQgz+3PnR7Q2QTirj6lcPnreI4QpowmQ6HFuzSnlhyGzTc2FGAOI6hXTnylVwIwvwWpeYoU6LVFqqQwA90de76cRzOlkdM7tVrCr9jEvuSdpdGQRAPMQPfm9hy6QKdVqMwL+o9Rl9kOmSVs3DWSzkSrnduU3yXrA0EI+XHGeA8qZ5Eynnu3GoYEKo3A6QX0rcUgk+fWjsklmtEqg4W7ESQeGNxvswTJWscDQ== 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=Ai5IVQzPg6lQ4HM/gaSmMmp8+WbWFTroh0dnwJHEYPA=; b=i0mNlY7oUvkUat1NEGp1GVFG/Vr3H/gfhSoAXWX0oGulwg0AVMQCdriMqtYDrFJ24Iwp0JNfN+byjTmOm0X3Esd9zLvzAPwshZXBfvX/nvhkFtO7DJ5x0CJvIQuFE5W2N0FWWWJNGMmAb5HOS5Qk7i0xAFc1S1IWPvDtbVGyQd6aCRB4olVHJ6guznS7cYjoAtBTZm/lacDXuc/iNQVmoO5xhpiVkheBowSxkzgE0uUQTFFyP1X0I+bYVqxy8SdgxDQ3e4thzng4EA92ZWRL8BFwePnWVuAg/YPg8TJgY5ee2Vwvn/RpLmqPh2gkZC/xp1u8sezeGFF5IZKgy8Jf1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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 BYAPR07CA0034.namprd07.prod.outlook.com (2603:10b6:a02:bc::47) by BL0PR12MB5010.namprd12.prod.outlook.com (2603:10b6:208:17c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.19; Tue, 20 Feb 2024 06:41:43 +0000 X-Received: from SJ1PEPF00001CE6.namprd03.prod.outlook.com (2603:10b6:a02:bc:cafe::2) by BYAPR07CA0034.outlook.office365.com (2603:10b6:a02:bc::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.38 via Frontend Transport; Tue, 20 Feb 2024 06:41:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.161) by SJ1PEPF00001CE6.mail.protection.outlook.com (10.167.242.22) 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, 20 Feb 2024 06:41:43 +0000 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 19 Feb 2024 22:41:33 -0800 X-Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 19 Feb 2024 22:41:32 -0800 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Mon, 19 Feb 2024 22:41:31 -0800 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH 3/6] RedfishPkg: introduce RedfishHttpLib Date: Tue, 20 Feb 2024 14:41:30 +0800 Message-ID: <20240220064130.28429-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: SJ1PEPF00001CE6:EE_|BL0PR12MB5010:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fa7eb02-c49c-4ee5-5cd5-08dc31df0048 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: LqPGGbXJ5jEBI0b11pw6fnGhP0IIl8z5e0MgUSpIHHdz2FK1CLWI/r307izLezfbGBKcfwBd3bXqVJvGgUHGhzXF1FvmYVtsNiT+Nd9QsO0uX7OYzRF2bsAWvSenW81g9MJxJ7FEPx/T66IH7llXM2oA05LWDrr9lWBSqLRiCjpLFYAow+L3F+/M1xOO6uwG+V1s7UD1w5MycV371IdFP2b0tM/PpzUTbDtOtDrIE7cniSRsjEjZAFrAJFUpRUIHWRVB/EIEzzPWltLCwldXaGyp8ByWegS5amSdCDblcjawaiOJ00pntsszpuPJ64quTZrVXWexR6fcZdV1vsRF/Cc0XZRlSZYnXPw1wjX+vWjpAzV9i/ku/A97/Rv2kdrGnRcCxAV4IZUtVAdZPoet+5ZjGzQ/s+QovurtRu4Tm3zvZ0ETV3hyiXYiVfctVV26xScVTvyRoOpH29B1pPRhltqzNF4mARHmiYAX4l66/Kgx+UVjTskslU0eleq7+AuNBpqY2EMhVaXlzF8uEKavjl8Xjs6TUlZ02ZbaruY/Rt3yIudboEbck7Fl/kmvzKg3Xf/l/qDME5/xv+vFwI/nF163jTVirV+7j9pYHH8iCJItRE8gg0EQtHkjUT+26pz5UDCCefLCj8+HYBfzkpovqejtKl8tC/lKsck23+d1X7U= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 06:41:43.1040 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fa7eb02-c49c-4ee5-5cd5-08dc31df0048 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5010 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: 8b4pumcdXnCICVdTYVkqxZZyx7686176AA= 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=HbB1Y21V; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 --- 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..b07a46993b --- /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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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..0a17952d63 --- /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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 Resrouce 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 (#115628): https://edk2.groups.io/g/devel/message/115628 Mute This Topic: https://groups.io/mt/104463405/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-