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.web09.20922.1628768648071244907 for ; Thu, 12 Aug 2021 04:44:08 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Nhah4vQc; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0858956428=nickle.wang@hpe.com) Received: from pps.filterd (m0150241.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17CBcQ9Q030241; Thu, 12 Aug 2021 11:43:59 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=h83NJNm7ya6+PZQoTkq/FcpeG0Ky9xCl3ZTtPCx+TPE=; b=Nhah4vQcTB+Uhh+qdB7qiJ1WeFghcnff10EhXmu3JKGoLYsUX6ziFHvfD+Zw26NMX8j1 qyfqkYt3Pj1FfpsJ7j3RHX5HblqjesBrGIitjYZedurbYRM5hEfAU8xJ5yZKmWOvNGUn bIFipyjZucxWDJc0YLyo9lHOPcZefBdsRHU+dhr2ZfQ8El6U+aXaybc+Ed3Bov9y8EcS jdu8Etqe1s2106YblI09tk8wk4r0x33S09V8b26K+wQYAzwoxb9DgW0OCQak/B6TMVV/ KxyiLnO2+Xsbew11wCobH7kQGdmb2155Ks/DCS5jgQdXOi494t0zeQcljLHxcQTyU/iN sg== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 3ace7k9pbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 11:43:58 +0000 Received: from G9W8453.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.160.211]) (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 A5658AF; Thu, 12 Aug 2021 11:43:57 +0000 (UTC) Received: from G9W8454.americas.hpqcorp.net (2002:10d8:a104::10d8:a104) by G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 12 Aug 2021 11:43:57 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (15.241.52.12) by G9W8454.americas.hpqcorp.net (16.216.161.4) with Microsoft SMTP Server (TLS) id 15.0.1497.18 via Frontend Transport; Thu, 12 Aug 2021 11:43:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IxvXvm47U6UTZNu8mjG2q5rNAQpa15EWyIfJ796vy+8LaC/e9qKtZghvAzCz1eCR9sRImDk8EAe2Szkvzs9C+CtjgIFgdkgujxnGvEXbQVjCJVxVJRdZqE+qtb9+w/U5NHZ/9EtRwbdoZaBnveOI5zQIAul0kBtTX6PmYWHhi8dENLZvC5RvrqS0ebMyxdbZw2nA3B7h+EKMitn3iQA8bKcoeAvCK85pbc6+MbHiiUqcaHfzuAAbPgAh6lQ+BE2HNsP/ScwtfWyob9OP6HCbLDP3kG10U9bjmwz+CUqaQVFGXa0ubmGi71wwu7PHIBVxg3MVWssIacRRfd+X4Zun5w== 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=h83NJNm7ya6+PZQoTkq/FcpeG0Ky9xCl3ZTtPCx+TPE=; b=cggSl1KrKl81U97pGdFDJjEQlqdsiBbLjk5Nby4pvaXDsKzHYRTOxJYK9BHfwe4LIWO95YoZzfwx1l5jx8pGHKG1Dc87YZr0Pp2KWb6bYqCzVgRKL12YHlM+mQwEzyR1lYlvNNeoxDGPJS10EGW88g30U4o42ocIGfWQDl8LXtQGK9MmKPnS2bs23R+73tU2jU5r1TqPVNG6B9NdCCDys/9jnzUC+jJmX1iQzINVNd/5+QJtNYmmQltiOf2WCr/pLWi3I/7Pf0rhmjFczwqrC44ytA6ZtsNAVqOV3dsv3TeeYhaz9zz4hVQj4N1DXkQjbTmLYCSEyxLoXLOZiQgeig== 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 DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760d::7) by DF4PR8401MB0858.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.21; Thu, 12 Aug 2021 11:43:54 +0000 Received: from DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM ([fe80::44b6:ec1d:9c03:c520]) by DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM ([fe80::44b6:ec1d:9c03:c520%5]) with mapi id 15.20.4394.026; Thu, 12 Aug 2021 11:43:54 +0000 From: "Nickle Wang" To: "Chang, Abner (HPS SW/FW Technologist)" , "devel@edk2.groups.io" CC: Liming Gao Subject: Re: [PATCH] RedfishClientPkg/ConvertLib: Common code and header files Thread-Topic: [PATCH] RedfishClientPkg/ConvertLib: Common code and header files Thread-Index: AQHXj0gjoljWCE7BAE2thHGCDIQQ7atvv+oA Date: Thu, 12 Aug 2021 11:43:54 +0000 Message-ID: References: <20210812060733.28551-1-abner.chang@hpe.com> In-Reply-To: <20210812060733.28551-1-abner.chang@hpe.com> Accept-Language: en-US, zh-TW 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-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 88333685-156c-4f00-5c92-08d95d867674 x-ms-traffictypediagnostic: DF4PR8401MB0858: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1q/7YC0MIPpCtwvugTEpVWWNdH60SS7xtCBzVAdUaWR8JnQlQaekRe4QxKxBMNGNQe2MAAbfosvJWGhDgYDsdTAtBlk1ZsDjQkV8OvzgPwqKdln9qkTcGoeSf4gWMiNasM2kAofB10bccs7thb37VGCsOJATfGUFSHB92m1o/o/je3bcdhvb2jLG9ud0j04sql9386dKxAMR9mWmQ5HarekOPBH2YwYp0MIZuBZ8r1cgVU4xIMs92XbLu9QPSIecXLmUWNHIlkbjZkwXDzdbsA14q5dpImoqff3XubQuHhBo8zN7sA2OyIsyQn+jngkcauaApBAZniUZlSu4C20U+OuE+BABEB7vP2NWtAGz3MBD4pNCMxxbJGajM2trxWqe1VrSw6NPjAwz3sGEVZswh9ZZP2DLNsba+iZfthNLR7ZsmP+RUN8obAVpb7u53wtVRyZ6NI5OoyycxLlu4GgEtL5x2JgwCZAlmwCXgkTY8/UDAtEmCCCbl+DzXwfCIhfR5RYQJsUEVez4d0W8BkbSTyNxSQeBEhKW2girH44eHjGnRGDfi2+wkCvEl7yGUuzdagjhLhtCri2LjhVf7cY5lXu31817qf31g8KRAcW1ErIe35BhPd7HyK1SD967snQ8lIA+yglFcxmeggHG8v2dkffvi3ivuCrduAiCY/c0JTlkKP4GNFUlUQ1Uch8YUtD0kwNCd0ZSk1kmeEHQVpmjJg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(396003)(346002)(136003)(376002)(366004)(39860400002)(55236004)(6506007)(86362001)(53546011)(8676002)(478600001)(7696005)(2906002)(110136005)(83380400001)(55016002)(38070700005)(66476007)(66946007)(9686003)(33656002)(8936002)(52536014)(4326008)(76116006)(316002)(30864003)(66556008)(19627235002)(122000001)(64756008)(38100700002)(186003)(5660300002)(26005)(71200400001)(66446008)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?zy1wMNjeYyY8Q6wjtX9CJDlwtCQZ0dP3a2vVyQkCg/ZXmmortKrxPUyZaSNN?= =?us-ascii?Q?Kj7a5ow5KGJDem3QpAnzLH+rMLe7Zl1ewIqKhYy6ECFJqjk8d2ye4dUO33Un?= =?us-ascii?Q?s2Utr9v0YPOj9RSc8+iYi0cPxA+IiNNSYDGL6cMdBTM/sOdfsqQF4CA1Oh0H?= =?us-ascii?Q?v1PpEW/2zxtDiMbXHHnFkW/cAkWSPskIPpKV4p4/ZHy8WJAKtQzcMD42lC1r?= =?us-ascii?Q?q5J34NsqHqnK/vHvPclWUyOVDOxAtRdXFpreeUfbB+CQiChwdLrjVrzxf9e0?= =?us-ascii?Q?HNMpl8jExCuSlwYfcjlJDRbTVob9pYbR0tRgVtrMpuzukRpxlXx1nKQXzI2Z?= =?us-ascii?Q?aRcsSlQOWNd/GuwJMChc9yzugDoiEJzxGwmndn1OLReLzbaR1T3+gscip/nf?= =?us-ascii?Q?jZG0/s6rNgwS/iNpFIr1WZyLByn2qKp4xwMhCQThnRdeOmAyCpHKAtztd22H?= =?us-ascii?Q?vHlqKv1t3u/ndiUBSXAp/Gpmn4V3tlIAN6E/BSb7YmXPWnVeJMJngwSXnRia?= =?us-ascii?Q?3LrP1f+rCjIPdfG2WUGx0donzUoh6DHfj19MlC3hl4bTS202LZccCnRFF6xV?= =?us-ascii?Q?5O7cs7hoHSP+e7SwBOyuqvMg8xh9NHpyAXfU9omRdUSPcV5PPnezFBSNiLJq?= =?us-ascii?Q?aTFmELHPB7lqCAmldVszwgoQoZksd29Tc/2anVdC6zW52784vLEFXtVjxFlG?= =?us-ascii?Q?75xBZhijodUMW6A/+42T8J1TD7MfJdS3FAvFIt9w9XZQlx8xBve5i2GjxIJV?= =?us-ascii?Q?pNrJeqaUDpso80KJUOB3AncBd2UtCnQENC8cHT0dauRkJCSmqlK8h5llTeL6?= =?us-ascii?Q?jPF0ZqwNtcGMuSG7+MGMXRMYZMacvMKteg77biZrhYbh1ovs1Sv7nb8zkswm?= =?us-ascii?Q?EByiYkyagQrlqybZwbbDD3Xkwg4daTjdbxNff8FbwZ8S/dKyJp/y3cswKO9p?= =?us-ascii?Q?9Nxf+kMTZLJGaXsoRrRuKSn6EGSQ8HsCKhNEkb9f3pJ/+K8a5p8cD10yGa2f?= =?us-ascii?Q?oAV3oBCpJ4HvzNB/tLqiObhke3OUBR2VW3yLipDSB6W9dBUyyqD6Jle2X+8H?= =?us-ascii?Q?3DI3xYXfQr8LWvyV0a8yKQvCKRfAYVhVBkWIp5sZvkhipb8kO2TFAZrPLknA?= =?us-ascii?Q?+CBpsr4AWfrpUznVkUJDxCMwYj32ApKcdzGv5mBFsG0fHyDIG7nEFOmX7xba?= =?us-ascii?Q?DwdCNTZTqFL2YeraJDmQ3wJX4uXYA4km61kdPjtfdXySLMpBEH043na+Ie/r?= =?us-ascii?Q?hBKH8GImT1yer0o6pjwE2EgCcAM9gjmHqyyJblhoNikIvwxy/kErCzHQbxtn?= =?us-ascii?Q?5ASJdrFOH+eHVqBtJ+4yeO02?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DF4PR8401MB0812.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 88333685-156c-4f00-5c92-08d95d867674 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Aug 2021 11:43:54.1145 (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: /XIcR5YznnBbowPs68KeLaZ1ZMulfedIy3q5By+G8Yi92JoQegdyK5BWBeOECsEEG8Yix6+6dyAu0enzymTzcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB0858 X-OriginatorOrg: hpe.com X-Proofpoint-ORIG-GUID: 74cuAbld5KsJqyDoibY7waOPvUpPDcaa X-Proofpoint-GUID: 74cuAbld5KsJqyDoibY7waOPvUpPDcaa X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-12_04:2021-08-12,2021-08-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108120076 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Looks like we miss function header in this patch... Nickle -----Original Message----- From: Chang, Abner (HPS SW/FW Technologist) =20 Sent: Thursday, August 12, 2021 2:08 PM To: devel@edk2.groups.io Cc: Wang, Nickle (HPS SW) ; Liming Gao Subject: [PATCH] RedfishClientPkg/ConvertLib: Common code and header files ConverterLib/ is the folder of script-generated JSON to C library for the e= ach 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: Liming Gao --- .../ConverterLib/include/RedfishCsCommon.h | 122 +++ .../ConverterLib/include/RedfishDataTypeDef.h | 45 + .../src/RedfishCsMemoryInternal.h | 36 + .../ConverterLib/src/RedfishCsCommon.c | 831 ++++++++++++++++++ .../ConverterLib/src/RedfishCsMemory.c | 144 +++ 5 files changed, 1178 insertions(+) create mode 100644 RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h create mode 100644 RedfishClientPkg/ConverterLib/include/RedfishDataTypeDe= f.h create mode 100644 RedfishClientPkg/ConverterLib/src/RedfishCsMemoryIntern= al.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/Redf= ishClientPkg/ConverterLib/include/RedfishCsCommon.h new file mode 100644 index 0000000000..3810836123 --- /dev/null +++ b/RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h @@ -0,0 +1,122 @@ +/** @file + + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#ifndef REDFISH_CS_COMMON_H_ +#define REDFISH_CS_COMMON_H_ + +#include "RedfishDataTypeDef.h" + +RedfishCS_Link * InitializeLinkHead (RedfishCS_Link *LinkHead);=20 +RedfishCS_Link * InsertHeadLink (RedfishCS_Link *ListHead,=20 +RedfishCS_Link *Entry); RedfishCS_Link * InsertTailLink (RedfishCS_Link=20 +*ListHead, RedfishCS_Link *Entry); RedfishCS_Link * GetFirstLink (const=20 +RedfishCS_Link *List); RedfishCS_Link * GetLastLink (const=20 +RedfishCS_Link *List); RedfishCS_Link * GetNextLink (const=20 +RedfishCS_Link *List, const RedfishCS_Link *Node); RedfishCS_Link *=20 +GetPreviousLink ( const RedfishCS_Link *List, const RedfishCS_Link=20 +*Node); RedfishCS_Link *RemoveLink ( const RedfishCS_Link *Link);=20 +RedfishCS_bool IsLinkEmpty (const RedfishCS_Link *LinkHead);=20 +RedfishCS_bool IsLinkAtEnd (const RedfishCS_Link *LinkHead, const=20 +RedfishCS_Link *ThisLink); RedfishCS_status recordCsRootMemory (void=20 +*memCs); RedfishCS_status allocateRecordCsMemory (RedfishCS_void=20 +*rootCs, RedfishCS_uint32 size, RedfishCS_void **Dst); RedfishCS_status=20 +allocateRecordCsZeroMemory (RedfishCS_void *rootCs, RedfishCS_uint32=20 +size, RedfishCS_void **Dst); RedfishCS_status=20 +allocateArrayRecordCsMemory(RedfishCS_void *rootCs, RedfishCS_uint32=20 +ArrayInstanceSize, RedfishCS_uint64 ArraySize, RedfishCS_void **Dst);=20 +RedfishCS_status allocateDuplicateStr (void *Cs, char *Str, void=20 +**DstBuffer); RedfishCS_status DestoryCsMemory (RedfishCS_void=20 +*rootCs); + +typedef struct _RedfishCS_char_Array RedfishCS_char_Array; typedef=20 +struct _RedfishCS_int64_Array RedfishCS_int64_Array; typedef struct=20 +_RedfishCS_bool_Array RedfishCS_bool_Array; typedef struct=20 +_RedfishCS_Link_Array RedfishCS_Link_Array; typedef struct=20 +_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; }=20 +RedfishCS_Type_EmptyProp_CS_Data; + +#endif diff --git a/RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h b/R= edfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h new file mode 100644 index 0000000000..8c903482aa --- /dev/null +++ b/RedfishClientPkg/ConverterLib/include/RedfishDataTypeDef.h @@ -0,0 +1,45 @@ +/** @file + + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#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..689aff9519 --- /dev/null +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsMemoryInternal.h @@ -0,0 +1,36 @@ +/** @file + + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #ifndef=20 +REDFISH_CS_MEMORY_INTERNAL_H_ #define REDFISH_CS_MEMORY_INTERNAL_H_ + +#include "RedfishDataTypeDef.h" + +RedfishCS_Link * InitializeLinkHead (RedfishCS_Link *LinkHead);=20 +RedfishCS_Link * InsertHeadLink (RedfishCS_Link *ListHead,=20 +RedfishCS_Link *Entry); RedfishCS_Link * InsertTailLink (RedfishCS_Link=20 +*ListHead, RedfishCS_Link *Entry); RedfishCS_Link * GetFirstLink (const=20 +RedfishCS_Link *List); RedfishCS_Link * GetLastLink (const=20 +RedfishCS_Link *List); RedfishCS_Link * GetNextLink (const=20 +RedfishCS_Link *List, const RedfishCS_Link *Node); RedfishCS_Link *=20 +GetPreviousLink ( const RedfishCS_Link *List, const RedfishCS_Link=20 +*Node); RedfishCS_Link *RemoveLink ( const RedfishCS_Link *Link);=20 +RedfishCS_bool IsLinkEmpty (const RedfishCS_Link *LinkHead);=20 +RedfishCS_bool IsLinkAtEnd (const RedfishCS_Link *LinkHead, const=20 +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/RedfishC= lientPkg/ConverterLib/src/RedfishCsCommon.c new file mode 100644 index 0000000000..cb80121831 --- /dev/null +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c @@ -0,0 +1,831 @@ +/** @file + + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "RedfishCsCommon.h" +#include "RedfishCsMemoryInternal.h" +#include +#include +#include + +RedfishCS_status GetRedfishPropertyVague(void *Cs, json_t *JsonObj,=20 +char *Key, RedfishCS_Vague **DstBuffer); + +RedfishCS_Link *InitializeLinkHead (RedfishCS_Link *ListHead) { + ListHead->ForwardLink =3D ListHead; + ListHead->BackLink =3D ListHead; + return ListHead; +} + +RedfishCS_Link *InsertHeadLink (RedfishCS_Link *ListHead,=20 +RedfishCS_Link *Entry) { + Entry->ForwardLink =3D ListHead->ForwardLink; + Entry->BackLink =3D ListHead; + Entry->ForwardLink->BackLink =3D Entry; + ListHead->ForwardLink =3D Entry; + return ListHead; +} + +RedfishCS_Link * InsertTailLink (RedfishCS_Link *ListHead,=20 +RedfishCS_Link *Entry) { + Entry->ForwardLink =3D ListHead; + Entry->BackLink =3D ListHead->BackLink; + Entry->BackLink->ForwardLink =3D Entry; + ListHead->BackLink =3D Entry; + return ListHead; +} + +RedfishCS_Link *GetFirstLink (const RedfishCS_Link *List) { + return List->ForwardLink; +} + +RedfishCS_Link *GetLastLink (const RedfishCS_Link *List) { + return List->BackLink; +} + +RedfishCS_Link *GetNextLink (const RedfishCS_Link *List, const=20 +RedfishCS_Link *Node) { + return Node->ForwardLink; +} + +RedfishCS_Link *GetPreviousLink (const RedfishCS_Link *List, const=20 +RedfishCS_Link *Node) { + return Node->BackLink; +} +RedfishCS_Link *RemoveLink ( const RedfishCS_Link *Link) { + Link->ForwardLink->BackLink =3D Link->BackLink; + Link->BackLink->ForwardLink =3D Link->ForwardLink; + return Link->ForwardLink; +} + +RedfishCS_bool IsLinkEmpty (const RedfishCS_Link *LinkHead) { return=20 +(RedfishCS_bool)(LinkHead->ForwardLink =3D=3D LinkHead); } + +RedfishCS_bool IsLinkAtEnd (const RedfishCS_Link *LinkHead, const=20 +RedfishCS_Link *ThisLink) { + return (RedfishCS_bool)(ThisLink->ForwardLink =3D=3D LinkHead); } + +RedfishCS_status allocateDuplicateStr (void *Cs, char *Str, void=20 +**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,=20 +(void **)DstBuffer); + if (Status !=3D RedfishCS_status_success) { + return Status; + } + memcpy (*DstBuffer, Str, strlen(Str) + 1); + return RedfishCS_status_success; +} + +RedfishCS_status CreateCsUriByOdataId (json_t *JsonOj, RedfishCS_char=20 +*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.id"); + CsTypeUri->Uri =3D (RedfishCS_char *)strdup (json_string_value=20 +(TempJsonObj)); + *CsTypeUriData =3D CsTypeUri; + return RedfishCS_status_success; +} + +RedfishCS_status CreateCsUriByNode (void *Cs, json_t *JsonOj,=20 +RedfishCS_char *NodeName, RedfishCS_char *ParentUri,=20 +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_Data= ), (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, NodeName, (void **)&CsTypeUri->He= ader.KeyName); + if (Status !=3D RedfishCS_status_success) { + return Status; + } + *CsTypeUriData =3D CsTypeUri; + Status =3D allocateDuplicateStr (Cs, (char *)json_string_value (TempJs= onObj2), (void **)&CsTypeUri->Uri); + return Status; + } + return RedfishCS_status_invalid_parameter; +} + +RedfishCS_status CreateCsJsonByNode (void *Cs, json_t *JsonObj,=20 +RedfishCS_char *NodeName, RedfishCS_char *ParentUri,=20 +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 ((const json_t *)TempJsonObj, JSON_INDENT (2)); + if (TempChar !=3D NULL) { + Status =3D allocateRecordCsMemory (Cs, sizeof (RedfishCS_Type_JSON_Dat= a), (void **)&CsTypeJson); + if (Status !=3D RedfishCS_status_success) { + return Status; + } + Status =3D allocateRecordCsMemory (Cs, (RedfishCS_int)strlen (TempChar= ) + 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, NodeName, (void **)&CsTypeJson->H= eader.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; +} + +RedfishCS_status CreateEmptyPropCsJson(RedfishCS_void *Cs, json_t=20 +*JsonObj, RedfishCS_char *NodeName, RedfishCS_char *ParentUri,=20 +RedfishCS_Type_EmptyProp_CS_Data **CsTypeEmptyPropCSData,=20 +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,=20 + 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; = =20 + CsTypeEmptyPropCS->Header.ThisUri =3D ParentUri; Status =3D=20 + allocateDuplicateStr(Cs, NodeName, (void=20 + **)&CsTypeEmptyPropCS->Header.KeyName); + if (Status !=3D RedfishCS_status_success) { + return Status; + } + CsTypeEmptyPropCS->NunmOfProperties =3D NunmOfProperties; // //=20 + Create instance for each key-value. + // + KeyValuePtr =3D &CsTypeEmptyPropCS->KeyValuePtr; =20 + json_object_foreach_safe(TempJsonObj, n, KeyName, KeyValueObj) { + Status =3D allocateRecordCsMemory(Cs, sizeof(RedfishCS_EmptyProp_KeyVa= lue), (void **)&KeyValue); + if (Status !=3D RedfishCS_status_success) { + return Status; + } + Status =3D allocateDuplicateStr(Cs, (char *)KeyName, (void **)&KeyValu= e->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; +} + +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; +} + +RedfishCS_bool CheckEmptyPropJsonObject(json_t *JsonObj,=20 +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; +} + +RedfishCS_bool SupportedRedfishResource (RedfishCS_char *Odata_Type,=20 +RedfishCS_char *NameSpace, RedfishCS_char *Version, RedfishCS_char=20 +*DataType) { + RedfishCS_char *TargetDataType; + + if (Odata_Type =3D=3D NULL || NameSpace =3D=3D NULL || DataType =3D=3D N= ULL) { + return RedfishCS_boolean_false; + } + if (Version !=3D NULL) { + TargetDataType =3D malloc(strlen(NameSpace) + strlen(Version) + 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. + } 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; +} + +RedfishCS_status +CreateCsUriOrJsonByNode (void *Cs, json_t *JsonObj, RedfishCS_char=20 +*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, &CsTyp= eUri); + if (Status =3D=3D RedfishCS_status_success) { + InsertTailLink (LinkHead, &CsTypeUri->Header.LinkEntry); + return RedfishCS_status_success; + } + } else { + Status =3D CreateCsJsonByNode (Cs, JsonObj, NodeName, ParentUri, &CsTy= peJson); + if (Status =3D=3D RedfishCS_status_success) { + InsertTailLink (LinkHead, &CsTypeJson->Header.LinkEntry); + return RedfishCS_status_success; + } + } + return Status; +} + +RedfishCS_status +CreateCsUriOrJsonByNodeArray (void *Cs, json_t *JsonObj, RedfishCS_char=20 +*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 (J= sonObjTemp); 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, &Cs= TypeUri); + if (Status =3D=3D RedfishCS_status_success) { + InsertTailLink (LinkHead, &CsTypeUri->Header.LinkEntry); + } + } else { + Status =3D CreateCsJsonByNode (Cs, JsonObjArray, NULL, ParentUri, &C= sTypeJson); + if (Status =3D=3D RedfishCS_status_success) { + InsertTailLink (LinkHead, &CsTypeJson->Header.LinkEntry); + } + } + } + return RedfishCS_status_success; +} + +RedfishCS_status +CreateJsonPayloadAndCs (char *JsonRawText, char *ResourceType, char=20 +*ResourceVersion, char *TypeName, json_t **JsonObjReturned, void **Cs,=20 +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, Resour= ceType, 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); +} + +RedfishCS_status GetRedfishPropertyStr (void *Cs, json_t *JsonObj, char=20 +*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=20 +*)json_string_value(TempJsonObj), (void **)DstBuffer); + return Status; +} + +RedfishCS_status GetRedfishPropertyBoolean (void *Cs, json_t *JsonObj,=20 +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=20 +**)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; +} + +RedfishCS_status GetRedfishPropertyInt64 (void *Cs, json_t *JsonObj,=20 +char *Key, RedfishCS_int64 **Dst) { + RedfishCS_status Status; + const 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=20 +**)Dst); + if (Status !=3D RedfishCS_status_success){ + return Status; + } + **Dst =3D (RedfishCS_int64)json_integer_value(TempJsonObj); + return RedfishCS_status_success; +} + +RedfishCS_status GetRedfishPropertyVague (void *Cs, json_t *JsonObj,=20 +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=20 + NULL){ + return RedfishCS_status_not_found; + } + Status =3D allocateRecordCsMemory(Cs, sizeof(RedfishCS_Vague), (void=20 + **)&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,=20 +&VagueData->DataValue.CharPtr); + } else if (json_is_integer(TempJsonObj)) { + VagueData->DataType =3D RedfishCS_Vague_DataType_Int64; + Status =3D GetRedfishPropertyInt64 (Cs, JsonObj, Key,=20 +&VagueData->DataValue.Int64Ptr); + } else if (json_is_boolean(TempJsonObj)) { + VagueData->DataType =3D RedfishCS_Vague_DataType_Bool; + Status =3D GetRedfishPropertyBoolean (Cs, JsonObj, Key,=20 +&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; +} + +RedfishCS_status InsertJsonStringObj (json_t *ParentJsonObj, char *Key,=20 +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; +} + +RedfishCS_status InsertJsonBoolObj (json_t *ParentJsonObj, char *Key,=20 +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; +} + +RedfishCS_status InsertJsonInt64Obj (json_t *ParentJsonObj, char *Key,=20 +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; +} + +RedfishCS_status InsertJsonVagueObj (json_t *ParentJsonObj, char *Key,=20 +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=20 +json_integer((json_int_t)*VagueValue->DataValue.Int64Ptr); + } 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; +} + +RedfishCS_status InsertJsonLinkObj (json_t *JsonObj, char *Key,=20 +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=20 + (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=20 + =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; +} + +RedfishCS_status InsertJsonStringArrayObj (json_t *ParentJsonObj, char=20 +*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=20 + 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; +} + +RedfishCS_status InsertJsonBoolArrayObj (json_t *ParentJsonObj, char=20 +*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=20 + 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; +} + +RedfishCS_status InsertJsonInt64ArrayObj (json_t *ParentJsonObj, char=20 +*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=20 + 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; +} + +RedfishCS_status InsertJsonLinkArrayObj (json_t *ParentJsonObj, char=20 +*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,=20 +&ThisLink->Header.LinkEntry); + }; + return RedfishCS_status_success; +} + +RedfishCS_status CsEmptyPropLinkToJson(json_t *ParentJsonObj, char=20 +*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=20 + *)GetFirstLink(Link); if (EmptyProp_CS_Ptr->Header.ResourceType !=3D Red= fishCS_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, KeyVal= uePtr->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/RedfishC= lientPkg/ConverterLib/src/RedfishCsMemory.c new file mode 100644 index 0000000000..9dbab2c0b1 --- /dev/null +++ b/RedfishClientPkg/ConverterLib/src/RedfishCsMemory.c @@ -0,0 +1,144 @@ +/** @file + + (C) Copyright 2018-2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "RedfishCsMemoryInternal.h" +#include +#include + +RedfishCS_Link CsMemRoot =3D {&CsMemRoot, &CsMemRoot}; + +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; +} + +RedfishCS_status allocateRecordCsMemory (RedfishCS_void *rootCs,=20 +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=20 + (&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=20 + (&CsMemRoot, &memRoot->nextRoot); }; + + return RedfishCS_status_invalid_parameter; +} + +RedfishCS_status allocateRecordCsZeroMemory (RedfishCS_void *rootCs,=20 +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; +} + +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=20 +(&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(&memRoot= ->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=20 +(&CsMemRoot, &memRoot->nextRoot); + }; + return RedfishCS_status_invalid_parameter; +} +RedfishCS_status allocateArrayRecordCsMemory(RedfishCS_void *rootCs,=20 +RedfishCS_uint32 ArrayInstanceSize, RedfishCS_uint64 ArraySize,=20 +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, &ArrayIns= tance); + 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)(uns= igned long long)ArrayInstance; // Next link. + } else if (SizeOfVoid =3D=3D sizeof (RedfishCS_uint64)){ + *((RedfishCS_uint64 *)PreArrayInstance) =3D (RedfishCS_uint64)Arra= yInstance; // Next link. + } else { + return RedfishCS_status_invalid_parameter; + } + } + PreArrayInstance =3D ArrayInstance; + } + return RedfishCS_status_success; +} -- 2.17.1