From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web10.11222.1688540222847662728 for ; Tue, 04 Jul 2023 23:57:03 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=fttISZFB; 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.236.41, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DXqLEB7ovA50vEedhdWA1gp62RmLCCir170nop/18rPRSweXh2LzHDlyXSJ4NhquEo5nGan2auu6TSHcTQaxFbaDPFq9Rpg3vSMlAxQhMZa02qaIloxxeOaKJ0YivvLDqkxVhnE1PBVLS6iQWGsc73dALmyhhW+OYulCvhG/jP08d5uWFqw3htdiFTZ7gFMAR7cqm75dsue5BoPkRXuJS088HjlFJjtjTjojslE/fAQNnV9OMKD861JMk1FUHL9pjg8vLraGD3P8h2K9mlKDQFEfYQPGHLdWxStjO4DMRXX3nuiQ79+6yci01KhfTlX/nraaWOD6zLsDDwBZT/CZkg== 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=jK+EViK/UvvetLdEwYk1FARpI2swO0/b0DYYC+d6T08=; b=SjkcPvq31epLIggOdBXHPuENTx9w+JMNToNCW2SdYS6ggqnw8D4dH0QggUlpIZR03lty0oFpW1zG2sxM+AEh0NKOUCo+Xwgeczg1M8BmN2AUoTxfWkGtIq5fLpxmS64esfVdNH0xZcrwSHhA8gR4rIiwRBbWxskLvhQfmk5aym9WEhXUYunME+kLGAC+HY4pV1pDBi1+w+umCcdVVJNob8wPWAGlfinCffV0m9Zjr5Tytt+lkQBdVSf/9YRBexodDgdLcjnLxmhPRIp9YAWXzr4kJsdum6DE9Nh03TKbhN8B0JwAWgppHfuUkytEbWU15ZPIjqqfIbUpWy0EMwxacw== 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 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=jK+EViK/UvvetLdEwYk1FARpI2swO0/b0DYYC+d6T08=; b=fttISZFB+gzKT3TLaKBRk6mutVrx5PChuxaj3fStVdBa6qOv5IgGRIYP9xxS6quxEuRkW017WYbwxQsgvoOSOYU6V4Ankx3/PWuyYhkWxKYR2VLnszJkh97s6+J8SjzvaGiDpkrKlkHN7MNwsHaRgrjCrLdGgp/ZOKyD8Cqosg0xY2iVU6A5IqxzHlvMnTDzY/u7S/+MMlknTsKBjPe6w8CiUSrXeOkcgdEiOwoVPqJNW2H0sgSYMYF7aClZ/xM6QakfXnZMJdTkNIhv37kDNHO+Wj/MZNY4ii/RxDvxdMD9EG3tzondAr0hWRPGmgoyKTcNPKmOPe+pVqLOs2u9WQ== Received: from DS7PR03CA0197.namprd03.prod.outlook.com (2603:10b6:5:3b6::22) by MW4PR12MB6998.namprd12.prod.outlook.com (2603:10b6:303:20a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Wed, 5 Jul 2023 06:56:57 +0000 Received: from DM6NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::ea) by DS7PR03CA0197.outlook.office365.com (2603:10b6:5:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.18 via Frontend Transport; Wed, 5 Jul 2023 06:56:56 +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 Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT038.mail.protection.outlook.com (10.13.173.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.44 via Frontend Transport; Wed, 5 Jul 2023 06:56:56 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.5; Tue, 4 Jul 2023 23:56:46 -0700 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.986.37; Tue, 4 Jul 2023 23:56:46 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 4 Jul 2023 23:56:45 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [PATCH v2 3/3] RedfishPkg/JsonLib: add object clear interface Date: Wed, 5 Jul 2023 14:56:44 +0800 Message-ID: <20230705065644.1531-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: DM6NAM11FT038:EE_|MW4PR12MB6998:EE_ X-MS-Office365-Filtering-Correlation-Id: 425f275c-4655-453e-eccb-08db7d2505a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jItugwdU9ylNJl0rs86/Ftws0lrujyjrzE0MmA04PSFJMGg/PnssZcMhf7hNnDezeweulzDDKGndHB0+VWAes94dSpoiyHy6by6RkoOGVo/m39ajIWlyCKgUJFuu89uTKXZWSNnRW2RAQU2p7JWI5uQ5xtBkuR5MZ8sf+sFaC3aV01iDOkzobWjuSN1l6AfuWxk0liop+x4CX+vZ6oKRfIfWuFHvMqqQ85omkDSusnGV4QiOss4FH4EvreXUeLyqGNdB7Y1FNyH61zeKuVs+jfiAH5knXKN31a1c8lL3S2ruANMR+1wtAQ1N9NbEQjqKwmpe7eCnOw2vHF+maSJWB5K+cEpPpgzbyaZn4EmnCcSqvYE2rZ0ZDTNMpziYFFPGYboPF2DvSVfbR70xsb9otYaKzcLM+1T3dNnqrwX2rmDNmgrjeriBACMIsj56Kse4l0pJ8LUbCNU/KNNdc9LBrwXz0XDB4GTLMsdKEywxABTrhjxxWbGbNht6hLW87ySdRNi+sC6ytTBKBTUh82VYkMAyHhqUd6yz+kEgTlv4aXmfZZzaMDL1VF2Br3eBOELi3wmNQNiNJJqx1EkcJw9gMnF+jRAl5LbT514xihEiM9kKQKyMpA/lH4eIHOKKpBvwo2kTg/9YWkhoUv7RudUxolQXLvgc+ltImhEkQSuIILpIPTnyvMU6QkG1pSAu9q3TWbvw2edMnSeGHLpiLwWi4CRTwqnXU8eoD3cLlZrT47YL9qux6yi+/63gmIHHtqwKTXF+MMVwYQFJc/sBAkRl5Q== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199021)(36840700001)(46966006)(40470700004)(54906003)(966005)(7696005)(478600001)(107886003)(336012)(186003)(1076003)(26005)(2906002)(82310400005)(70586007)(8936002)(82740400003)(6916009)(316002)(5660300002)(8676002)(41300700001)(70206006)(4326008)(356005)(7636003)(86362001)(40460700003)(36756003)(83380400001)(47076005)(36860700001)(40480700001)(426003)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2023 06:56:56.3032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 425f275c-4655-453e-eccb-08db7d2505a0 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: DM6NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6998 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 Reviewed-by: Abner Chang --- 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