From nobody Sat May 4 18:40:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+71776+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71776+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1613620924; cv=none; d=zohomail.com; s=zohoarc; b=eOKcmyMempM/EE0I5hllQb21lPu4DqGL7CHJPef79eAtdE9krAn3NS2rVh2NfZfGR8vMwhU0C+A1wnVCVgZbgxK7aDvlBJnReyuy5NO4z+wC8r2RnYa+ur5cmunpdlzceDyqiwUynTdSUkgROEv6YftNOt+ezYTjdx2ygPYoGC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613620924; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=gXZ8fZ3Ybbkcp3ipTMtWUBUSe8cNQ3K3fOFq5fOx+So=; b=LjXyc1b+3aQYygtEEOsfzWMUqK3dna2eGYbdt30JwXDr+I8zNq/LvT/3x+HqT4Eit8GYgAwhNu+5/ulGMHJDJUwTKMg8cAKVyiCFGbs/GA1m0eDBUOpkB3BRFkyiZew5UYwp6iv/mV4NstuCS+j/dwzlejO8vqPq0K3mNQ+r5ZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71776+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1613620924102530.7685265741446; Wed, 17 Feb 2021 20:02:04 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2ewvYY1788612xdxJq3SunFV; Wed, 17 Feb 2021 20:02:03 -0800 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.2421.1613620918282670056 for ; Wed, 17 Feb 2021 20:01:58 -0800 X-Received: from pps.filterd (m0134422.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11I40DYT018391; Thu, 18 Feb 2021 04:01:58 GMT X-Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 36rhrduhv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Feb 2021 04:01:57 +0000 X-Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id 1336A67; Thu, 18 Feb 2021 04:01:57 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id D37C54C; Thu, 18 Feb 2021 04:01:55 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Leif Lindholm , Nickle Wang , Michael D Kinney Subject: [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: Add JsonLoadString function Date: Thu, 18 Feb 2021 11:12:19 +0800 Message-Id: <20210218031219.16966-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: mWfn1tBGviyXItTpbds6tZxUx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613620923; bh=mppUlw5KyGjHu8vOEQP7u4ME999qY8Yu8llGgX+cEx8=; h=Cc:Date:From:Reply-To:Subject:To; b=Uv/Sb1NvUFjz32Ybx8Q496wtdzan/9Avf8p48rxtaxlY040s8Xthn4ozmxh94pVDaVV GaVXWgOTlBGf/GUsbvpQQpAciB8pxgwGu53upoQDhE2/N2EXzyEAsnC2qI/IHPrv2IIUU 9dsDsKxwE/M6OEy6JVNTGrrFxYoqqM8d5ME= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add JsonLoadString function to load a NULL terminated-string JSON Signed-off-by: Abner Chang Cc: Leif Lindholm Cc: Nickle Wang Cc: Michael D Kinney Reviewed-by: Nickle Wang --- RedfishPkg/Include/Library/JsonLib.h | 21 +++++++++++++++++++++ RedfishPkg/Library/JsonLib/JsonLib.c | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Libr= ary/JsonLib.h index 3c10f67d27..8a30c5250b 100644 --- a/RedfishPkg/Include/Library/JsonLib.h +++ b/RedfishPkg/Include/Library/JsonLib.h @@ -664,6 +664,27 @@ JsonDumpString ( IN UINTN Flags ); =20 +/** + Convert a string to JSON object. + The function is used to convert a NULL terminated CHAR8 string to a JSON + 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. + + Real number and number with exponent part are not supportted by UEFI. + + Caller needs to cleanup the root value by calling JsonValueFree(). + + @param[in] String The NULL terminated CHAR8 string to convert. + + @retval Array JSON value or object JSON value, or NULL when any err= or occurs. + +**/ +EDKII_JSON_VALUE +EFIAPI +JsonLoadString ( + IN CONST CHAR8* String + ); + /** Load JSON from a buffer. =20 diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/Json= Lib/JsonLib.c index 34ff381aee..3693299afb 100644 --- a/RedfishPkg/Library/JsonLib/JsonLib.c +++ b/RedfishPkg/Library/JsonLib/JsonLib.c @@ -819,6 +819,32 @@ JsonDumpString ( return json_dumps((json_t *)JsonValue, Flags); } =20 +/** + Convert a string to JSON object. + The function is used to convert a NULL terminated CHAR8 string to a JSON + 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. + + Real number and number with exponent part are not supportted by UEFI. + + Caller needs to cleanup the root value by calling JsonValueFree(). + + @param[in] String The NULL terminated CHAR8 string to convert. + + @retval Array JSON value or object JSON value, or NULL when any err= or occurs. + +**/ +EDKII_JSON_VALUE +EFIAPI +JsonLoadString ( + IN CONST CHAR8* String + ) +{ + json_error_t JsonError; + + return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonErro= r); +} + /** Load JSON from a buffer. =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#71776): https://edk2.groups.io/g/devel/message/71776 Mute This Topic: https://groups.io/mt/80722392/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-