From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.76]) by mx.groups.io with SMTP id smtpd.web11.32241.1688390448908502526 for ; Mon, 03 Jul 2023 06:20:49 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=CVk6ZUyn; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.94.76, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fgp9MhHMgNbaVbzP7FKjl/l3TANnYYrc3U6RkG6K7DUAiPAJHynZ2mRXd1viDOH6X25/EtvPQYfUYUNJRhSzLBx+rO+ZxatsBaatJKVscMTNKj7kS6qnqHKVMipwcb2cWUJ3ga5KgtvcIC8CsQ/2T6u7bc2Xg/RHQoynzAtCEM1x7ecLxe33qQ6PXnPKevxZc6i+h3oTJjmDt0kurO2O8Lc1VLqFaWQSOaIxLzlz/C2+vZhqwAow2pIzEob+vsfDdhhappdkeEyPUGqWte58YiMYQAyLqr2TLNFDlirmbKR0j+Wy5KcreQhqeQut/BWLIQyR2cWep+DEtR+a35HsuQ== 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=qKr6Mkmth/hdzy2v1pdDEDlsnbR4gPF29g5gU36IOeU=; b=NaT8kfSvi4imQmvxH8BpXFlThRpWhZRXGwiX5Cp51KXvJelGW23qkp8Bg60XYdqTfoUTF6ataABuklGjWOHNmVDngvhLI6ja3lJysnfp1L1wKsRrX3R29KqEZIUv67rGfsvkzMYO7uiV9OgeZZ0phhlwPoQcn2crIyYQM/wbtj/7ElZwL0Xc97qMp02XOgn/6BA/noXQp3w3uWzl3mpfbTic04XA5tTs8C0Dn2qld02Ya/o9g9GDhRs88zAhDm2ZnVFFID8Xl3uHdmHpnih9EL2AEGWv2wMvVLIOWSqETZZaYX0utPap2kt6DN5gL9q4CUsY9iFncIu5DMq6EG6mwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qKr6Mkmth/hdzy2v1pdDEDlsnbR4gPF29g5gU36IOeU=; b=CVk6ZUynr71E+3twed+yL4YAytA/6kDnJcVwIsPo2sy/XKwo3NRIUTtJeRYBQYYog/5kYmZMN8uP3d9qDabxmB0D05cb98v7NvpJfIzkTJV6au5bYRfhINC7JRuX19Sd4/rA9bTyXa+0FlGMg87WaA94NadmuJ6BmiyOIEbmR2jBrbhoyVZaD28gJThOf0OL0PdlGTH28CIDYegbQS3uNr/EoDBm2RlLneXoPIIJ5hqowAMcehfWlSqe4K1o6UEqcl8VV0EVQc1swqsHBELEkHDa25tOnmJeX77U/uqv477tcMkVD2cqLcUTTG/PcvbX60MtWUU6glu/6isqrLVkdg== Received: from MW4PR04CA0175.namprd04.prod.outlook.com (2603:10b6:303:85::30) by DS0PR12MB7582.namprd12.prod.outlook.com (2603:10b6:8:13c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 13:20:46 +0000 Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::b0) by MW4PR04CA0175.outlook.office365.com (2603:10b6:303:85::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.30 via Frontend Transport; Mon, 3 Jul 2023 13:20:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.43 via Frontend Transport; Mon, 3 Jul 2023 13:20:46 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 3 Jul 2023 06:20:33 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 3 Jul 2023 06:20:32 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 3 Jul 2023 06:20:31 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [PATCH 3/3] RedfishPkg/JsonLib: add object clear interface Date: Mon, 3 Jul 2023 21:20:30 +0800 Message-ID: <20230703132030.7271-1-nicklew@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Return-Path: nicklew@nvidia.com X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT055:EE_|DS0PR12MB7582:EE_ X-MS-Office365-Filtering-Correlation-Id: 234c9bf7-c2e4-4689-e0cd-08db7bc84fa7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T6InGZxF23zZiWy+zFPAX1MPEv1AXwxb889azzZG//z/ta4tJYV6RE2rJXlUELEWzlEJnn4VUoz/FuvpTFNagXsMeeLPQrNF0jtEsOjSN0EUXuCHIf2kLfh2qiiFhHxi0vrDPFNOG5Jh6Le2XCoqfbnRT6ZsNeGqbXdC3omR4cGAblPYqKfD+c8Qsq5nDGFB4N5W5ZPEUVWKpLXMJ2fabsMbQxjdm45ie+Wgg36J0Wy/JaRR3KnWuUwHoJLz4uPdW+C8gr+NZR1Gdhyh57aX/PaXY690EWYyG1RVCWoZtzwj1T2V93f5cAUmgY0uhCHJ+eD9kj5H5lm7qVD9sKpggL64nu16xhC03ZZGsxRQkN1gxuu+qjdoh5E91zwsYl70f+q0Kyudqnw0TXrt5zuuOIb2e3VX+CDsg5TezSa/YksPTNTBhK6OgcWRZZJ/Oy9t1C6auYJ6s1ruSv0jFxBhtj/Y35uVaTyZ+Dbv/ovYx2AsPFmf36GESRnQQXsZZulhP+0b2W8ZbpiBmygkKl0l+mxENt02ySVTwx3TzbzZRl5XQhl/u3dQr+d6mZz8dPeK8IgOE1G8th72lwygf4MNLmrdMGzdlo/3Kz77jrgV3HFS7j7cHHtPdN4txX8nImj/KFLm8UmZivMAIw21KUeIQ4g1JnLvNyO7joNC+2FDugizV4jfYlUVO+HUtUdIvz1Faqbbc/6a+xM+BOLT4d+6R474ssiiahbx/uJzSkNrt5Sbo7LfcZiryiGt5skT5AQtr6PbkfBTAD3O7EOZ1aCXyw== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199021)(46966006)(36840700001)(40470700004)(6916009)(4326008)(70206006)(316002)(2906002)(478600001)(36756003)(70586007)(8936002)(8676002)(5660300002)(40460700003)(336012)(41300700001)(40480700001)(966005)(36860700001)(54906003)(86362001)(82310400005)(7696005)(1076003)(26005)(186003)(47076005)(426003)(82740400003)(7636003)(2616005)(83380400001)(107886003)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 13:20:46.2197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 234c9bf7-c2e4-4689-e0cd-08db7bc84fa7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7582 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain -Add JsonObjectClear() interface for application to clear all elements in JSON object. -Fix typo. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- RedfishPkg/Include/Library/JsonLib.h | 33 +++++++++++++++++------ RedfishPkg/Library/JsonLib/JsonLib.c | 39 ++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Libr= ary/JsonLib.h index f98f4e779ede..8f31d9341481 100644 --- a/RedfishPkg/Include/Library/JsonLib.h +++ b/RedfishPkg/Include/Library/JsonLib.h @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -97,7 +98,7 @@ typedef enum { =20 More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 - @retval The created JSON value which contains a JSON array or NULL = if intial a JSON array + @retval The created JSON value which contains a JSON array or NULL = if initial a JSON array is failed. =20 **/ @@ -116,7 +117,7 @@ JsonValueInitArray ( =20 More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 - @retval The created JSON value which contains a JSON object or NULL= if intial a JSON object + @retval The created JSON value which contains a JSON object or NULL= if initial a JSON object is failed. =20 **/ @@ -571,6 +572,22 @@ JsonObjectSize ( IN EDKII_JSON_OBJECT JsonObject ); =20 +/** + The function removes all elements from object. Returns 0 on success and = -1 if object is not + a JSON object. The reference count of all removed values are decremented= . + + @param[in] JsonObject The provided JSON object. + + @retval EFI_ABORTED Some error occur and operation abort= ed. + @retval EFI_SUCCESS JSON value has been appended to the = end of the JSON array. + +**/ +EFI_STATUS +EFIAPI +JsonObjectClear ( + IN EDKII_JSON_OBJECT JsonObject + ); + /** The function is used to enumerate all keys in a JSON object. =20 @@ -705,7 +722,7 @@ JsonArrayAppendValue ( More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 @param[in] JsonArray The provided JSON array. - @param[in] Index The Index position before removement= . + @param[in] Index The Index position before removal. =20 @retval EFI_ABORTED Some error occur and operation abort= ed. @retval EFI_SUCCESS The JSON array has been removed at p= osition index. @@ -722,7 +739,7 @@ JsonArrayRemoveValue ( Dump JSON to a buffer. =20 @param[in] JsonValue The provided JSON value. - @param[in] Flags The Index position before removement. The v= alue + @param[in] Flags The Index position before removal. The valu= e could be the combination of below flags. - EDKII_JSON_INDENT(n) - EDKII_JSON_COMPACT @@ -737,7 +754,7 @@ JsonArrayRemoveValue ( https://jansson.readthedocs.io/en/2.13/apir= ef.html#encoding =20 @retval CHAR8 * Dump fail if NULL returned, otherwise the b= uffer - contain JSON paylaod in ASCII string. The r= eturn + contain JSON payload in ASCII string. The r= eturn value must be freed by the caller FreePool(= ). **/ CHAR8 * @@ -753,7 +770,7 @@ JsonDumpString ( value. Only object and array represented strings can be converted succes= sfully, since they are the only valid root values of a JSON text for UEFI usage. =20 - Real number and number with exponent part are not supportted by UEFI. + Real number and number with exponent part are not supported by UEFI. =20 Caller needs to cleanup the root value by calling JsonValueFree(). =20 @@ -775,7 +792,7 @@ JsonLoadString ( /** Load JSON from a buffer. =20 - @param[in] Buffer Bufffer to the JSON payload + @param[in] Buffer Buffier to the JSON payload @param[in] BufferLen Length of the buffer @param[in] Flags Flag of loading JSON buffer, the value could be the combination of below flags. @@ -807,7 +824,7 @@ JsonLoadBuffer ( When the reference count drops to zero, there are no references left and= the value can be destroyed. =20 - This funciton decrement the reference count of EDKII_JSON_VALUE. As soon= as + This function decrement the reference count of EDKII_JSON_VALUE. As soon= as a call to json_decref() drops the reference count to zero, the value is destroyed and it can no longer be used. =20 diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/Json= Lib/JsonLib.c index 69f2455c00ed..9b758b940293 100644 --- a/RedfishPkg/Library/JsonLib/JsonLib.c +++ b/RedfishPkg/Library/JsonLib/JsonLib.c @@ -28,7 +28,7 @@ =20 More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 - @retval The created JSON value which contains a JSON array or NULL = if intial a JSON array + @retval The created JSON value which contains a JSON array or NULL = if initial a JSON array is failed. =20 **/ @@ -50,7 +50,7 @@ JsonValueInitArray ( =20 More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 - @retval The created JSON value which contains a JSON object or NULL= if intial a JSON object + @retval The created JSON value which contains a JSON object or NULL= if initial a JSON object is failed. =20 **/ @@ -672,6 +672,29 @@ JsonObjectSize ( return json_object_size ((json_t *)JsonObject); } =20 +/** + The function removes all elements from object. Returns 0 on success and = -1 if object is not + a JSON object. The reference count of all removed values are decremented= . + + @param[in] JsonObject The provided JSON object. + + @retval EFI_ABORTED Some error occur and operation abort= ed. + @retval EFI_SUCCESS JSON value has been appended to the = end of the JSON array. + +**/ +EFI_STATUS +EFIAPI +JsonObjectClear ( + IN EDKII_JSON_OBJECT JsonObject + ) +{ + if (json_object_clear ((json_t *)JsonObject) !=3D 0) { + return EFI_ABORTED; + } + + return EFI_SUCCESS; +} + /** The function is used to enumerate all keys in a JSON object. =20 @@ -864,7 +887,7 @@ JsonArrayAppendValue ( More details for reference count strategy can refer to the API descripti= on for JsonValueFree(). =20 @param[in] JsonArray The provided JSON array. - @param[in] Index The Index position before removement= . + @param[in] Index The Index position before removal. =20 @retval EFI_ABORTED Some error occur and operation abort= ed. @retval EFI_SUCCESS The JSON array has been removed at p= osition index. @@ -888,7 +911,7 @@ JsonArrayRemoveValue ( Dump JSON to a buffer. =20 @param[in] JsonValue The provided JSON value. - @param[in] Flags The Index position before removement. The v= alue + @param[in] Flags The Index position before removal. The valu= e could be the combination of below flags. - EDKII_JSON_INDENT(n) - EDKII_JSON_COMPACT @@ -903,7 +926,7 @@ JsonArrayRemoveValue ( https://jansson.readthedocs.io/en/2.13/apir= ef.html#encoding =20 @retval CHAR8 * Dump fail if NULL returned, otherwise the b= uffer - contain JSON paylaod in ASCII string. The r= eturn + contain JSON payload in ASCII string. The r= eturn value must be freed by the caller using Fre= ePool(). **/ CHAR8 * @@ -926,7 +949,7 @@ JsonDumpString ( value. Only object and array represented strings can be converted succes= sfully, since they are the only valid root values of a JSON text for UEFI usage. =20 - Real number and number with exponent part are not supportted by UEFI. + Real number and number with exponent part are not supported by UEFI. =20 Caller needs to cleanup the root value by calling JsonValueFree(). =20 @@ -951,7 +974,7 @@ JsonLoadString ( /** Load JSON from a buffer. =20 - @param[in] Buffer Bufffer to the JSON payload + @param[in] Buffer Buffier to the JSON payload @param[in] BufferLen Length of the buffer @param[in] Flags Flag of loading JSON buffer, the value could be the combination of below flags. @@ -986,7 +1009,7 @@ JsonLoadBuffer ( When the reference count drops to zero, there are no references left and= the value can be destroyed. =20 - This funciton decrement the reference count of EDKII_JSON_VALUE. As soon= as + This function decrement the reference count of EDKII_JSON_VALUE. As soon= as a call to json_decref() drops the reference count to zero, the value is destroyed and it can no longer be used. =20 --=20 2.17.1