From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=jLNJUVVo; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=06830be148=abner.chang@hpe.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id; s=pps0720; bh=kC/ZCe9Ky/Ybox18n2U887kP7i8JdQK2BJqU55ZZgdw=; b=jLNJUVVoRgUOLIeh5+rwDU9WqrPNnyg+JUiUxp7TRz6PksEmRWFUk50zQ4daq8v4DW/N BoiWKyTkssCdgigThow3uEvuDhYta1QXWxtfqGZARvE0RWEbXK9/0orHmJr2Se/aSolP YQS7Tz2XBjPMuHKhS/xpnuwG2dEGkH33q7RjvaZFgzMRa6CR9OdT62ocmXe/WuuS6JG/ XDlzTy3tfBVbpoIjXQGfSD869nTW4FaJo5XM5lH4tRLFMNeXS41jGHEShJ0LZTv6IRIF uUzg3h9ARGNGJG/Bc9yPzQ4Y4eysFWEMTiwcV6vz5xjyVUP1XiCfm4YiTS/LADgJwi7e 4A== 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 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) 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: [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-Mailer: git-send-email 2.17.1 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-02-18_01:2021-02-18,2021-02-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=920 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102180030 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 --- 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/Library/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 ); +/** + 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 successfully, + 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 error occurs. + +**/ +EDKII_JSON_VALUE +EFIAPI +JsonLoadString ( + IN CONST CHAR8* String + ); + /** Load JSON from a buffer. diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/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); } +/** + 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 successfully, + 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 error occurs. + +**/ +EDKII_JSON_VALUE +EFIAPI +JsonLoadString ( + IN CONST CHAR8* String + ) +{ + json_error_t JsonError; + + return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError); +} + /** Load JSON from a buffer. -- 2.17.1