From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web10.5714.1611896932543741759 for ; Thu, 28 Jan 2021 21:08:52 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=eOGGfgvl; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=06631716d4=abner.chang@hpe.com) Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10T54Ytt014944; Fri, 29 Jan 2021 05:08:51 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=zjN8uGFzjA7IbK4u94im77A0c2ola3ekgMByUm6Y4H0=; b=eOGGfgvlNEPUOFmG/b0NR/xdrGv+oTtSP7hjySquUZOR3v9H1Atkn1nzMh672Cmat8cg QJKVEUip3S6mSSgYihutxnoEDjh3uTMxka/nopw8KjUMp/e5I+HozEedR6hAWPVDYAC1 9igRM1SpI90YalzrpetgVUvH/8oX2vbvz3QypOM6Embm5+vTV1hJANZYQ/CGiSqGc4vp vRpTAQWEPggmCBKNMsWdLsaLkOtaW9uASr0k3IFQK81PpMD0Fe63m3lmGexlxDEser0i B2EA8NyN47jg6jOpkB9lJQMcsi8OGKJBMum2BYIicV+uACUJZAHByoWaR7VukEVRhy9W 5A== Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0b-002e3701.pphosted.com with ESMTP id 36c0524ta9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Jan 2021 05:08:51 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 322B4B3; Fri, 29 Jan 2021 05:08:51 +0000 (UTC) Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id E59EB37; Fri, 29 Jan 2021 05:08:49 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Leif Lindholm , Nickle Wang , Michael D Kinney Subject: [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function Date: Fri, 29 Jan 2021 12:20:04 +0800 Message-Id: <20210129042004.20663-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.343,18.0.737 definitions=2021-01-29_02:2021-01-28,2021-01-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 clxscore=1015 mlxlogscore=858 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101290026 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..82ca4bad60 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 UTF8 encoded 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 UTF8 encoded 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..00dedc1c60 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 UTF8 encoded 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 UTF8 encoded 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