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.web12.7206.1604021836706600910 for ; Thu, 29 Oct 2020 18:37:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Frv8x9y8; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0572814f16=abner.chang@hpe.com) Received: from pps.filterd (m0134422.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09U1Vroi008016 for ; Fri, 30 Oct 2020 01:37:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=qcM2vyxrjAE4VBFh3Pf509BS7YB2BjxlfDUOgHYg5vo=; b=Frv8x9y83XCObVCRDsnZJwAljItfuiX+LLEnG5vV+xtfx4cG4oMrVjlNvYmAl1Jj441I ZuoiiF7Cy9T17ElvoNYMwLSMTejA/dPtUiLBBV3a9Kny739UppJvdQPwYlg90PBnCHc2 Vm+ZnD5DtV7PrlqzFGq9LWi2VFCAb8GVc4P4QP8S6X/JJhFNIz7HTszeLdNonVu1TN3j OUkYS5A0JCBzV8Iigh9BDIHZhKiB8+m6C/iipR9nGm1BBUCKkrYeyPW85XFR6iZ4jgeC 3ck7QIHyWSvSqPy5UzNrtj/9Rzjjb1fz9ufg04V4Ag/hIHMX7EVOuL9JVzJ07wFjyqiS 3w== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0b-002e3701.pphosted.com with ESMTP id 34fan1xgg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 30 Oct 2020 01:37:16 +0000 Received: from G9W8454.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.161.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g4t3425.houston.hpe.com (Postfix) with ESMTPS id C1AA4AC for ; Fri, 30 Oct 2020 01:37:14 +0000 (UTC) Received: from G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) by G9W8454.americas.hpqcorp.net (2002:10d8:a104::10d8:a104) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 30 Oct 2020 01:37:09 +0000 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (15.241.52.11) by G9W8453.americas.hpqcorp.net (16.216.160.211) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Fri, 30 Oct 2020 01:37:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UBvFsHONDeLcez9e74MhTkRZVw2QRGeQi901F2o5D0OzosqskwWGaYzZ66m/KySdldetx3COciNvjnAktxvd6ph6u9bJxXx7zEjSOWUkGMo/TirbVwhMTAL24jlveYUt4aCnKU77ljGOzORjpO9kHQsPJr0XmwvuXUVeEgDR/5SOM12qvzOzl+Eq5jFRGFdc9tzK/iwDUtYZ96yOtyNRkc6+0u0xPszeIMcxg8YyeVyWbf3NmYA702325RvuYLuwQ0ABLBiJ5PTpdAm/osK0ela5ZLNGRlaZuAdCkjRH2Q6RbKGESYrkxd9a7MyxNlt3WrxX3ww/8O3OH5jsyNt1iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qcM2vyxrjAE4VBFh3Pf509BS7YB2BjxlfDUOgHYg5vo=; b=bM2magRY2k95Dc+B04Z/Rix2a9qHMF4aUz2Cf/zjKpB1m3EzQB7kQXPSbxyB/S6VwdONbvHvvY6QKJtlV2OTdx8u2Y9ADujBEw3SjKoCgVis/SFOqFyvFZZO07Dtezc7DqphceJPZ6wiySavgJ9QThEXIvbAV9MNGrkYUMf9kYRDNolUjDXXOuIGUvPp9bCxYVjA8BillWPuptDfG/4Fw602Zd5Fn4ck4s0F3uDbNXpxfkC4iBT4QQAeOyKkLqEsuEqN3oYfMNxzFTrUpMFP/exF+T7wWVDrYQWR3r5hsc2M5cbZWqNifQmxLIOiwRlb8xk88E0FxqLEhEDkGtcYTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7508::16) by CS1PR8401MB0584.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7507::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 30 Oct 2020 01:37:06 +0000 Received: from CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM ([fe80::f4a5:2722:be1c:7222]) by CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM ([fe80::f4a5:2722:be1c:7222%6]) with mapi id 15.20.3477.035; Fri, 30 Oct 2020 01:37:06 +0000 From: "Abner Chang" To: "Wang, Nickle (HPS SW)" , "devel@edk2.groups.io" CC: Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao Subject: Re: [RestJsonStructureDxe PATCH v3 2/3] RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol Thread-Topic: [RestJsonStructureDxe PATCH v3 2/3] RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol Thread-Index: AQHWoxEFKAtTeOWcQki1RbLJfNzAx6muOspwgAE498A= Date: Fri, 30 Oct 2020 01:37:06 +0000 Message-ID: References: <20201015154928.16211-1-abner.chang@hpe.com> <20201015154928.16211-3-abner.chang@hpe.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: hpe.com; dkim=none (message not signed) header.d=none;hpe.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [1.34.113.40] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 05943d4f-ba16-4aeb-56a2-08d87c744faf x-ms-traffictypediagnostic: CS1PR8401MB0584: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:209; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RtlllvzmrgqFlP6YTpsm/iHxkdFCcvksNgzvRrMus7BgP1TkSbnNqRCoNf+B8l5KD4SRXf+RtO6Y6XeVVgwpVysXqB3Ure2dA8Pf5UxkJMTflyCcaQ/N09WeT8HuiCrQBpYNMEh2h33cSAD+pm3h4ghpCk15OeD0trHmGoPwGjK4/KIId7rrtU3Otxmn6ScazEYZqd3Ph3AUqvhQ9tuYqjVm2S97PmAHbd2vJ5hVm1TB+UTldG+raQCHG4t23ZmQL1GPJu8YhcRbDe9Jkj8ZAdqTaVIu/iAB+bcfwTSOw5tfp3/4GNeIWIXj9jVskMPDsD1SaZzQuo0DmuzHAOM9JQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(39860400002)(376002)(346002)(366004)(396003)(136003)(8936002)(316002)(55016002)(33656002)(8676002)(71200400001)(478600001)(30864003)(7696005)(86362001)(54906003)(9686003)(110136005)(52536014)(66946007)(83380400001)(53546011)(4326008)(6506007)(186003)(66446008)(5660300002)(66556008)(66476007)(64756008)(76116006)(26005)(2906002)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: I7/o56T7fP6EotsoF4mP7lHNS34hAHYzJfjEHA67bTTXyuE9DPdhxJm9i98S6FpJz1XKghVBTWCklQ0Iti1AtSLskiduzHE7GbErFnnTOu8FlbJYMPyAvYi7jz7KTt8KjEnTXY8zkhR7Kr9h/B9Y0zeVlYs1uZZqR16yD2PcvKL5EoHGobm06oVnujaXYeQnb4H1mxQLGud92F+eKQl8HThYEe5e9tp5KX0rYmi2F9/319dA1dfbtSsRF2fDecT2DTp661580SlIH7WSlQJRCuAv+zJcInYPLHPDjJHLV8S76iOSJZynwP6vG3MqKOEBwF2123BLsnWzDe3/PiVVNPAvRUvZpADR+1pph+VG/70NaA2fhQbXcXtCViOwhXJkGQTy+E9GdJpdX37elmBpqKBuFEXeLijv/EXL9BzQm1YDnw6UTpPmWT0vtO79U8wlrsxeAYnhQO+DbQ1VDeQDKGR7ETwupqCPezfoXWeoBSFrev0FeuHkoQwD1SwwHEMbiaDwV2AsTypCP5h4BcZ2EE3GyC+aZDe/HXYRE0YIJa65ewrpAb4XW30UCq8p6e/tGjDSbZ2Se4eqYD20kjk1+Yhboobbtijl72eQR4bsKDgrdEw49gQbds9JUvdZLYp2xyKTnIud5ffRQ3s5Xfp6Og== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 05943d4f-ba16-4aeb-56a2-08d87c744faf X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2020 01:37:06.6867 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: xnSh6UfYWCitYa0epSdPwd0P3HcFvV8Y6bmId8/T+EJnf8HNLodcm7Ne+ZpP46z6NbIbItSZlZwK2LnDQrUdsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0584 X-OriginatorOrg: hpe.com X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-10-29_12:2020-10-29,2020-10-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1015 impostorscore=0 mlxscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010300007 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Wang, Nickle (HPS SW) > Sent: Thursday, October 29, 2020 2:58 PM > To: Chang, Abner (HPS SW/FW Technologist) ; > devel@edk2.groups.io > Cc: Jiaxin Wu ; Siyuan Fu ; Fan > Wang ; Jiewen Yao > Subject: RE: [RestJsonStructureDxe PATCH v3 2/3] > RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol >=20 > Hi Abner, >=20 > I have comment for function RestJsonStructureUnload(). Please check my > inline comment below. >=20 > Thanks, > Nickle >=20 > > -----Original Message----- > > From: Chang, Abner (HPS SW/FW Technologist) > > Sent: Thursday, October 15, 2020 11:49 PM > > To: devel@edk2.groups.io > > Cc: Jiaxin Wu ; Siyuan Fu ; > > Fan Wang ; Jiewen Yao ; > > Wang, Nickle (HPS SW) > > Subject: [RestJsonStructureDxe PATCH v3 2/3] > > RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol > > > > Implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL, refer to UEFI > spec > > 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter. > > > > Signed-off-by: Abner Chang > > > > Cc: Jiaxin Wu > > Cc: Siyuan Fu > > Cc: Fan Wang > > Cc: Jiewen Yao > > Cc: Nickle Wang > > --- > > RedfishPkg/RedfishPkg.dsc | 11 + > > .../RestJsonStructureDxe.c | 585 ++++++++++++++++++ > > .../RestJsonStructureDxe.inf | 40 ++ > > .../RestJsonStructureInternal.h | 33 + > > 4 files changed, 669 insertions(+) > > create mode 100644 > > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > > create mode 100644 > > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > > create mode 100644 > > RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > > > > diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc > > index 8acadddefc..f0c6740fac 100644 > > --- a/RedfishPkg/RedfishPkg.dsc > > +++ b/RedfishPkg/RedfishPkg.dsc > > @@ -38,3 +38,14 @@ > > > > > DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTabl > > eLib.inf > > DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf > > > > > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/Dx > > eReportStatusCodeLib.inf > > + > > +[LibraryClasses.ARM, LibraryClasses.AARCH64] > > + # > > + # This library provides the instrinsic functions generated by a > > +given > > compiler. > > + # > > + NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf > > + NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf > > + ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf > > + > > +[Components] > > + RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > > diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > > new file mode 100644 > > index 0000000000..03fbecf993 > > --- /dev/null > > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c > > @@ -0,0 +1,585 @@ > > +/** @file > > + > > + The implementation of EFI REST Resource JSON to C structure > > + convertor Protocol. > > + > > + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> > + > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#include > > +#include #include > > +"RestJsonStructureInternal.h" > > + > > +LIST_ENTRY mRestJsonStructureList; > > +EFI_HANDLE mProtocolHandle; > > + > > +/** > > + This function registers Restful resource interpreter for the > > + specific schema. > > + > > + @param[in] This This is the > > EFI_REST_JSON_STRUCTURE_PROTOCOL instance. > > + @param[in] JsonStructureSupported The type and version of REST > JSON > > resource which this converter > > + supports. > > + @param[in] ToStructure The function to convert REST = JSON > > resource to structure. > > + @param[in] ToJson The function to convert REST = JSON > structure > > to JSON in text format. > > + @param[in] DestroyStructure Destroy REST JSON structure > returned > > in ToStructure() function. > > + > > + @retval EFI_SUCCESS Register successfully. > > + @retval Others Fail to register. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureRegister ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN EFI_REST_JSON_STRUCTURE_SUPPORTED > *JsonStructureSupported, > > + IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE ToStructure, > > + IN EFI_REST_JSON_STRUCTURE_TO_JSON ToJson, > > + IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure > > +) > > +{ > > + UINTN NumberOfNS; > > + UINTN Index; > > + LIST_ENTRY *ThisList; > > + REST_JSON_STRUCTURE_INSTANCE *Instance; > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId; > > + EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp; > > + > > + if (This =3D=3D NULL || > > + ToStructure =3D=3D NULL || > > + ToJson =3D=3D NULL || > > + DestroyStructure =3D=3D NULL || > > + JsonStructureSupported =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + // > > + // Check how many name space interpreter can interpret. > > + // > > + ThisList =3D &JsonStructureSupported->NextSupportedRsrcInterp; > > + NumberOfNS =3D 1; > > + while (TRUE) { > > + if (ThisList->ForwardLink =3D=3D &JsonStructureSupported- > > >NextSupportedRsrcInterp) { > > + break; > > + } else { > > + ThisList =3D ThisList->ForwardLink; > > + NumberOfNS ++; > > + } > > + }; > > + > > + Instance =3D > > + (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof > > (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof > > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); > > + if (Instance =3D=3D NULL) { > > + return EFI_OUT_OF_RESOURCES; > > + } > > + InitializeListHead (&Instance->NextRestJsonStructureInstance); > > + Instance->NumberOfNameSpaceToConvert =3D NumberOfNS; > > + Instance->SupportedRsrcIndentifier =3D > > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > > *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1); > > + // > > + // Copy supported resource identifer interpreter. > > + // > > + CloneSupportedInterpId =3D Instance->SupportedRsrcIndentifier; > > + ThisSupportedInterp =3D JsonStructureSupported; for (Index =3D 0; > > + Index < NumberOfNS; Index ++) { > > + CopyMem ((VOID *)CloneSupportedInterpId, (VOID > > *)&ThisSupportedInterp->RestResourceInterp, sizeof > > (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); > > + ThisSupportedInterp =3D (EFI_REST_JSON_STRUCTURE_SUPPORTED > > *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink; > > + CloneSupportedInterpId ++; > > + } > > + Instance->JsonToStructure =3D ToStructure; Instance->StructureToJso= n > > + =3D ToJson; Instance->DestroyStructure =3D DestroyStructure; > > + InsertTailList (&mRestJsonStructureList, &Instance- > > >NextRestJsonStructureInstance); > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + This function check if this interpreter instance support the given > > namesapce. > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > > instance. > > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > > + @param[in] RsrcTypeIdentifier Resource type identifier. > > + @param[in] ResourceRaw Given Restful resource. > > + @param[out] RestJSonHeader Property interpreted from given > > ResourceRaw. > > + > > + @retval EFI_SUCCESS > > + @retval Others. > > + > > +**/ > > +EFI_STATUS > > +InterpreterInstanceToStruct ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > > + IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier > > OPTIONAL, > > + IN CHAR8 *ResourceRaw, > > + OUT EFI_REST_JSON_STRUCTURE_HEADER **RestJSonHeader > > + ) > > +{ > > + UINTN Index; > > + EFI_STATUS Status; > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > *ThisSupportedRsrcTypeId; > > + > > + if (This =3D=3D NULL || > > + InterpreterInstance =3D=3D NULL || > > + ResourceRaw =3D=3D NULL || > > + RestJSonHeader =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + Status =3D EFI_UNSUPPORTED; > > + if (RsrcTypeIdentifier =3D=3D NULL) { > > + // > > + // No resource type identifier, send to intepreter anyway. > > + // Interpreter may recognize this resource. > > + // > > + Status =3D InterpreterInstance->JsonToStructure ( > > + This, > > + NULL, > > + ResourceRaw, > > + RestJSonHeader > > + ); > > + } else { > > + // > > + // Check if the namesapce and version is supported by this interpr= eter. > > + // > > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > > >SupportedRsrcIndentifier; > > + for (Index =3D 0; Index < InterpreterInstance- > > >NumberOfNameSpaceToConvert; Index ++){ > > + if (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.ResourceTypeName, > > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D= =3D 0){ > > + if ((RsrcTypeIdentifier->NameSpace.MajorVersion =3D=3D NULL) &= & > > + (RsrcTypeIdentifier->NameSpace.MinorVersion =3D=3D NULL) &= & > > + (RsrcTypeIdentifier->NameSpace.ErrataVersion =3D=3D NULL) > > + ) { > > + // > > + // Don't check version of this resource type identifier. > > + // > > + Status =3D InterpreterInstance->JsonToStructure ( > > + This, > > + RsrcTypeIdentifier, > > + ResourceRaw, > > + RestJSonHeader > > + ); > > + break; > > + } else { > > + // > > + // Check version. > > + // > > + if ((AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.MajorVersion, > > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D= =3D 0) && > > + (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.MinorVersion, > > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D= =3D 0) && > > + (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.ErrataVersion, > > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D= =3D 0)) { > > + Status =3D InterpreterInstance->JsonToStructure ( > > + This, > > + RsrcTypeIdentifier, > > + ResourceRaw, > > + RestJSonHeader > > + ); > > + break; > > + } > > + } > > + } > > + ThisSupportedRsrcTypeId ++; > > + } > > + } > > + return Status; > > +} > > +/** > > + This function converts JSON C structure to JSON property. > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > > instance. > > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > > + @param[in] RestJSonHeader Resource type identifier. > > + @param[out] ResourceRaw Output in JSON text format. > > + > > + @retval EFI_SUCCESS > > + @retval Others. > > + > > +**/ > > +EFI_STATUS > > +InterpreterEfiStructToInstance ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader, > > + OUT CHAR8 **ResourceRaw > > +) > > +{ > > + UINTN Index; > > + EFI_STATUS Status; > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > *ThisSupportedRsrcTypeId; > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier; > > + > > + if (This =3D=3D NULL || > > + InterpreterInstance =3D=3D NULL || > > + RestJSonHeader =3D=3D NULL || > > + ResourceRaw =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + RsrcTypeIdentifier =3D &RestJSonHeader->JsonRsrcIdentifier; > > + if (RsrcTypeIdentifier =3D=3D NULL || > > + RsrcTypeIdentifier->NameSpace.ResourceTypeName =3D=3D NULL || > > + RsrcTypeIdentifier->NameSpace.MajorVersion =3D=3D NULL || > > + RsrcTypeIdentifier->NameSpace.MinorVersion =3D=3D NULL || > > + RsrcTypeIdentifier->NameSpace.ErrataVersion =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + // > > + // Check if the namesapce and version is supported by this interpret= er. > > + // > > + Status =3D EFI_UNSUPPORTED; > > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > > >SupportedRsrcIndentifier; > > + for (Index =3D 0; Index < InterpreterInstance- > > >NumberOfNameSpaceToConvert; Index ++){ > > + if (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.ResourceTypeName, > > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D=3D = 0){ > > + // > > + // Check version. > > + // > > + if ((AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.MajorVersion, > > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D=3D 0)= && > > + (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.MinorVersion, > > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D=3D 0)= && > > + (AsciiStrCmp ( > > + RsrcTypeIdentifier->NameSpace.ErrataVersion, > > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D=3D 0= )) { > > + Status =3D InterpreterInstance->StructureToJson ( > > + This, > > + RestJSonHeader, > > + ResourceRaw > > + ); > > + break; > > + } > > + } > > + ThisSupportedRsrcTypeId ++; > > + } > > + return Status; > > +} > > + > > +/** > > + This function destory REST property structure. > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > > instance. > > + @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE > > + @param[in] RestJSonHeader Property interpreted from given > > ResourceRaw. > > + > > + @retval EFI_SUCCESS > > + @retval Others. > > + > > +**/ > > +EFI_STATUS > > +InterpreterInstanceDestoryJsonStruct ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance, > > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader > > + ) > > +{ > > + UINTN Index; > > + EFI_STATUS Status; > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > *ThisSupportedRsrcTypeId; > > + > > + if (This =3D=3D NULL || > > + InterpreterInstance =3D=3D NULL || > > + RestJSonHeader =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + Status =3D EFI_UNSUPPORTED; > > + // > > + // Check if the namesapce and version is supported by this interpret= er. > > + // > > + ThisSupportedRsrcTypeId =3D InterpreterInstance- > > >SupportedRsrcIndentifier; > > + for (Index =3D 0; Index < InterpreterInstance- > > >NumberOfNameSpaceToConvert; Index ++){ > > + if (AsciiStrCmp ( > > + RestJSonHeader- > >JsonRsrcIdentifier.NameSpace.ResourceTypeName, > > + ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) =3D=3D = 0) { > > + if ((RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion > > + =3D=3D > > NULL) && > > + (RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion > > + =3D=3D > > NULL) && > > + (RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion > > + =3D=3D > > NULL) > > + ) { > > + // > > + // Don't check version of this resource type identifier. > > + // > > + Status =3D InterpreterInstance->DestroyStructure ( > > + This, > > + RestJSonHeader > > + ); > > + break; > > + } else { > > + // > > + // Check version. > > + // > > + if ((AsciiStrCmp ( > > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersio= n, > > + ThisSupportedRsrcTypeId->NameSpace.MajorVersion) =3D=3D = 0) && > > + (AsciiStrCmp ( > > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersio= n, > > + ThisSupportedRsrcTypeId->NameSpace.MinorVersion) =3D=3D = 0) && > > + (AsciiStrCmp ( > > + RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersi= on, > > + ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) =3D=3D= 0)) { > > + Status =3D InterpreterInstance->DestroyStructure ( > > + This, > > + RestJSonHeader > > + ); > > + break; > > + } > > + } > > + } > > + ThisSupportedRsrcTypeId ++; > > + } > > + return Status; > > +} > > + > > +/** > > + This function translates the given JSON text to JSON C Structure. > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > > instance. > > + @param[in] RsrcTypeIdentifier Resource type identifier. > > + @param[in] ResourceJsonText Given Restful resource. > > + @param[out] JsonStructure Property interpreted from given > > ResourceRaw. > > + > > + @retval EFI_SUCCESS > > + @retval Others. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureToStruct ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier > > OPTIONAL, > > + IN CHAR8 *ResourceJsonText, > > + OUT EFI_REST_JSON_STRUCTURE_HEADER **JsonStructure > > +) > > +{ > > + EFI_STATUS Status; > > + REST_JSON_STRUCTURE_INSTANCE *Instance; > > + > > + if (This =3D=3D NULL || > > + ResourceJsonText =3D=3D NULL || > > + JsonStructure =3D=3D NULL > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + if (IsListEmpty (&mRestJsonStructureList)) { > > + return EFI_UNSUPPORTED; > > + } > > + Status =3D EFI_SUCCESS; > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > > (&mRestJsonStructureList); > > + while (TRUE) { > > + Status =3D InterpreterInstanceToStruct ( > > + This, > > + Instance, > > + RsrcTypeIdentifier, > > + ResourceJsonText, > > + JsonStructure > > + ); > > + if (!EFI_ERROR (Status)) { > > + break; > > + } > > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > > >NextRestJsonStructureInstance)) { > > + Status =3D EFI_UNSUPPORTED; > > + break; > > + } > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > > + }; > > + return Status; > > +} > > + > > +/** > > + This function destory REST property EFI structure which returned in > > + JsonToStructure(). > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > > + @param[in] RestJSonHeader Property to destory. > > + > > + @retval EFI_SUCCESS > > + @retval Others > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureDestroyStruct ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader > > +) > > +{ > > + EFI_STATUS Status; > > + REST_JSON_STRUCTURE_INSTANCE *Instance; > > + > > + if (This =3D=3D NULL || RestJSonHeader =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + if (IsListEmpty (&mRestJsonStructureList)) { > > + return EFI_UNSUPPORTED; > > + } > > + Status =3D EFI_SUCCESS; > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > > (&mRestJsonStructureList); > > + while (TRUE) { > > + Status =3D InterpreterInstanceDestoryJsonStruct ( > > + This, > > + Instance, > > + RestJSonHeader > > + ); > > + if (!EFI_ERROR (Status)) { > > + break; > > + } > > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > > >NextRestJsonStructureInstance)) { > > + Status =3D EFI_UNSUPPORTED; > > + break; > > + } > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > > + }; > > + return Status; > > +} > > + > > +/** > > + This function translates the given JSON C Structure to JSON text. > > + > > + @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL > instance. > > + @param[in] RestJSonHeader Given Restful resource. > > + @param[out] ResourceRaw Resource in RESTfuls service oriented. > > + > > + @retval EFI_SUCCESS > > + @retval Others Fail to remove the entry > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureToJson ( > > + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This, > > + IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader, > > + OUT CHAR8 **ResourceRaw > > +) > > +{ > > + EFI_STATUS Status; > > + REST_JSON_STRUCTURE_INSTANCE *Instance; > > + > > + if (This =3D=3D NULL || RestJSonHeader =3D=3D NULL || ResourceRaw = =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + if (IsListEmpty (&mRestJsonStructureList)) { > > + return EFI_UNSUPPORTED; > > + } > > + Status =3D EFI_SUCCESS; > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > > (&mRestJsonStructureList); > > + while (TRUE) { > > + Status =3D InterpreterEfiStructToInstance ( > > + This, > > + Instance, > > + RestJSonHeader, > > + ResourceRaw > > + ); > > + if (!EFI_ERROR (Status)) { > > + break; > > + } > > + if (IsNodeAtEnd(&mRestJsonStructureList, &Instance- > > >NextRestJsonStructureInstance)) { > > + Status =3D EFI_UNSUPPORTED; > > + break; > > + } > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > > + }; > > + return Status; > > +} > > + > > +EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol =3D { > > + RestJsonStructureRegister, > > + RestJsonStructureToStruct, > > + RestJsonStructureToJson, > > + RestJsonStructureDestroyStruct > > +}; > > + > > +/** > > + This is the declaration of an EFI image entry point. > > + > > + @param ImageHandle The firmware allocated handle for the = UEFI > > image. > > + @param SystemTable A pointer to the EFI System Table. > > + > > + @retval EFI_SUCCESS The operation completed successfully. > > + @retval Others An unexpected error occurred. > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureEntryPoint ( > > + IN EFI_HANDLE ImageHandle, > > + IN EFI_SYSTEM_TABLE *SystemTable > > + ) > > +{ > > + EFI_STATUS Status; > > + > > + InitializeListHead (&mRestJsonStructureList); > > + // > > + // Install the Restful Resource Interpreter Protocol. > > + // > > + mProtocolHandle =3D NULL; > > + Status =3D gBS->InstallProtocolInterface ( > > + &mProtocolHandle, > > + &gEfiRestJsonStructureProtocolGuid, > > + EFI_NATIVE_INTERFACE, > > + (VOID *)&mRestJsonStructureProtocol > > + ); > > + return Status; > > +} > > + > > +/** > > + This is the unload handle for Redfish discover module. > > + > > + Disconnect the driver specified by ImageHandle from all the devices > > + in the > > handle database. > > + Uninstall all the protocols installed in the driver entry point. > > + > > + @param[in] ImageHandle The drivers' driver image. > > + > > + @retval EFI_SUCCESS The image is unloaded. > > + @retval Others Failed to unload the image. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +RestJsonStructureUnload ( > > + IN EFI_HANDLE ImageHandle > > + ) > > +{ > > + EFI_STATUS Status; > > + REST_JSON_STRUCTURE_INSTANCE *Instance; > > + REST_JSON_STRUCTURE_INSTANCE *NextInstance; > > + > > + if (IsListEmpty (&mRestJsonStructureList)) { > > + return EFI_SUCCESS; > > + } > We still need to uninstall REST Json Structure Protocol when list is empt= y, > right? The protocol is installed on driver entry when list is empty. [Chang, Abner]=20 Thanks for catching this. That issue is fixed in V4 (just sent) of patches = set. Abner >=20 > > + // > > + // Free memory of REST_JSON_STRUCTURE_INSTANCE instance. > > + // > > + Instance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode > > (&mRestJsonStructureList); > > + do { > > + NextInstance =3D NULL; > > + if (!IsNodeAtEnd(&mRestJsonStructureList, &Instance- > > >NextRestJsonStructureInstance)) { > > + NextInstance =3D (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode > > (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance); > > + } > > + FreePool ((VOID *)Instance); > > + Instance =3D NextInstance; > > + } while (Instance !=3D NULL); > > + > > + Status =3D gBS->UninstallProtocolInterface ( > > + mProtocolHandle, > > + &gEfiRestJsonStructureProtocolGuid, > > + (VOID *)&mRestJsonStructureProtocol > > + ); > > + return Status; > > +} > > diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > > new file mode 100644 > > index 0000000000..2ab1e3bc45 > > --- /dev/null > > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf > > @@ -0,0 +1,40 @@ > > +## @file > > +# Implementation of EFI REST JSON Structure Protocol. > > +# > > +# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
# > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ## > > + > > +[Defines] > > + INF_VERSION =3D 0x00010005 > > + BASE_NAME =3D RestJsonStructureDxe > > + FILE_GUID =3D 83FAAFBF-FC4B-469F-892A-798E66A6F50A > > + MODULE_TYPE =3D DXE_DRIVER > > + VERSION_STRING =3D 1.0 > > + ENTRY_POINT =3D RestJsonStructureEntryPoint > > + UNLOAD_IMAGE =3D RestJsonStructureUnload > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + MdeModulePkg/MdeModulePkg.dec > > + RedfishPkg/RedfishPkg.dec > > + > > +[Sources] > > + RestJsonStructureDxe.c > > + RestJsonStructureInternal.h > > + > > +[LibraryClasses] > > + BaseLib > > + BaseMemoryLib > > + MemoryAllocationLib > > + UefiBootServicesTableLib > > + UefiDriverEntryPoint > > + UefiLib > > + > > +[Protocols] > > + gEfiRestJsonStructureProtocolGuid ## Producing > > + > > +[Depex] > > + TRUE > > + > > diff --git > > a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > > b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > > new file mode 100644 > > index 0000000000..e8a3408404 > > --- /dev/null > > +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h > > @@ -0,0 +1,33 @@ > > +/** @file > > + The internal definitions of EFI REST Resource JSON to C structure > > +convertor > > + Protocol. > > + > > + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> > + > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#ifndef EFI_REST_JSON_STRUCTURE_INTERNAL_H_ > > +#define EFI_REST_JSON_STRUCTURE_INTERNAL_H_ > > + > > +#include > > +#include > > +#include > > +#include #include > > + #include > > + > > +/// > > +/// Internal structure to maintain the information of JSON to /// C > > +structure convertor. > > +/// > > +typedef struct _REST_JSON_STRUCTURE_INSTANCE { > > + LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor > instance > > + UINTN NumberOfNameSpaceToConvert; ///< Number of resource > > type this convertor supports. > > + EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER > > *SupportedRsrcIndentifier; ///< The resource type linklist > > + EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; > > ///< JSON to C structure function > > + EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; = ///< > C > > structure to JSON function > > + EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; > > ///< Destory C struture function. > > +} REST_JSON_STRUCTURE_INSTANCE; > > +#endif > > -- > > 2.17.1