From nobody Sun May 5 14:36:11 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+70886+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+70886+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1611896938; cv=none; d=zohomail.com; s=zohoarc; b=jADKHNhighPwuy6QJU2TXTCkIIVmiKG/HPDkC+NwQVVbv0c/PiYTORrTUJ2sVef3aSXsO8BQ9ynZ+xQKwtDzDS/TA6KSr8rfYeHn6x+u9Xs+Tp0KR9MOcKTD4/Gjgzgt7OJX1tS7OnOP05yfLszHrJq38x96lLq77Rzdi9WU+/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611896938; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=dHmD42AYyqzFhIIheyqOA83B0I0n+POwKpUcWduQWJM=; b=ZcJoAI+kNDrrIf+J4yKllm3pBFR5da6OhlWpujFRMoUSY4dLLEV2jbNd/GYNHvy7jID0vRO8QXpbZuXXuwmjS50qzExll4kw08t9ustBWyFX21PDuhp4+bEbPbCBUZpxuOrY8utLRJKtO7cdQV3NBm6B5T5hyDP9IMzsizDSEMA= 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+70886+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 1611896938469976.6506781605747; Thu, 28 Jan 2021 21:08:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0VRFYY1788612xSHDBqFmpIY; Thu, 28 Jan 2021 21:08:58 -0800 X-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 X-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 X-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 X-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) X-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: [edk2-devel] [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-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: yzdI8ScmlWIorQryxQYDwPcSx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611896938; bh=80Pu9LVoUkj9wcPER57ZjQPYlXijdtKHVrMpKEDGVc4=; h=Cc:Date:From:Reply-To:Subject:To; b=fLS/Pn6zE3IvVjusgyCtXNMu7bGQn19RZ/0dt8OgIQwYvWlK9wfU0RJZNQNqc8Ykjdf ucGB1pPlETzFUEVcc+mJfAIgAxukvGJsh0dV9Wh8rh7N68+TYTqy4uAG4VXrNgavjlZof bP5Id2nN+qEgZpCtdfFkDTvoZAP/Dj/8NCA= 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 --- 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..82ca4bad60 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 UTF8 encoded 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 UTF8 encoded string to co= nvert + + @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..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); } =20 +/** + 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 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 UTF8 encoded string to co= nvert + + @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 (#70886): https://edk2.groups.io/g/devel/message/70886 Mute This Topic: https://groups.io/mt/80203698/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-