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.web08.32528.1611552033741754507 for ; Sun, 24 Jan 2021 21:20:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=n9GyQtGQ; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0659271e3c=abner.chang@hpe.com) Received: from pps.filterd (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10P5I8mU032317; Mon, 25 Jan 2021 05:20:32 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=p+087vXrb6veOdIoXJ/ZXAdblp4H6DMiNcmhEJBGmkU=; b=n9GyQtGQqjlpHZUHEYJ+j+1KkldjVFUF2dVHLx1LFvZdSiwoceaE2i6NpCMKVf6wk1D2 lcox08z2ZaLcEQT2Wg2WStM4V0QkHUjbzSsTMHCGJ0/kIqeCVgaq2f6/7VBHBWOFEsl3 H8IVjI5HJzF+UH0KSYjwcsRbPrJpI///nnGqfgcpiZBndEObXViX4mT/e1hqjsLxzN3B 7BWX0zjH/mKrbJN5Xxk5Up5LhHQzEURa3JdyyM+sMxF6Wj+gV2g3bXCHyOPQ5CpGFci0 v64DlQE5O8Fayc0M6T+CHrE/TPIKOo6KY003FG7dU5hViCNf2zXPkwVGtLCXXNoD5QL2 jA== Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0b-002e3701.pphosted.com with ESMTP id 368cf5smug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Jan 2021 05:20:32 +0000 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g9t5009.houston.hpe.com (Postfix) with ESMTP id B4B1F71; Mon, 25 Jan 2021 05:20:31 +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 785124B; Mon, 25 Jan 2021 05:20:30 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Leif Lindholm , Nickle Wang , Michael D Kinney Subject: [PATCH] RedfishPkg/JsonLib: Fix build errors Date: Mon, 25 Jan 2021 12:31:54 +0800 Message-Id: <20210125043154.20645-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-25_01:2021-01-22,2021-01-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 malwarescore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101250029 This patch fixes the build errors when build JsonLib with EDK2 Redfish feature driver. - Add JsonLoadString function to load a NULL terminated-string JSON - json_string_value() in JsonValueGetAsciiString () is removed by accident. Signed-off-by: Abner Chang Cc: Leif Lindholm Cc: Nickle Wang Cc: Michael D Kinney --- RedfishPkg/Library/JsonLib/JsonLib.inf | 5 +++-- RedfishPkg/Include/Library/JsonLib.h | 21 ++++++++++++++++++ RedfishPkg/Library/JsonLib/JsonLib.c | 30 ++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/RedfishPkg/Library/JsonLib/JsonLib.inf b/RedfishPkg/Library/JsonLib/JsonLib.inf index 48b094a78a..9d52a622e1 100644 --- a/RedfishPkg/Library/JsonLib/JsonLib.inf +++ b/RedfishPkg/Library/JsonLib/JsonLib.inf @@ -75,12 +75,13 @@ # C4244: conversion from type1 to type2, possible loss of data # C4334: 32-bit shift implicitly converted to 64-bit # C4204: nonstandard extension used: non-constant aggregate initializer + # C4706: assignment within conditional expression # # Define macro HAVE_CONFIG_H to include jansson_private_config.h to build. # Undefined _WIN32, WIN64, _MSC_VER macros # On GCC, no error on the unused-function and unused-but-set-variable. # - MSFT:*_*_X64_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4334 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER - MSFT:*_*_IA32_CC_FLAGS = /wd4204 /wd4244 /wd4090 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER + MSFT:*_*_X64_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4334 /wd4706 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER + MSFT:*_*_IA32_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4706 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER GCC:*_*_*_CC_FLAGS = -Wno-unused-function -Wno-unused-but-set-variable 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..1762c6f5af 100644 --- a/RedfishPkg/Library/JsonLib/JsonLib.c +++ b/RedfishPkg/Library/JsonLib/JsonLib.c @@ -430,10 +430,10 @@ JsonValueGetAsciiString ( IN EDKII_JSON_VALUE Json ) { - CHAR8 *AsciiStr; + CONST CHAR8 *AsciiStr; UINTN Index; - AsciiStr = (CHAR8 *) ((json_t *) Json); + AsciiStr = json_string_value ((json_t *) Json); if (AsciiStr == NULL) { return NULL; } @@ -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