From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.49]) by mx.groups.io with SMTP id smtpd.web11.14629.1683105630662893728 for ; Wed, 03 May 2023 02:20:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=jRmrpu2z; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.100.49, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ksZfGkGxObXDRpsFAu3qcdipkcENLxe1CV8TehDOO9I4Ut3XTjWu3Et19uM4shEorgHvhPuKjKUC86l7XFWLIoMQjOBpU3YZAB+ckygAG78n1kmpVTksON5Y0v84IfD3E1Cu6Mp8+agpiiLe+pB/DwwddeDMQo0Cfct5mHOujXfPNYRas7+rZ5TQzHd2vO5Ji4oUrK9FIKEAS8HnzmDAkPWd+mfu0kb0tALv+IwuuXKSedpD8pSKzzdeF/x+LuJSeYzh7gj8fHloN54ImPiwiMMV/G8P2d2c/rodslEpAAxrup+nNQ9xyxNDdIhjcmLlK/2l98eBMKEeB32vNxNz/g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5JR1NjObaLIOXe006gDN7Dg7fsxJovULYuDZYHhbE8Y=; b=Amf64aCxBE8bt8gPsnrL6yhYuKCeeIPy1/af4K9/GWv3Ytb2EAuGEC4JXbhUNDjcostz48gr4iTVyYHndWHEjzloFIVvUfOQ+FiPL7pVmrwEq4iJMaOMHNsTUgAKzkMZ/u+zEOac4BASUd2fg219Gj01kFor4X77Hz90zglN0vkjkRW5G7wwzelL8tLMGcNcORW9KvirQI/SkJUDZfEQOc8VfFn88uJzOnGfjhoFCd0gFQTwRs5y+zzq3Ydb8lqwKa+faHjMKOCH2enCZfpuXU613rJagLyHHgs/DObm8b+2QcadvPsgLp08bdVdo93jAPRsg5AZ9syMQ7X2G7hl3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5JR1NjObaLIOXe006gDN7Dg7fsxJovULYuDZYHhbE8Y=; b=jRmrpu2z+a9Prd78siM74P4wymomXB26I55hsjN7Vyhwaf7UqEJL28tBOeMxS+sASC1I//yVkLe8X/9sHJNcvNZaYfIC4eizkINyNcG9HNadqAm/O9xPSCE7NYuV+52WWEWuOv4JAYz3YW1giN/H7CMeisRytly81TStv8MZT9fXek155G661jVKdSiOwi6Q+M4kFY7DxGaymhccl4TMeCihMgJVbOl891a661ZQ+EnTi04ggrZknF8DjvTJoyVuoRoDFxydQ99m02jAii5FmrA3V2xyfQLoOlfk23tURjQ+UpznpOA1myBv7Qoo6CSG9OZ6vmEgldqvhHAsoknAsQ== Received: from MW4PR12MB7031.namprd12.prod.outlook.com (2603:10b6:303:1ef::6) by CY5PR12MB6251.namprd12.prod.outlook.com (2603:10b6:930:21::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Wed, 3 May 2023 09:20:27 +0000 Received: from MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::d9df:b45b:2cc1:f017]) by MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::d9df:b45b:2cc1:f017%5]) with mapi id 15.20.6340.031; Wed, 3 May 2023 09:20:27 +0000 From: "Nickle Wang" To: "abner.chang@amd.com" , "devel@edk2.groups.io" CC: Igor Kulchytskyy Subject: Re: [edk2-redfish-client][PATCH] RedfishClientPkg/ConvertLib: Common code and header files Thread-Topic: [edk2-redfish-client][PATCH] RedfishClientPkg/ConvertLib: Common code and header files Thread-Index: AQHZfZe4RE+eYmqJskW4JeSgpt94KK9IRcgA Date: Wed, 3 May 2023 09:20:26 +0000 Message-ID: References: <20230503081712.1752-1-abner.chang@amd.com> In-Reply-To: <20230503081712.1752-1-abner.chang@amd.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR12MB7031:EE_|CY5PR12MB6251:EE_ x-ms-office365-filtering-correlation-id: 7dfcaa59-1eb2-40b2-93dd-08db4bb7a1d9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /TBt97SYCV+Rf2ozBUPgAcvNuKdR3zhAxaQzbpwDZtF1qhCdNRt+JHxOMK8HeHPePnyxwb7SvGaHyGMPfzjZvoOkBxMe8CEf+aJ9St8SBlohSEWNAv/g+aFnnxJRM7Z4f9kweaPyBKg/EmdgZkFYEQwxdIFCFEc5Xq+DoLoQFNXdcs9n7jtdHpATm7INu5zWklnuPIb3efpvS+CuHJEhvVwd06sSViS1J4effODB/7Xmx7hlKKTMzsfP5xhqx4TO8tWExgjB1yozFLBk51tkm0EiIyl0rqv5BxyXEmINcith5PI0POX0VZ9pXP2CkwUmmjmenzZ7CjuveZLBfUCCeN0+FHPEVBwpMLJ/6TNtZ6XaeVCd7641aKFKuHP2C+oWmxnRdNlInmyAluQexiWJiS04a1V1enMOpAD518UoV82qDQ9oeE/kh37hlcBy66JUPr4E75VoS+D2m7PGmDfmHn5HvQ/9vN26S577x1ambgk+UYyPBk1HQjEcHcz9cBHRZm7y0tOUBn6yu7HqjCz9CkpYLs4BY/nAYIP10fv2ZFly2dUg3xP/FHvuhKtkQRFDl7saFu2J+vDX6z3Of8GxGJXo0RUN94j7yoYWTV1h39U= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR12MB7031.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(376002)(136003)(366004)(451199021)(86362001)(33656002)(38070700005)(122000001)(38100700002)(9686003)(83380400001)(53546011)(110136005)(45080400002)(71200400001)(478600001)(6506007)(186003)(966005)(7696005)(64756008)(8936002)(76116006)(4326008)(41300700001)(316002)(66556008)(19627235002)(66946007)(66476007)(66446008)(55016003)(2906002)(5660300002)(30864003)(52536014)(8676002)(579004)(559001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?uNd6Ld0/SwdJ1fpNCEPQ53TpSM3aF/1qobtavRs4gxq9wrxjjxccLX+VeWRA?= =?us-ascii?Q?VuqG6FhQ1jhrk9tjfoVxQFw7NkxheyGX9m5wZbxY3kf/U9wd0u1T3cPtdg5o?= =?us-ascii?Q?7xJbkekLjv0DoFLukUE80PM4UbFTbMil/O5vsqjld7I2V5Afvu42idJTaAQK?= =?us-ascii?Q?jCjGEfEjZky7XsqDvjvXQlomG80Dv9tf/xOL2rGKpdxMzmVuTUawoi/UlfAx?= =?us-ascii?Q?GV8W43KkTSxV6bY7MXKFUcFffBzemXozJL0ZCrFiiprIgvFBmJEksBYdRbTH?= =?us-ascii?Q?w7b+SkLkTFygZQE6gFvAe3q7WsaDj6n+35DKpH/u6gVTCRdI0nlEzSypoRRm?= =?us-ascii?Q?JQrA5ttRHoS9UbKMuIamxx1RcYHloRMwpoalzS3jZ+nPEzV+n9mxy5wtZBI8?= =?us-ascii?Q?AA2+LnRlIc7joCeG1lxSgIRMyHqMqjv9Zs6Xt1+WH3hVGsiQ1my+OrMzEImh?= =?us-ascii?Q?6ZOJHuAef4J5BeYUcPBV62nhPhzM8hd9K7yGpq9CevRiSx5MdXaLMdoqgMO/?= =?us-ascii?Q?hH7osU47mCrnVV8sgyH5b1KbysY33i42JC2Dld9oPK+hv+Yd4aF4oT82Wut1?= =?us-ascii?Q?JAg7b1zIDWIhiZ+iZidhmdp5tToQ1fE9GmWQpogToe1dK5eoXY0xNMoq2fbD?= =?us-ascii?Q?wu65tdoqNaEd+j/bz3axphBGJ2qr7jb805OkiMhhQ9pKIb5eGSrIj2CMChub?= =?us-ascii?Q?8XDyakIQt2FdPOzepK7oRc+4aQ7iMRwZ9EtSMZIUNqdMbw+E8Hsa8j+j/Hik?= =?us-ascii?Q?/2DHagG3RZzRForrAhMGbIE95EI9IbB4jvDxsSRYxpA6PwHcPt1w1RALaRpj?= =?us-ascii?Q?4UEFwVgCc04PyFLgTi4tfkrxF0qDIwg2yHCo5bsrMj1a+krZYuA69EC9NnZ4?= =?us-ascii?Q?AzXiNsLu24NSd0OcJkKP5K3bhEnZ7fuuWokvn+wov64UEmHYYKQUveL8/oj6?= =?us-ascii?Q?pdtCE5uJxgXfTo3c149Bif777B0VZ1v0wSV1CVxfGHL5uJI46PwbMOgamatn?= =?us-ascii?Q?7wcEl3NFnKxeyqX/MIShTYjgYEt/8u+pSQQoVABisHvOFHcCuR+B5d6tgRsq?= =?us-ascii?Q?lfgM0zMllTZ0NmTsOO584SHI2OJjnGUjcmCpcdh0KG7JTEzGTnzo5K/p7PYx?= =?us-ascii?Q?WIMF2MDBHAKCSBR65N5/HbIHVM/QEJv8FLftbYxcfMkkXJ6ybtgp2b5Mmo0Y?= =?us-ascii?Q?BNYAC+9pnv13jeNxwPze6W+I2fEj+PtijMotEhSyXOWBPFTo1QzcRvT5bopZ?= =?us-ascii?Q?AKxfUgZacY0DtcyD+XAgeRDN+0Uq8OGrRRg8vjAp0FuSZ72Vg/c1BR+HxVCG?= =?us-ascii?Q?UsNK4Y/sXJtZ+xdugPPv8Qlnk+flaPNdx6ILIWzl+5FdnUzoyKjCwP2xLHkU?= =?us-ascii?Q?Q9hVbWPneAVgc0kIu3uQWQYj8lSCmRkJ369/xldsBCbbY+lzBNgdVB7XUlkd?= =?us-ascii?Q?tTNa/2r3K/i1XGT3A8Vka7Hj4XCsrq6DJbzWEr5iViXj/Wd7RPdaXofQ3X2L?= =?us-ascii?Q?Bezjdn2BojiO12m4RdDXRS67aUS45CZHLgqSHazA7OR4RzUtYXeaYeA67zSM?= =?us-ascii?Q?rYk7vsocqvxhSmPREcAGhL8cJz8s7dRjwbYGLYGQG5DTqRXI5EuIkL+ECY76?= =?us-ascii?Q?okeiirL44GrfGNSNZIZoxQ68HPdiIkU+RYm2qNBRRDk9?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB7031.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7dfcaa59-1eb2-40b2-93dd-08db4bb7a1d9 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 May 2023 09:20:26.9288 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: sUQA0LRevrL3hvAtX8nyzj51fI6w0gjySyahxqVM43NGwUIfnOULUFum5QAosAE400Krp0BPXA8c4a93LUPk1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6251 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Nickle Wang Regards, Nickle > -----Original Message----- > From: abner.chang@amd.com > Sent: Wednesday, May 3, 2023 4:17 PM > To: devel@edk2.groups.io > Cc: Nickle Wang ; Igor Kulchytskyy > Subject: [edk2-redfish-client][PATCH] RedfishClientPkg/ConvertLib: Common > code and header files > > External email: Use caution opening links or attachments > > > From: Abner Chang > > ConverterLib/* is the folder of script-generated JSON > to C library for the each Redfish schema. The common > code and header files in this patch are used by those > libraries. > > Signed-off-by: Abner Chang > Cc: Nickle Wang > Cc: Igor Kulchytskyy > --- > .../ConverterLib/include/RedfishCsCommon.h | 203 +++ > .../ConverterLib/include/RedfishDataTypeDef.h | 47 + > .../src/RedfishCsMemoryInternal.h | 83 + > .../ConverterLib/src/RedfishCsCommon.c | 1465 +++++++++++++++++ > .../ConverterLib/src/RedfishCsMemory.c | 238 +++ > 5 files changed, 2036 insertions(+) > create mode 100644 > RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h > create mode 100644 > RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h > create mode 100644 > RedfishClientPkg/ConverterLib/src/RedfishCsMemoryInternal.h > create mode 100644 RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c > create mode 100644 RedfishClientPkg/ConverterLib/src/RedfishCsMemory.c > > diff --git a/RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h > b/RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h > new file mode 100644 > index 0000000000..5cdec02ffd > --- /dev/null > +++ b/RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h > @@ -0,0 +1,203 @@ > +/** @file > + > + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + Copyright Notice: > + Copyright 2019-2021 Distributed Management Task Force, Inc. All rights > reserved. > + License: BSD 3-Clause License. For full text see link: > https://github.c/ > om%2FDMTF%2FRedfish-JSON-C-Struct- > Converter%2Fblob%2Fmaster%2FLICENSE.md&data=3D05%7C01%7Cnicklew%40n > vidia.com%7C6c287e287fb44d40c3e308db4baed8a2%7C43083d15727340c1b7d > b39efd9ccc17a%7C0%7C0%7C638186986569209689%7CUnknown%7CTWFpbG > Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn > 0%3D%7C3000%7C%7C%7C&sdata=3DVKor2rANpdKrvHJ7pEDkfh2XrTqQdtRVZjryv > urM1ms%3D&reserved=3D0 > +**/ > + > +#ifndef REDFISH_CS_COMMON_H_ > +#define REDFISH_CS_COMMON_H_ > + > +#include "RedfishDataTypeDef.h" > + > +RedfishCS_Link * > +InitializeLinkHead ( > + RedfishCS_Link *LinkHead > + ); > + > +RedfishCS_Link * > +InsertHeadLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ); > + > +RedfishCS_Link * > +InsertTailLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ); > + > +RedfishCS_Link * > +GetFirstLink ( > + const RedfishCS_Link *List > + ); > + > +RedfishCS_Link * > +GetLastLink ( > + const RedfishCS_Link *List > + ); > + > +RedfishCS_Link * > +GetNextLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ); > + > +RedfishCS_Link * > +GetPreviousLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ); > + > +RedfishCS_Link * > +RemoveLink ( > + const RedfishCS_Link *Link > + ); > + > +RedfishCS_bool > +IsLinkEmpty ( > + const RedfishCS_Link *LinkHead > + ); > + > +RedfishCS_bool > +IsLinkAtEnd ( > + const RedfishCS_Link *LinkHead, > + const RedfishCS_Link *ThisLink > + ); > + > +RedfishCS_status > +recordCsRootMemory ( > + void *memCs > + ); > + > +RedfishCS_status > +allocateRecordCsMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 size, > + RedfishCS_void **Dst > + ); > + > +RedfishCS_status > +allocateRecordCsZeroMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 size, > + RedfishCS_void **Dst > + ); > + > +RedfishCS_status > +allocateArrayRecordCsMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 ArrayInstanceSize, > + RedfishCS_uint64 ArraySize, > + RedfishCS_void **Dst > + ); > + > +RedfishCS_status > +allocateDuplicateStr ( > + void *Cs, > + char *Str, > + void **DstBuffer > + ); > + > +RedfishCS_status > +DestoryCsMemory ( > + RedfishCS_void *rootCs > + ); > + > +typedef struct _RedfishCS_char_Array RedfishCS_char_Array; > +typedef struct _RedfishCS_int64_Array RedfishCS_int64_Array; > +typedef struct _RedfishCS_bool_Array RedfishCS_bool_Array; > +typedef struct _RedfishCS_Link_Array RedfishCS_Link_Array; > +typedef struct _RedfishCS_EmptyProp_KeyValue > RedfishCS_EmptyProp_KeyValue; > + > +typedef enum { > + RedfishCS_Type_CS =3D 1, > + RedfishCS_Type_CS_EmptyProp, > + RedfishCS_Type_JSON, > + RedfishCS_Type_Uri > +} RedfishCS_Type; > + > +typedef struct _RedfishCS_Header { > + RedfishCS_Link LinkEntry; > + RedfishCS_Type ResourceType; > + RedfishCS_char *KeyName; > + RedfishCS_char *ThisUri; > +} RedfishCS_Header; > + > +typedef struct _RedfishCS_Type_Uri_Data { > + RedfishCS_Header Header; > + RedfishCS_char *Uri; > +} RedfishCS_Type_Uri_Data; > + > +typedef struct _RedfishCS_Type_CS_Data { > + RedfishCS_Header Header; > + // > + // Followed by C structure of resource. > + // > +} RedfishCS_Type_CS_Data; > + > +typedef struct _RedfishCS_Type_JSON_Data { > + RedfishCS_Header Header; > + RedfishCS_char *JsonText; > +} RedfishCS_Type_JSON_Data; > + > +typedef struct _RedfishCS_Number { > + RedfishCS_uint16 Value; > + RedfishCS_uint16 MaxValue; > + RedfishCS_uint16 MinValue; > +} RedfishCS_Number; > + > +typedef struct _RedfishCS_char_Array { > + RedfishCS_char_Array *Next; > + RedfishCS_char *ArrayValue; > +} RedfishCS_char_Array; > + > +typedef struct _RedfishCS_int64_Array { > + RedfishCS_int64_Array *Next; > + RedfishCS_int64 *ArrayValue; > +} RedfishCS_int64_Array; > + > +typedef struct _RedfishCS_bool_Array { > + RedfishCS_bool_Array *Next; > + RedfishCS_bool *ArrayValue; > +} RedfishCS_bool_Array; > + > +typedef struct _RedfishCS_Link_Array { > + RedfishCS_Link_Array *Next; > + RedfishCS_Link *ArrayValue; > +} RedfishCS_Link_Array; > + > +typedef enum { > + RedfishCS_Vague_DataType_String =3D 1, > + RedfishCS_Vague_DataType_Int64, > + RedfishCS_Vague_DataType_Bool > +} RedfishCS_Vague_DataType; > + > +typedef union { > + RedfishCS_char *CharPtr; > + RedfishCS_bool *BoolPtr; > + RedfishCS_int64 *Int64Ptr; > +} RedfishCS_Vague_Ptr; > + > +typedef struct _RedfishCS_Vague { > + RedfishCS_Vague_DataType DataType; > + RedfishCS_Vague_Ptr DataValue; > +} RedfishCS_Vague; > + > +typedef struct _RedfishCS_EmptyProp_KeyValue { > + RedfishCS_EmptyProp_KeyValue *NextKeyValuePtr; > + RedfishCS_char *KeyNamePtr; > + RedfishCS_Vague *Value; > +} RedfishCS_EmptyProp_KeyValue; > + > +typedef struct _RedfishCS_Type_EmptyProp_CS_Data { > + RedfishCS_Header Header; > + RedfishCS_uint32 NunmOfProperties; > + RedfishCS_EmptyProp_KeyValue *KeyValuePtr; > +} RedfishCS_Type_EmptyProp_CS_Data; > + > +#endif > diff --git a/RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h > b/RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h > new file mode 100644 > index 0000000000..96eebc66e7 > --- /dev/null > +++ b/RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h > @@ -0,0 +1,47 @@ > +/** @file > + > + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + Copyright Notice: > + Copyright 2019-2021 Distributed Management Task Force, Inc. All rights > reserved. > + License: BSD 3-Clause License. For full text see link: > https://github.c/ > om%2FDMTF%2FRedfish-JSON-C-Struct- > Converter%2Fblob%2Fmaster%2FLICENSE.md&data=3D05%7C01%7Cnicklew%40n > vidia.com%7C6c287e287fb44d40c3e308db4baed8a2%7C43083d15727340c1b7d > b39efd9ccc17a%7C0%7C0%7C638186986569209689%7CUnknown%7CTWFpbG > Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn > 0%3D%7C3000%7C%7C%7C&sdata=3DVKor2rANpdKrvHJ7pEDkfh2XrTqQdtRVZjryv > urM1ms%3D&reserved=3D0 > +**/ > + > +#ifndef REDFISH_CS_DATA_TYPE_H_ > +#define REDFISH_CS_DATA_TYPE_H_ > + > +#include > + > +typedef char RedfishCS_char; > +typedef int RedfishCS_bool; > +typedef signed char RedfishCS_int8; > +typedef unsigned char RedfishCS_uint8; > +typedef int RedfishCS_int16; > +typedef int RedfishCS_int; > +typedef unsigned int RedfishCS_uint16; > +typedef long int RedfishCS_int32; > +typedef unsigned long int RedfishCS_uint32; > +typedef long long RedfishCS_int64; > +typedef unsigned long long RedfishCS_uint64; > +typedef void RedfishCS_void; > + > +#define RedfishCS_boolean_false 0 > +#define RedfishCS_boolean_true 1 > + > +typedef RedfishCS_int64 RedfishCS_status; > +#define RedfishCS_status_success 0 > +#define RedfishCS_status_unsupported -1 > +#define RedfishCS_status_invalid_parameter -2 > +#define RedfishCS_status_insufficient_memory -3 > +#define RedfishCS_status_not_found -4 > +#define RedfishCS_status_unknown_error -5 > + > +typedef struct _RedfishCS_Link RedfishCS_Link; > +struct _RedfishCS_Link { > + RedfishCS_Link *BackLink; > + RedfishCS_Link *ForwardLink; > +}; > + > +#endif > diff --git a/RedfishClientPkg/ConverterLib/src/RedfishCsMemoryInternal.h > b/RedfishClientPkg/ConverterLib/src/RedfishCsMemoryInternal.h > new file mode 100644 > index 0000000000..acf2b15a16 > --- /dev/null > +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsMemoryInternal.h > @@ -0,0 +1,83 @@ > +/** @file > + > + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + Copyright Notice: > + Copyright 2019-2021 Distributed Management Task Force, Inc. All rights > reserved. > + License: BSD 3-Clause License. For full text see link: > https://github.c/ > om%2FDMTF%2FRedfish-JSON-C-Struct- > Converter%2Fblob%2Fmaster%2FLICENSE.md&data=3D05%7C01%7Cnicklew%40n > vidia.com%7C6c287e287fb44d40c3e308db4baed8a2%7C43083d15727340c1b7d > b39efd9ccc17a%7C0%7C0%7C638186986569209689%7CUnknown%7CTWFpbG > Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn > 0%3D%7C3000%7C%7C%7C&sdata=3DVKor2rANpdKrvHJ7pEDkfh2XrTqQdtRVZjryv > urM1ms%3D&reserved=3D0 > +**/ > + > +#ifndef REDFISH_CS_MEMORY_INTERNAL_H_ > +#define REDFISH_CS_MEMORY_INTERNAL_H_ > + > +#include "RedfishDataTypeDef.h" > + > +RedfishCS_Link * > +InitializeLinkHead ( > + RedfishCS_Link *LinkHead > + ); > + > +RedfishCS_Link * > +InsertHeadLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ); > + > +RedfishCS_Link * > +InsertTailLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ); > + > +RedfishCS_Link * > +GetFirstLink ( > + const RedfishCS_Link *List > + ); > + > +RedfishCS_Link * > +GetLastLink ( > + const RedfishCS_Link *List > + ); > + > +RedfishCS_Link * > +GetNextLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ); > + > +RedfishCS_Link * > +GetPreviousLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ); > + > +RedfishCS_Link * > +RemoveLink ( > + const RedfishCS_Link *Link > + ); > + > +RedfishCS_bool > +IsLinkEmpty ( > + const RedfishCS_Link *LinkHead > + ); > + > +RedfishCS_bool > +IsLinkAtEnd ( > + const RedfishCS_Link *LinkHead, > + const RedfishCS_Link *ThisLink > + ); > + > +typedef struct _RedfishCS_Internal_memory_link { > + RedfishCS_Link nextLink; > + void *memoryPtr; > +} RedfishCS_Internal_memory_link; > + > +typedef struct _RedfishCS_Internal_memory_root { > + RedfishCS_Link nextRoot; > + RedfishCS_Link memBlocks; > + void *CsPtr; > +} RedfishCS_Internal_memory_root; > + > +#endif > diff --git a/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c > b/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c > new file mode 100644 > index 0000000000..212f0de1a8 > --- /dev/null > +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c > @@ -0,0 +1,1465 @@ > +/** @file > + > + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + Copyright Notice: > + Copyright 2019-2021 Distributed Management Task Force, Inc. All rights > reserved. > + License: BSD 3-Clause License. For full text see link: > https://github.c/ > om%2FDMTF%2FRedfish-JSON-C-Struct- > Converter%2Fblob%2Fmaster%2FLICENSE.md&data=3D05%7C01%7Cnicklew%40n > vidia.com%7C6c287e287fb44d40c3e308db4baed8a2%7C43083d15727340c1b7d > b39efd9ccc17a%7C0%7C0%7C638186986569209689%7CUnknown%7CTWFpbG > Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn > 0%3D%7C3000%7C%7C%7C&sdata=3DVKor2rANpdKrvHJ7pEDkfh2XrTqQdtRVZjryv > urM1ms%3D&reserved=3D0 > +**/ > + > +#include "RedfishCsCommon.h" > +#include "RedfishCsMemoryInternal.h" > +#include > +#include > +#include > + > +RedfishCS_status > +GetRedfishPropertyVague ( > + void *Cs, > + json_t *JsonObj, > + char *Key, > + RedfishCS_Vague **DstBuffer > + ); > + > +/** > + This function initiates a Redfish C Structure link. > + > + ListHead The link list entry. > + Return the list head. > + > +**/ > +RedfishCS_Link * > +InitializeLinkHead ( > + RedfishCS_Link *ListHead > + ) > +{ > + ListHead->ForwardLink =3D ListHead; > + ListHead->BackLink =3D ListHead; > + return ListHead; > +} > + > +/** > + This function inserts the list to list head. > + > + ListHead The link list head. > + Entry The list to insert. > + > + Return the list head. > + > +**/ > +RedfishCS_Link * > +InsertHeadLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ) > +{ > + Entry->ForwardLink =3D ListHead->ForwardLink; > + Entry->BackLink =3D ListHead; > + Entry->ForwardLink->BackLink =3D Entry; > + ListHead->ForwardLink =3D Entry; > + return ListHead; > +} > + > +/** > + This function inserts the list to list tail. > + > + ListHead The link list head. > + Entry The list to insert. > + > + Return the list head. > + > +**/ > +RedfishCS_Link * > +InsertTailLink ( > + RedfishCS_Link *ListHead, > + RedfishCS_Link *Entry > + ) > +{ > + Entry->ForwardLink =3D ListHead; > + Entry->BackLink =3D ListHead->BackLink; > + Entry->BackLink->ForwardLink =3D Entry; > + ListHead->BackLink =3D Entry; > + return ListHead; > +} > + > +/** > + This function gets the first list from the list head. > + > + List The link list head. > + > + Return the first list * > + > +**/ > +RedfishCS_Link * > +GetFirstLink ( > + const RedfishCS_Link *List > + ) > +{ > + return List->ForwardLink; > +} > + > +/** > + This function gets the last list from the list head. > + > + List The link list head. > + > + Return the last list. > + > +**/ > +RedfishCS_Link * > +GetLastLink ( > + const RedfishCS_Link *List > + ) > +{ > + return List->BackLink; > +} > + > +/** > + This function gets the next list of Node. > + > + List The link list head. > + Node The list we will get the next list from. > + > + Return the next list. > + > +**/ > +RedfishCS_Link * > +GetNextLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ) > +{ > + return Node->ForwardLink; > +} > + > +/** > + This function gets the previous list of Node. > + > + List The link list head. > + Node The list we will get the previous list from. > + > + Return the previous RedfishCS_Link * > + > +**/ > +RedfishCS_Link * > +GetPreviousLink ( > + const RedfishCS_Link *List, > + const RedfishCS_Link *Node > + ) > +{ > + return Node->BackLink; > +} > + > +/** > + This function removes a list. > + > + Link The list to be removed. > + > + Return the next list. > + > +**/ > +RedfishCS_Link * > +RemoveLink ( > + const RedfishCS_Link *Link > + ) > +{ > + Link->ForwardLink->BackLink =3D Link->BackLink; > + Link->BackLink->ForwardLink =3D Link->ForwardLink; > + return Link->ForwardLink; > +} > + > +/** > + This function checks if the list is empty. > + > + LinkHead The list head. > + > + Return true if it is empty otherwise it is not empty. > + > +**/ > +RedfishCS_bool > +IsLinkEmpty ( > + const RedfishCS_Link *LinkHead > + ) > +{ > + return (RedfishCS_bool)(LinkHead->ForwardLink =3D=3D LinkHead); > +} > + > +/** > + This function checks if the list is at the end. > + > + LinkHead The list head. > + ThisLink The list to check. > + > + Return true if it is at the end otherwise it is not. > + > +**/ > +RedfishCS_bool > +IsLinkAtEnd ( > + const RedfishCS_Link *LinkHead, > + const RedfishCS_Link *ThisLink > + ) > +{ > + return (RedfishCS_bool)(ThisLink->ForwardLink =3D=3D LinkHead); > +} > + > +/** > + This function duplicates a string. > + > + Cs The CStructure instance that owns the string. > + Str String to be duplicated. > + DstBuffer The buffer to retrieve the string. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +allocateDuplicateStr ( > + void *Cs, > + char *Str, > + void **DstBuffer > + ) > +{ > + RedfishCS_status Status; > + > + if ((Str =3D=3D NULL) || (strlen (Str) =3D=3D 0)) { > + *DstBuffer =3D NULL; > + return RedfishCS_status_success; > + } > + > + Status =3D allocateRecordCsMemory (Cs, (RedfishCS_int)strlen (Str) + 1= , (void > **)DstBuffer); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + memcpy (*DstBuffer, Str, strlen (Str) + 1); > + return RedfishCS_status_success; > +} > + > +/** > + This function creates an URI type CS by the Odata ID. > + > + JsonOj JSON object which has odata ID key. > + ParentUri The parent URI of odata ID. > + CsTypeUriData The pointer to retrieve the RedfishCS_Type_Uri_Data. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateCsUriByOdataId ( > + json_t *JsonOj, > + RedfishCS_char *ParentUri, > + RedfishCS_Type_Uri_Data **CsTypeUriData > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_Type_Uri_Data *CsTypeUri; > + > + CsTypeUri =3D NULL; > + TempJsonObj =3D json_object_get (JsonOj, "@odata.id"); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + CsTypeUri =3D malloc (sizeof (RedfishCS_Type_Uri_Data)); > + if (CsTypeUri =3D=3D NULL) { > + return RedfishCS_status_insufficient_memory; > + } > + > + InitializeLinkHead (&CsTypeUri->Header.LinkEntry); > + CsTypeUri->Header.ResourceType =3D RedfishCS_Type_Uri; > + CsTypeUri->Header.ThisUri =3D ParentUri; > + CsTypeUri->Header.KeyName =3D (RedfishCS_char *)strdup ("@odata.i= d"); > + CsTypeUri->Uri =3D (RedfishCS_char *)strdup (json_stri= ng_value > (TempJsonObj)); > + *CsTypeUriData =3D CsTypeUri; > + return RedfishCS_status_success; > +} > + > +/** > + This function creates URI type CS by node. > + > + Cs The CStructure instance owns the string. > + JsonOj JSON object which has NodeName key. > + NodeName The JSON key name. > + ParentUri The parent URI of odata ID. > + CsTypeUriData The pointer to retrieve the RedfishCS_Type_Uri_Data. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateCsUriByNode ( > + void *Cs, > + json_t *JsonOj, > + RedfishCS_char *NodeName, > + RedfishCS_char *ParentUri, > + RedfishCS_Type_Uri_Data **CsTypeUriData > + ) > +{ > + json_t *TempJsonObj; > + json_t *TempJsonObj2; > + RedfishCS_Type_Uri_Data *CsTypeUri; > + RedfishCS_status Status; > + > + CsTypeUri =3D NULL; > + > + if (NodeName !=3D NULL) { > + TempJsonObj =3D json_object_get (JsonOj, NodeName); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + } else { > + if (JsonOj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + TempJsonObj =3D JsonOj; > + } > + > + TempJsonObj2 =3D json_object_get (TempJsonObj, "@odata.id"); > + if (TempJsonObj2 !=3D NULL) { > + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_Type_Uri_Da= ta), > (void **)&CsTypeUri); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + InitializeLinkHead (&CsTypeUri->Header.LinkEntry); > + CsTypeUri->Header.ResourceType =3D RedfishCS_Type_Uri; > + CsTypeUri->Header.ThisUri =3D ParentUri; > + Status =3D allocateDuplicateStr (Cs, NodeNam= e, (void > **)&CsTypeUri->Header.KeyName); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + *CsTypeUriData =3D CsTypeUri; > + Status =3D allocateDuplicateStr (Cs, (char *)json_string_val= ue > (TempJsonObj2), (void **)&CsTypeUri->Uri); > + return Status; > + } > + > + return RedfishCS_status_invalid_parameter; > +} > + > +/** > + This function creates JSON type CS by node. > + > + Cs The CStructure instance owns the string. > + JsonOj JSON object which has NodeName key. > + NodeName The JSON key name. > + ParentUri The parent URI of odata ID. > + CsTypeJsonData The pointer to retrieve the RedfishCS_Type_JSON_Data. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateCsJsonByNode ( > + void *Cs, > + json_t *JsonObj, > + RedfishCS_char *NodeName, > + RedfishCS_char *ParentUri, > + RedfishCS_Type_JSON_Data **CsTypeJsonData > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_Type_JSON_Data *CsTypeJson; > + RedfishCS_char *TempChar; > + RedfishCS_char *DumpStr; > + RedfishCS_status Status; > + > + CsTypeJson =3D NULL; > + if (NodeName !=3D NULL) { > + TempJsonObj =3D json_object_get (JsonObj, NodeName); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + } else { > + // Dump JSON from JsonObj. > + TempJsonObj =3D JsonObj; > + } > + > + TempChar =3D json_dumps ((json_t *)TempJsonObj, JSON_INDENT (2)); > + if (TempChar !=3D NULL) { > + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_Type_JSON_D= ata), > (void **)&CsTypeJson); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + Status =3D allocateRecordCsMemory (Cs, (RedfishCS_int)strlen (TempCh= ar) + 1, > (void **)&DumpStr); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + strncpy (DumpStr, TempChar, strlen (TempChar) + 1); > + InitializeLinkHead (&CsTypeJson->Header.LinkEntry); > + CsTypeJson->Header.ResourceType =3D RedfishCS_Type_JSON; > + CsTypeJson->Header.ThisUri =3D ParentUri; > + Status =3D allocateDuplicateStr (Cs, NodeNa= me, (void > **)&CsTypeJson->Header.KeyName); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + CsTypeJson->JsonText =3D DumpStr; > + *CsTypeJsonData =3D CsTypeJson; > + return RedfishCS_status_success; > + } > + > + return RedfishCS_status_invalid_parameter; > +} > + > +/** > + This function creates an empty property type CS by node. > + > + Cs The CStructure instance owns the string. > + JsonOj JSON object which has the NodeName. > + NodeName The JSON key name. > + ParentUri The parent URI of odata ID. > + CsTypeEmptyPropCSData The pointer to retrieve the CsTypeEmptyPropCSDat= a. > + NunmOfProperties Number of properties in CS. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateEmptyPropCsJson ( > + RedfishCS_void *Cs, > + json_t *JsonObj, > + RedfishCS_char *NodeName, > + RedfishCS_char *ParentUri, > + RedfishCS_Type_EmptyProp_CS_Data **CsTypeEmptyPropCSData, > + RedfishCS_uint32 NunmOfProperties > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_status Status; > + RedfishCS_Type_EmptyProp_CS_Data *CsTypeEmptyPropCS; > + RedfishCS_char *KeyName; > + json_t *KeyValueObj; > + RedfishCS_void *n; > + RedfishCS_EmptyProp_KeyValue **KeyValuePtr; > + RedfishCS_EmptyProp_KeyValue *KeyValue; > + > + CsTypeEmptyPropCS =3D NULL; > + if (NodeName !=3D NULL) { > + TempJsonObj =3D json_object_get (JsonObj, NodeName); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + } > + > + Status =3D allocateRecordCsMemory (Cs, sizeof > (RedfishCS_Type_EmptyProp_CS_Data), (void **)&CsTypeEmptyPropCS); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + InitializeLinkHead (&CsTypeEmptyPropCS->Header.LinkEntry); > + CsTypeEmptyPropCS->Header.ResourceType =3D > RedfishCS_Type_CS_EmptyProp; > + CsTypeEmptyPropCS->Header.ThisUri =3D ParentUri; > + Status =3D allocateDuplicateStr (Cs, N= odeName, (void > **)&CsTypeEmptyPropCS->Header.KeyName); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + CsTypeEmptyPropCS->NunmOfProperties =3D NunmOfProperties; > + // > + // Create instance for each key-value. > + // > + KeyValuePtr =3D &CsTypeEmptyPropCS->KeyValuePtr; > + json_object_foreach_safe (TempJsonObj, n, KeyName, KeyValueObj) { > + Status =3D allocateRecordCsMemory (Cs, sizeof > (RedfishCS_EmptyProp_KeyValue), (void **)&KeyValue); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + Status =3D allocateDuplicateStr (Cs, (char *)KeyName, (void **)&KeyV= alue- > >KeyNamePtr); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + Status =3D GetRedfishPropertyVague (Cs, TempJsonObj, (char *)KeyName= , > &KeyValue->Value); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + *KeyValuePtr =3D KeyValue; > + KeyValuePtr =3D &KeyValue->NextKeyValuePtr; > + } > + > + *CsTypeEmptyPropCSData =3D CsTypeEmptyPropCS; > + return RedfishCS_status_success; > +} > + > +/** > + This function checks if property type is supported. > + > + JsonOj JSON object of this property. > + > + Return RedfishCS_bool. > + > +**/ > +RedfishCS_bool > +CheckSupportedPropTypeInEmptyProperty ( > + json_t *JsonObj > + ) > +{ > + // > + // Only support below property types for the property is declared as > + // empty property in schema. > + // e.g. "properties": {} > + // > + if (json_is_string (JsonObj) || > + json_is_integer (JsonObj) || > + // json_is_real(JsonObj) || > + json_is_number (JsonObj) || > + json_is_boolean (JsonObj)) > + { > + return RedfishCS_boolean_true; > + } > + > + return RedfishCS_boolean_false; > +} > + > +/** > + This function checks the properties in a empty property type JSON obje= ct. > + Also returns the number of properties in NumOfProperty. > + > + JsonOj JSON object > + NumOfProperty Pointer to retrieve the number of property in JSON obje= ct. > + > + Return RedfishCS_bool. > + > +**/ > +RedfishCS_bool > +CheckEmptyPropJsonObject ( > + json_t *JsonObj, > + RedfishCS_uint32 *NumOfProperty > + ) > +{ > + RedfishCS_char *NewKey; > + json_t *Value; > + RedfishCS_void *n; > + RedfishCS_uint32 Num; > + > + Num =3D 0; > + json_object_foreach_safe (JsonObj, n, NewKey, Value) { > + if (!CheckSupportedPropTypeInEmptyProperty (Value)) { > + return RedfishCS_boolean_false; > + } > + > + Num++; > + } > + if (NumOfProperty !=3D NULL) { > + *NumOfProperty =3D Num; > + } > + > + return RedfishCS_boolean_true; > +} > + > +/** > + This function checks if this is a supported Redfish resource. > + > + Odata_Type The string to Odata type. > + NameSpace The string to the Redfish schema name space. > + Version The string to the Redfish schema version. > + DataType The string to the data type defined in Redfish schema. > + > + Return RedfishCS_bool. > + > +**/ > +RedfishCS_bool > +SupportedRedfishResource ( > + RedfishCS_char *Odata_Type, > + RedfishCS_char *NameSpace, > + RedfishCS_char *Version, > + RedfishCS_char *DataType > + ) > +{ > + RedfishCS_char *TargetDataType; > + > + if ((Odata_Type =3D=3D NULL) || (NameSpace =3D=3D NULL) || (DataType = =3D=3D NULL)) { > + return RedfishCS_boolean_false; > + } > + > + if (Version !=3D NULL) { > + TargetDataType =3D malloc (strlen (NameSpace) + strlen (Version) + s= trlen > (DataType) + 16); // Plus 16 bytes to make more room. > + = // Actually we just need 1 > byte for "#" > + = // Two bytes for "." and > one byte for NULL terminator. > + } else { > + TargetDataType =3D malloc (strlen (NameSpace) + strlen (DataType) + = 16); // > Plus 16 bytes to make more room. > + = // Actually we just need 1 byte for "#" > + = // Two bytes for "." and one byte for > NULL terminator. > + } > + > + if (TargetDataType =3D=3D NULL) { > + return RedfishCS_boolean_false; > + } > + > + TargetDataType[0] =3D 0; // Insert NULL terminator. > + strcat (TargetDataType, "#"); > + strcat (TargetDataType, NameSpace); > + strcat (TargetDataType, "."); > + if ((Version !=3D NULL) && (strcmp (Version, "noversioned") !=3D 0)) { > + strcat (TargetDataType, Version); > + strcat (TargetDataType, "."); > + } > + > + strcat (TargetDataType, DataType); > + if (strcmp (Odata_Type, TargetDataType) =3D=3D 0) { > + return RedfishCS_boolean_true; > + } > + > + free (TargetDataType); > + return RedfishCS_boolean_false; > +} > + > +/** > + This function creates JSON or URI type CS according to the > + number of properties in JSON object. > + > + Cs he CStructure instance owns the new created CS. > + JsonObj JSON object which has NodeName key. > + NodeName The key name in JSON object. > + ParentUri The parent URI. > + LinkHead The list head to link with the new CS. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateCsUriOrJsonByNode ( > + void *Cs, > + json_t *JsonObj, > + RedfishCS_char *NodeName, > + RedfishCS_char *ParentUri, > + RedfishCS_Link *LinkHead > + ) > +{ > + json_t *JsonObjTemp; > + RedfishCS_Type_Uri_Data *CsTypeUri; > + RedfishCS_Type_JSON_Data *CsTypeJson; > + RedfishCS_status Status; > + > + Status =3D RedfishCS_status_invalid_parameter; > + JsonObjTemp =3D json_object_get (JsonObj, NodeName); > + if (JsonObjTemp =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + if (json_object_size (JsonObjTemp) =3D=3D 1) { > + Status =3D CreateCsUriByNode (Cs, JsonObj, NodeName, ParentUri, > &CsTypeUri); > + if (Status =3D=3D RedfishCS_status_success) { > + InsertTailLink (LinkHead, &CsTypeUri->Header.LinkEntry); > + return RedfishCS_status_success; > + } > + } else { > + Status =3D CreateCsJsonByNode (Cs, JsonObj, NodeName, ParentUri, > &CsTypeJson); > + if (Status =3D=3D RedfishCS_status_success) { > + InsertTailLink (LinkHead, &CsTypeJson->Header.LinkEntry); > + return RedfishCS_status_success; > + } > + } > + > + return Status; > +} > + > +/** > + This function creates JSON or URI array type CS according to the > + number of properties in JSON object. > + > + Cs he CStructure instance owns the new created CS. > + JsonObj JSON object which has NodeName. > + NodeName The key name in JSON object. > + ParentUri The parent URI. > + LinkHead The list head to link with the new CS. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateCsUriOrJsonByNodeArray ( > + void *Cs, > + json_t *JsonObj, > + RedfishCS_char *NodeName, > + RedfishCS_char *ParentUri, > + RedfishCS_Link *LinkHead > + ) > +{ > + json_t *JsonObjTemp; > + json_t *JsonObjArray; > + RedfishCS_Type_Uri_Data *CsTypeUri; > + RedfishCS_Type_JSON_Data *CsTypeJson; > + RedfishCS_status Status; > + RedfishCS_uint16 ArrayIndex; > + > + Status =3D RedfishCS_status_invalid_parameter; > + JsonObjTemp =3D json_object_get (JsonObj, NodeName); > + if (JsonObjTemp =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + if (json_array_size (JsonObjTemp) =3D=3D 0) { > + return RedfishCS_status_success; > + } > + > + for (ArrayIndex =3D 0; ArrayIndex < (RedfishCS_uint16)json_array_size > (JsonObjTemp); ArrayIndex++) { > + JsonObjArray =3D json_array_get (JsonObjTemp, (size_t)ArrayIndex); > + if (JsonObjArray =3D=3D NULL) { > + continue; > + } > + > + if (json_object_size (JsonObjArray) =3D=3D 1) { > + Status =3D CreateCsUriByNode (Cs, JsonObjArray, NULL, ParentUri, > &CsTypeUri); > + if (Status =3D=3D RedfishCS_status_success) { > + InsertTailLink (LinkHead, &CsTypeUri->Header.LinkEntry); > + } > + } else { > + Status =3D CreateCsJsonByNode (Cs, JsonObjArray, NULL, ParentUri, > &CsTypeJson); > + if (Status =3D=3D RedfishCS_status_success) { > + InsertTailLink (LinkHead, &CsTypeJson->Header.LinkEntry); > + } > + } > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function creates JSON object and CS. > + > + JsonRawText JSON raw text. > + ResourceType The Redfish resource type. > + ResourceVersion The Redfish resource version. > + TypeName The Redfish type name. > + JsonObjReturned Pointer to retrieve JSON object. > + Cs Pointer to retrieve CS. > + size The size of CS. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CreateJsonPayloadAndCs ( > + char *JsonRawText, > + char *ResourceType, > + char *ResourceVersion, > + char *TypeName, > + json_t **JsonObjReturned, > + void **Cs, > + int size > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_char *TempChar; > + RedfishCS_Header *Header; > + void *TempCS; > + > + if ((JsonRawText =3D=3D NULL) || > + (ResourceType =3D=3D NULL) || > + (TypeName =3D=3D NULL) || > + (Cs =3D=3D NULL) || > + (size =3D=3D 0) > + ) > + { > + return RedfishCS_status_invalid_parameter; > + } > + > + *JsonObjReturned =3D json_loads (JsonRawText, 0, NULL); > + if (*JsonObjReturned =3D=3D NULL) { > + return RedfishCS_status_unknown_error; > + } > + > + TempJsonObj =3D json_object_get (*JsonObjReturned, "@odata.type"); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + TempChar =3D (RedfishCS_char *)json_string_value (TempJsonObj); > + if ((TempChar =3D=3D NULL) || !SupportedRedfishResource (TempChar, > ResourceType, ResourceVersion, TypeName)) { > + return RedfishCS_status_unsupported; > + } > + > + TempCS =3D malloc (size); > + if (TempCS =3D=3D NULL) { > + return RedfishCS_status_insufficient_memory; > + } > + > + memset (TempCS, 0, size); > + Header =3D (RedfishCS_Header *)TempCS; > + Header->ResourceType =3D RedfishCS_Type_CS; > + Header->KeyName =3D NULL; > + InitializeLinkHead (&Header->LinkEntry); > + *Cs =3D TempCS; > + return recordCsRootMemory (TempCS); > +} > + > +/** > + This function returns a Redfish string property. > + > + Cs The owner of this property. > + JsonObj The JSON object has the Key. > + Key The key in JSON object. > + DstBuffer Pointer to retrieve a string. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +GetRedfishPropertyStr ( > + void *Cs, > + json_t *JsonObj, > + char *Key, > + RedfishCS_char **DstBuffer > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_status Status; > + > + if (DstBuffer =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + *DstBuffer =3D NULL; > + > + TempJsonObj =3D json_object_get (JsonObj, Key); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + Status =3D allocateDuplicateStr (Cs, (char *)json_string_value (TempJs= onObj), > (void **)DstBuffer); > + return Status; > +} > + > +/** > + This function returns a Redfish bool property. > + > + Cs The owner of this property. > + JsonObj The JSON object has the Key. > + Key The key in JSON object. > + DstBuffer Pointer to retrieve a boolean. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +GetRedfishPropertyBoolean ( > + void *Cs, > + json_t *JsonObj, > + char *Key, > + RedfishCS_bool **DstBuffer > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_status Status; > + > + if (DstBuffer =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + TempJsonObj =3D json_object_get (JsonObj, Key); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_bool), (void > **)DstBuffer); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + if (json_is_true (TempJsonObj)) { > + **DstBuffer =3D RedfishCS_boolean_true; > + } else { > + **DstBuffer =3D RedfishCS_boolean_false; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function returns Redfish a long long property. > + > + Cs The owner of this property. > + JsonObj The JSON object has the Key. > + Key The key in JSON object. > + DstBuffer Pointer to retrieve a long long value. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +GetRedfishPropertyInt64 ( > + void *Cs, > + json_t *JsonObj, > + char *Key, > + RedfishCS_int64 **Dst > + ) > +{ > + RedfishCS_status Status; > + json_t *TempJsonObj; > + > + if (Dst =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + TempJsonObj =3D json_object_get (JsonObj, Key); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_int64), (void= **)Dst); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + **Dst =3D (RedfishCS_int64)json_integer_value (TempJsonObj); > + return RedfishCS_status_success; > +} > + > +/** > + This function returns a type-agnostic property. > + > + Cs The owner of this property. > + JsonObj The JSON object has the Key. > + Key The key in JSON object. > + DstBuffer Pointer to retrieve a type agnostic value. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +GetRedfishPropertyVague ( > + void *Cs, > + json_t *JsonObj, > + char *Key, > + RedfishCS_Vague **DstBuffer > + ) > +{ > + json_t *TempJsonObj; > + RedfishCS_status Status; > + RedfishCS_Vague *VagueData; > + > + if (DstBuffer =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + TempJsonObj =3D json_object_get (JsonObj, Key); > + if (TempJsonObj =3D=3D NULL) { > + return RedfishCS_status_not_found; > + } > + > + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_Vague), (void > **)&VagueData); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + if (json_is_string (TempJsonObj)) { > + VagueData->DataType =3D RedfishCS_Vague_DataType_String; > + Status =3D GetRedfishPropertyStr (Cs, JsonObj, Key, &Va= gueData- > >DataValue.CharPtr); > + } else if (json_is_integer (TempJsonObj)) { > + VagueData->DataType =3D RedfishCS_Vague_DataType_Int64; > + Status =3D GetRedfishPropertyInt64 (Cs, JsonObj, Key, &= VagueData- > >DataValue.Int64Ptr); > + } else if (json_is_boolean (TempJsonObj)) { > + VagueData->DataType =3D RedfishCS_Vague_DataType_Bool; > + Status =3D GetRedfishPropertyBoolean (Cs, JsonObj, Key,= &VagueData- > >DataValue.BoolPtr); > + } else if (json_is_null (TempJsonObj)) { > + *DstBuffer =3D NULL; // No value for this key > + free (VagueData); > + return RedfishCS_status_success; > + } else { > + return RedfishCS_status_unsupported; > + } > + > + if (Status =3D=3D RedfishCS_status_success) { > + *DstBuffer =3D VagueData; > + } > + > + return Status; > +} > + > +/** > + This function inserts a string JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + StringValue Value of string to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonStringObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_char *StringValue > + ) > +{ > + json_t *JsonValue; > + RedfishCS_char NullStr[] =3D ""; > + RedfishCS_char *InsertStr; > + > + InsertStr =3D StringValue; > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (InsertStr =3D=3D (char *)NULL) { > + InsertStr =3D NullStr; > + } > + > + JsonValue =3D json_string (InsertStr); > + if (JsonValue =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + if (json_object_set_new (ParentJsonObj, Key, JsonValue) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts a bool JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + BoolValue Value of a bool to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonBoolObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_bool *BoolValue > + ) > +{ > + json_t *JsonValue; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (BoolValue =3D=3D (RedfishCS_bool *)NULL) { > + return RedfishCS_status_success; // No value for this key. > + } > + > + JsonValue =3D json_boolean ((BOOLEAN)*BoolValue); > + if (JsonValue =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + if (json_object_set_new (ParentJsonObj, Key, JsonValue) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts a long long value JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + Int64Value Value of a long long to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonInt64Obj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_int64 *Int64Value > + ) > +{ > + json_t *JsonValue; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (Int64Value =3D=3D (RedfishCS_int64 *)NULL) { > + return RedfishCS_status_success; // No value for this key. > + } > + > + JsonValue =3D json_integer ((json_int_t)*Int64Value); > + if (JsonValue =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + if (json_object_set_new (ParentJsonObj, Key, JsonValue) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts a type-agnostic JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + VagueValue Value of a type agnostic value to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonVagueObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_Vague *VagueValue > + ) > +{ > + json_t *JsonValue; > + RedfishCS_char NullStr[] =3D ""; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (VagueValue =3D=3D (RedfishCS_Vague *)NULL) { > + JsonValue =3D json_null (); // No value for this key. > + } else if (VagueValue->DataType =3D=3D RedfishCS_Vague_DataType_String= ) { > + if (VagueValue->DataValue.CharPtr =3D=3D NULL) { > + JsonValue =3D json_string (NullStr); > + } else { > + JsonValue =3D json_string (VagueValue->DataValue.CharPtr); > + } > + } else if (VagueValue->DataType =3D=3D RedfishCS_Vague_DataType_Int64)= { > + JsonValue =3D json_integer ((json_int_t)*VagueValue->DataValue.Int64= Ptr); > + } else if (VagueValue->DataType =3D=3D RedfishCS_Vague_DataType_Bool) = { > + JsonValue =3D json_boolean ((BOOLEAN)*VagueValue->DataValue.BoolPtr)= ; > + } else { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (json_object_set_new (ParentJsonObj, Key, JsonValue) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts a link type JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + Link Value of a link type to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonLinkObj ( > + json_t *JsonObj, > + char *Key, > + RedfishCS_Link *Link > + ) > +{ > + json_t *JsonTextObj; > + RedfishCS_Type_JSON_Data *CsJsonHeader; > + > + if ((Link =3D=3D NULL) || (JsonObj =3D=3D NULL)) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (IsLinkEmpty (Link)) { > + return RedfishCS_status_success; > + } > + > + CsJsonHeader =3D (RedfishCS_Type_JSON_Data *)GetFirstLink (Link); > + if ((CsJsonHeader->Header.ResourceType !=3D RedfishCS_Type_JSON) && > + (CsJsonHeader->Header.ResourceType !=3D RedfishCS_Type_Uri)) > + { > + // Only support JSON/URI property for CStructure to JSON > + return RedfishCS_status_unsupported; > + } > + > + if (CsJsonHeader->JsonText =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (CsJsonHeader->Header.ResourceType =3D=3D RedfishCS_Type_JSON) { > + JsonTextObj =3D json_loads (CsJsonHeader->JsonText, 0, NULL); > + if (json_object_set_new (JsonObj, Key, JsonTextObj) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + } else { > + JsonTextObj =3D json_string (CsJsonHeader->JsonText); > + if (json_object_set_new (JsonObj, Key, JsonTextObj) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts an array of string JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + StringValueArray Value of a string array to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonStringArrayObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_char_Array *StringValueArray > + ) > +{ > + json_t *ArrayJson; > + json_t *ArrayMember; > + RedfishCS_char_Array *NextArray; > + RedfishCS_char NullStr[] =3D ""; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (StringValueArray =3D=3D (RedfishCS_char_Array *)NULL) { > + return RedfishCS_status_success; // No value for this key. > + } > + > + ArrayJson =3D json_array (); > + if (ArrayJson =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D StringValueArray; > + do { > + if (NextArray->ArrayValue =3D=3D NULL) { > + ArrayMember =3D json_string (NullStr); > + } else { > + ArrayMember =3D json_string (NextArray->ArrayValue); > + } > + > + if (json_array_append_new (ArrayJson, ArrayMember) !=3D 0) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D NextArray->Next; > + } while (NextArray !=3D NULL); > + > + if (json_object_set_new (ParentJsonObj, Key, ArrayJson) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts an array of bool JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + BoolValueArray Value of a bool array to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonBoolArrayObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_bool_Array *BoolValueArray > + ) > +{ > + json_t *ArrayJson; > + json_t *ArrayMember; > + RedfishCS_bool_Array *NextArray; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (BoolValueArray =3D=3D (RedfishCS_bool_Array *)NULL) { > + return RedfishCS_status_success; // No value for this key. > + } > + > + ArrayJson =3D json_array (); > + if (ArrayJson =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D BoolValueArray; > + do { > + ArrayMember =3D json_boolean ((BOOLEAN)*NextArray->ArrayValue); > + if (json_array_append_new (ArrayJson, ArrayMember) !=3D 0) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D NextArray->Next; > + } while (NextArray !=3D NULL); > + > + if (json_object_set_new (ParentJsonObj, Key, ArrayJson) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts an array of long long value JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + Int64ValueArray Value of a long long array to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonInt64ArrayObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_int64_Array *Int64ValueArray > + ) > +{ > + json_t *ArrayJson; > + json_t *ArrayMember; > + RedfishCS_int64_Array *NextArray; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (Int64ValueArray =3D=3D (RedfishCS_int64_Array *)NULL) { > + return RedfishCS_status_success; // No value for this key. > + } > + > + ArrayJson =3D json_array (); > + if (ArrayJson =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D Int64ValueArray; > + do { > + ArrayMember =3D json_integer (*NextArray->ArrayValue); > + if (json_array_append_new (ArrayJson, ArrayMember) !=3D 0) { > + return RedfishCS_status_unsupported; > + } > + > + NextArray =3D NextArray->Next; > + } while (NextArray !=3D NULL); > + > + if (json_object_set_new (ParentJsonObj, Key, ArrayJson) =3D=3D -1) { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts an array of link JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + LinkArray Value of a link array to insert. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +InsertJsonLinkArrayObj ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_Link *LinkArray > + ) > +{ > + json_t *ArrayJson; > + json_t *ArrayMember; > + RedfishCS_Type_Uri_Data *ThisLink; > + > + if (ParentJsonObj =3D=3D NULL) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (IsLinkEmpty (LinkArray)) { > + return RedfishCS_status_success; > + } > + > + ArrayJson =3D json_array (); > + if (ArrayJson =3D=3D NULL) { > + return RedfishCS_status_unsupported; > + } > + > + ThisLink =3D (RedfishCS_Type_Uri_Data *)GetFirstLink (LinkArray); > + while (RedfishCS_boolean_true) { > + if (ThisLink->Header.ResourceType !=3D RedfishCS_Type_Uri) { > + return RedfishCS_status_invalid_parameter; > + } > + > + if (ThisLink->Uri !=3D (RedfishCS_char *)NULL) { > + ArrayMember =3D json_string (ThisLink->Uri); > + if (json_array_append_new (ArrayJson, ArrayMember) !=3D 0) { > + return RedfishCS_status_unsupported; > + } > + } > + > + if (IsLinkAtEnd (LinkArray, &ThisLink->Header.LinkEntry)) { > + if (json_object_set_new (ParentJsonObj, Key, ArrayJson) =3D=3D -1)= { > + return RedfishCS_status_unsupported; > + } > + > + return RedfishCS_status_success; > + } > + > + ThisLink =3D (RedfishCS_Type_Uri_Data *)GetNextLink (LinkArray, &Thi= sLink- > >Header.LinkEntry); > + } > + > + return RedfishCS_status_success; > +} > + > +/** > + This function inserts an empty property type JSON object. > + > + ParentJsonObj The parent JSON object > + Key JSON key to insert. > + Link Value of an empty property type link. > + > + Return RedfishCS_status. > + > +**/ > +RedfishCS_status > +CsEmptyPropLinkToJson ( > + json_t *ParentJsonObj, > + char *Key, > + RedfishCS_Link *Link > + ) > +{ > + RedfishCS_uint32 Index; > + RedfishCS_Type_EmptyProp_CS_Data *EmptyProp_CS_Ptr; > + RedfishCS_EmptyProp_KeyValue *KeyValuePtr; > + json_t *JsonObj; > + RedfishCS_status Status; > + > + EmptyProp_CS_Ptr =3D (RedfishCS_Type_EmptyProp_CS_Data *)GetFirstLink > (Link); > + if (EmptyProp_CS_Ptr->Header.ResourceType !=3D > RedfishCS_Type_CS_EmptyProp) { > + return RedfishCS_status_unsupported; > + } > + > + JsonObj =3D json_object (); > + KeyValuePtr =3D EmptyProp_CS_Ptr->KeyValuePtr; > + for (Index =3D 0; Index < EmptyProp_CS_Ptr->NunmOfProperties; Index++)= { > + Status =3D InsertJsonVagueObj (JsonObj, KeyValuePtr->KeyNamePtr, > KeyValuePtr->Value); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + KeyValuePtr =3D KeyValuePtr->NextKeyValuePtr; > + } > + > + if (json_object_set_new (ParentJsonObj, Key, JsonObj) !=3D 0) { > + return RedfishCS_status_unknown_error; > + } > + > + return RedfishCS_status_success; > +} > diff --git a/RedfishClientPkg/ConverterLib/src/RedfishCsMemory.c > b/RedfishClientPkg/ConverterLib/src/RedfishCsMemory.c > new file mode 100644 > index 0000000000..aec03ead6f > --- /dev/null > +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsMemory.c > @@ -0,0 +1,238 @@ > +/** @file > + > + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + Copyright Notice: > + Copyright 2019-2021 Distributed Management Task Force, Inc. All rights > reserved. > + License: BSD 3-Clause License. For full text see link: > https://github.c/ > om%2FDMTF%2FRedfish-JSON-C-Struct- > Converter%2Fblob%2Fmaster%2FLICENSE.md&data=3D05%7C01%7Cnicklew%40n > vidia.com%7C6c287e287fb44d40c3e308db4baed8a2%7C43083d15727340c1b7d > b39efd9ccc17a%7C0%7C0%7C638186986569209689%7CUnknown%7CTWFpbG > Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn > 0%3D%7C3000%7C%7C%7C&sdata=3DVKor2rANpdKrvHJ7pEDkfh2XrTqQdtRVZjryv > urM1ms%3D&reserved=3D0 > +**/ > + > +#include "RedfishCsMemoryInternal.h" > +#include > +#include > + > +RedfishCS_Link CsMemRoot =3D { &CsMemRoot, &CsMemRoot }; > + > +/** > + This function records the memory allocation to > + the C Structure instance that owns the memory block. > + > + memCs C Structure instance. > + Return RedfishCS_status > + > +**/ > +RedfishCS_status > +recordCsRootMemory ( > + void *memCs > + ) > +{ > + RedfishCS_Internal_memory_root *memRoot; > + > + memRoot =3D malloc (sizeof (RedfishCS_Internal_memory_root)); > + if (memRoot =3D=3D NULL) { > + return RedfishCS_status_insufficient_memory; > + } > + > + InitializeLinkHead (&memRoot->nextRoot); > + InitializeLinkHead (&memRoot->memBlocks); > + memRoot->CsPtr =3D memCs; > + InsertTailLink (&CsMemRoot, &memRoot->nextRoot); > + return RedfishCS_status_success; > +} > + > +/** > + This function allocates and records the memory allocation > + to the C Structure instance that owns the memory block. > + > + rootCs C Structure instance. > + size The size to allocate. > + Dst Pointer to retrieve the pointer to memory > + block. > + Return RedfishCS_status > + > +**/ > +RedfishCS_status > +allocateRecordCsMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 size, > + RedfishCS_void **Dst > + ) > +{ > + RedfishCS_Internal_memory_root *memRoot; > + RedfishCS_Internal_memory_link *memLink; > + > + if (IsLinkEmpty (&CsMemRoot)) { > + return RedfishCS_status_invalid_parameter; > + } > + > + memRoot =3D (RedfishCS_Internal_memory_root *)GetFirstLink (&CsMemRoot= ); > + while (RedfishCS_boolean_true) { > + if (memRoot->CsPtr =3D=3D rootCs) { > + // Allocation memory and record it. > + memLink =3D malloc (sizeof (RedfishCS_Internal_memory_link)); > + if (memLink =3D=3D NULL) { > + return RedfishCS_status_insufficient_memory; > + } > + > + *Dst =3D malloc (size); > + if (*Dst =3D=3D NULL) { > + free (memLink); > + return RedfishCS_status_insufficient_memory; > + } > + > + memset (*Dst, 0, size); > + memset (memLink, 0, sizeof (RedfishCS_Internal_memory_link)); > + InitializeLinkHead (&memLink->nextLink); > + memLink->memoryPtr =3D *Dst; > + InsertTailLink (&memRoot->memBlocks, &memLink->nextLink); > + return RedfishCS_status_success; > + } > + > + if (IsLinkAtEnd (&CsMemRoot, (RedfishCS_Link *)&memRoot->nextRoot)) = { > + break; > + } > + > + memRoot =3D (RedfishCS_Internal_memory_root *)GetNextLink > (&CsMemRoot, &memRoot->nextRoot); > + } > + > + return RedfishCS_status_invalid_parameter; > +} > + > +/** > + This function allocates, records and zero out the memory > + to the C Structure instance that owns the memory block. > + > + rootCs C Structure instance. > + size The size to allocate. > + Dst Pointer to retrieve the pointer to memory > + block. > + Return RedfishCS_status > + > +**/ > +RedfishCS_status > +allocateRecordCsZeroMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 size, > + RedfishCS_void **Dst > + ) > +{ > + RedfishCS_status Status; > + > + Status =3D allocateRecordCsMemory (rootCs, size, Dst); > + if ((Status !=3D RedfishCS_status_success) || (*Dst =3D=3D NULL)) { > + return Status; > + } > + > + memset (*Dst, 0, size); > + return RedfishCS_status_success; > +} > + > +/** > + This function destroies all memory allocations belong > + to the C Structure instance. > + > + rootCs C Structure instance. > + > + Return RedfishCS_status > + > +**/ > +RedfishCS_status > +DestoryCsMemory ( > + RedfishCS_void *rootCs > + ) > +{ > + RedfishCS_Internal_memory_root *memRoot; > + RedfishCS_Internal_memory_link *memLink; > + > + if (IsLinkEmpty (&CsMemRoot)) { > + return RedfishCS_status_invalid_parameter; > + } > + > + memRoot =3D (RedfishCS_Internal_memory_root *)GetFirstLink (&CsMemRoot= ); > + while (RedfishCS_boolean_true) { > + if (memRoot->CsPtr =3D=3D rootCs) { > + if (IsLinkEmpty (&memRoot->memBlocks)) { > + return RedfishCS_status_success; > + } > + > + while (RedfishCS_boolean_true) { > + memLink =3D (RedfishCS_Internal_memory_link *)GetLastLink (&memR= oot- > >memBlocks); > + if (memLink->memoryPtr !=3D NULL) { > + free (memLink->memoryPtr); > + RemoveLink (&memLink->nextLink); > + free (memLink); > + } > + > + if (IsLinkEmpty (&memRoot->memBlocks)) { > + RemoveLink (&memRoot->nextRoot); > + free (memRoot); > + free (rootCs); > + return RedfishCS_status_success; > + } > + } > + } > + > + if (IsLinkAtEnd (&CsMemRoot, (RedfishCS_Link *)&memRoot->nextRoot)) = { > + break; > + } > + > + memRoot =3D (RedfishCS_Internal_memory_root *)GetNextLink > (&CsMemRoot, &memRoot->nextRoot); > + } > + > + return RedfishCS_status_invalid_parameter; > +} > + > +/** > + This function allocates an array of memory blocks owned > + by the C Structure instance. > + > + rootCs C Structure instance. > + ArrayInstanceSize Number of items in array. > + ArraySize The size of each array. > + Dst Pointer to retrieve the pointer to memory > + block. > + > + Return RedfishCS_status > + > +**/ > +RedfishCS_status > +allocateArrayRecordCsMemory ( > + RedfishCS_void *rootCs, > + RedfishCS_uint32 ArrayInstanceSize, > + RedfishCS_uint64 ArraySize, > + RedfishCS_void **Dst > + ) > +{ > + RedfishCS_uint16 Index; > + RedfishCS_void *ArrayInstance; > + RedfishCS_void *PreArrayInstance; > + RedfishCS_status Status; > + RedfishCS_uint16 SizeOfVoid; > + > + for (Index =3D 0; Index < ArraySize; Index++) { > + Status =3D allocateRecordCsMemory (rootCs, ArrayInstanceSize, > &ArrayInstance); > + if (Status !=3D RedfishCS_status_success) { > + return Status; > + } > + > + memset (ArrayInstance, 0, ArrayInstanceSize); > + if (Index =3D=3D 0) { > + *Dst =3D ArrayInstance; > + } else { > + SizeOfVoid =3D sizeof (RedfishCS_void *); > + if (SizeOfVoid =3D=3D sizeof (RedfishCS_uint32)) { > + *((RedfishCS_uint32 *)PreArrayInstance) =3D (RedfishCS_uint32)(u= nsigned > long long)ArrayInstance; // Next link. > + } else if (SizeOfVoid =3D=3D sizeof (RedfishCS_uint64)) { > + *((RedfishCS_uint64 *)PreArrayInstance) =3D > (RedfishCS_uint64)ArrayInstance; // Next link. > + } else { > + return RedfishCS_status_invalid_parameter; > + } > + } > + > + PreArrayInstance =3D ArrayInstance; > + } > + > + return RedfishCS_status_success; > +} > -- > 2.37.1.windows.1