From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.71]) by mx.groups.io with SMTP id smtpd.web12.46538.1660851692823838654 for ; Thu, 18 Aug 2022 12:41:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ami.com header.s=selector1 header.b=NCouFHJy; spf=pass (domain: ami.com, ip: 40.107.93.71, mailfrom: igork@ami.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TRXSH+eU6T68tGI17mgHQLS2Jr15p/gVl4BGspTv/3EUpTkorGOz6c7EOY52CVGaUG5DlmLIWter5TMAlNPQR3Y7uWG11sFrBsZcwPdUmcbXmGz2KI8NOVt6mhCNsfh3KTgBYekDhcVP938HygDFvnxr40v2br74O0xDfDRxtN1sy63h3tdmdM9fJDcrTtpP5mk13mR8Q0f6B2k7OXq9gy0niB9PWCkPeH1lLWb2U4i5YdtkJ7X6fAToi3Y6DY5G/nYV/t3GWfD34Gu4dooqVPxnraeKvPmnMbV2vBsJ7RJOFhoIeBagTIuMu3R88HX2vvOfEl/Nlo27+dS9E1IdrQ== 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=v1AZfN0qeZCKBws+cmtMFmTJjTpVyM9MLW+KQv3Udfw=; b=SGSmignZkQUt8Z4TjhkBfOLXeOG/WXn5I0ztzymfpis5a6d/VelmUqRYGTQG7k6G1BbYE+wUBo+NLrHZeeGI4QcR+4rT+R3MKQ//1E4qCrvAou22Ic9LQtE60Lh/j1q+SDkOpFrRkAXp5RrSXEOCm3dpR9XxvPW3tJO74eUFbVcBv0CN945iPkqPo/C1fNQD34rVbGWi1fMhf/AxE2RT0IPrVBcEPxfWEo0YPLo2VIkISnHWz0+Y3VmrJPA7gAOhKfQi/imoOYSEK7ZM1wg16kq7C2SqfsDTVsguR90+6A7Kl8Xx/ssVURNQTx0rkt7E1JHgsxsz/TiNDas5BoFEOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ami.com; dmarc=pass action=none header.from=ami.com; dkim=pass header.d=ami.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ami.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1AZfN0qeZCKBws+cmtMFmTJjTpVyM9MLW+KQv3Udfw=; b=NCouFHJyHzEyoQ1LiOshPgtzXqBxwv9KrNzVb7WXWE+70QLDDtAVkwcAgfvSsODjhJbkCjv+X0KCpWR4wH7nd2hniV95Eb//6W7deen0HoA8rkoNS7IzWzfe585LiLkUKCA8tK5GJKEr/1VMye2kQP04tjxv8FJKaMkFaXHKbcg= Received: from BLAPR10MB5185.namprd10.prod.outlook.com (2603:10b6:208:328::16) by DM6PR10MB3035.namprd10.prod.outlook.com (2603:10b6:5:6f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Thu, 18 Aug 2022 19:41:30 +0000 Received: from BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::3007:4429:73e9:503e]) by BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::3007:4429:73e9:503e%3]) with mapi id 15.20.5525.019; Thu, 18 Aug 2022 19:41:29 +0000 From: "Igor Kulchytskyy" To: "devel@edk2.groups.io" CC: "Abner.Chang@amd.com" , "nickle.wang@hpe.com" , Igor Kulchytskyy , Abner Chang Subject: [PATCH V4 3/3] RedfishPkg: Redfish functions for REST requests are not fully spec complied Thread-Topic: [PATCH V4 3/3] RedfishPkg: Redfish functions for REST requests are not fully spec complied Thread-Index: AQHYszqD8Z4AxLEDXkCisiWzK4C+mQ== Date: Thu, 18 Aug 2022 19:41:29 +0000 Message-ID: <1660851683-3680-1-git-send-email-igork@ami.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=ami.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1b3d99d3-4079-4422-db2a-08da8151a5b9 x-ms-traffictypediagnostic: DM6PR10MB3035:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NEWygYxuLXKlUAPbEzmd9O4OORCaw6wv/SSWg8jRYSXbMpkQ75KL8Crm1FEuGk3o1DtnuWqgqALC1tjULVn5Ndd8R6H8zoXu+XNOAYUdbeMfT30Q4k8KgC9fZ0eIbHLK4xlVoXFOcB/UMziTRaB71LXsAZkX8tZbDLlymV92AWqhoDBv+sdlKQRJmh8/wHmeNyUepTe1Tq4i3m7OyMT2rZq2rfAyuLFwa1Iccui9p+y3NPZ7fSeDF+8nD2PyK7CVOKN7yhJ99ruzinKJ7gysxnGKcu5cjOYzur96QPNgXkusWYCKT9D4cnDvZZ9xFw/lQjecNQ0ViPmwwQCltpZ2LAoQbcmpauJftEtFj5hdXK+yrwb1yrlIuWoKKdJ21Q+LKTymGxsVdq09/VCIC+p6G7EKmMGpQg1B+7YklH2xZ4w7UFs0YlY/VLRmjuRHgjJoSTkaG0X/MJdSPQMyBux5o6wwMznl4PhNAuy+IuNOVlnOzSvLiO9WCTnuB1tIS0e9oVpkpin8XyZ3ek6BE0LGp4P3HSjkRXSqRCpXjYo+des0MQxU1t3WIAhPC4HzW7IxOgZAXbqpDSDxyIGsvtxtWDjG+akIPu7973VGopQWzYAVBBQ7HKFPOGPtkCv172Qug7EASSxVfi8cmlzNWfaqZ1pnbS9M0w/o26RLhXfRoofR3If0YzJ+YgV/B4k2g3SoSV0+8cNPe2a5r7OzEXJBNo/T6VKhubWSd9BHqUbbNAlAMcSz/Zl09WPPJps1Dkf7rgxfiiaIElaajZOaZ9M8Lg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5185.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(346002)(136003)(366004)(376002)(39850400004)(396003)(36756003)(86362001)(38100700002)(2906002)(316002)(6916009)(71200400001)(54906003)(122000001)(26005)(91956017)(4326008)(186003)(5660300002)(8676002)(6486002)(66946007)(6506007)(66446008)(6512007)(76116006)(66476007)(2616005)(64756008)(66556008)(478600001)(83380400001)(40140700001)(38070700005)(30864003)(8936002)(41300700001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?ySwJ2dbJXxXI1dm6wJTAmeZ5cCCh4t1phwIcaW4Ck0O9lVnqXr9AD0i9i/?= =?iso-8859-1?Q?HpDqg1IjsN9Bkj6NxLTxzNj3mvq/PIcruSugBUQkVR28Il3AvcjJyvo3bp?= =?iso-8859-1?Q?eNnAg3xsRwfvbWGfcNa//tfATMhJxKVKNNE5pepRVusvv0gICoYo3GTSpH?= =?iso-8859-1?Q?t69QY4DzELdjne5XsSzmjptebn7ydQzDJ5qdc3XtlEWGS3zRL5vGOcok1V?= =?iso-8859-1?Q?8os6SJT9DefTGed0/1GX0T9M641sU39JXEnHjGzn6Rs4oYYgeBRd1xobcN?= =?iso-8859-1?Q?ceJ82CoJP+2iHObK8W8LP6L0M2lLN/IQ5RWDYm97AeiTX+7TINntyLQ06U?= =?iso-8859-1?Q?qzZZtPfiy4M8NxQuU6Tl9zsDz12Yrzzy9cRbPHNtyem11Qp37BMLIasdwN?= =?iso-8859-1?Q?LXzI+pgc4y/9vZfWPWnXR70zb2oyvVygDzqYBHFQxi4QXNmYDMbpbg/aFq?= =?iso-8859-1?Q?xfCR4V9rCvyFMLJAbEl/9YBqw8B7Q4ECxEqYj6q+5uljB1lu0OFxCa3YdK?= =?iso-8859-1?Q?agLByr959EDjCh4taMLFdoJlmH5VjtiWqJR9sUNVdCisL50yBB9/PuDwwN?= =?iso-8859-1?Q?KIjY9Cr1mLT0Rgj6iBg1NBVY25jH35Y7QrtTnnf6tsMHFLxtuwB9kLEZFJ?= =?iso-8859-1?Q?HBjjIu4DBaYutt7UwwVOvGqGG4W0PqvdF5kIZWdQxIr9YLFas2ZY2NwiR1?= =?iso-8859-1?Q?N5E1bnxVwVql8gbLeUBYVCOHpCgjDGa8eVJTk02icBIhrfZMZOFrU2SSIk?= =?iso-8859-1?Q?68tB2TCR3YZkyRbSLWBibhCdVMZAAgsrcQoHi9iYFeAUWPrCV7XaoPNqJ5?= =?iso-8859-1?Q?8vHjq6B7kyTTh7TdGxkSdQ68SJr0T88Vay0MGGBIS5mpd3Gt6ZX5XUWWVk?= =?iso-8859-1?Q?lF1oA2CS7Yd9ndfqQ93u6OKSKqb8Tod3m5NW5RvNpckFzolw9vMWCjtfdZ?= =?iso-8859-1?Q?L0Ppjg3KmfZAis5+puvc+Oj/oANbrMTrU7ef1AAwzACCssPx/Koz+ueXyc?= =?iso-8859-1?Q?ojPROHCFaM0Ndw9YSwed5Klcbf7YIMVFGJ7Gr5hlOCnygyxP5TsayXgPeN?= =?iso-8859-1?Q?RtXg/PB86u8a32XFzIQQmmlwRQXRr40AbZLah46pSjQMYysWv7KKmIqnFp?= =?iso-8859-1?Q?yTR/OwcGmP7kA/Ehq8+8Zmc9DyzUXQK9YewjYWYs+EfAKbg3oB9HCzgCoD?= =?iso-8859-1?Q?xXmQkcOBbCbMbVPDlAfCUiFy4yGnP0Ik/uixNSmyLku5eikomjB1suJ4rp?= =?iso-8859-1?Q?A1HaAEq00/W43vRPQkIkRA70O6NSVsBtBqu7XhM3I5mVS0hpUYIOEoGJyG?= =?iso-8859-1?Q?EPlb7ticRATCQzPXt+VSt398eiuq5dV6xCyMjnREil0QVgiF9XTxw62A3p?= =?iso-8859-1?Q?dpYX0R22zJID3cjiTA/Y+aD98F27tg70TXc2wp5kFzX5mG0ACjBl6w+Kd2?= =?iso-8859-1?Q?oyqXabIPlAqB/I7+MJlfhDXR1PjnTeHOD6G8wgfFwT8oQEDPmRsE4bGrqw?= =?iso-8859-1?Q?S7IGBXfy2LbDa5vIfmRNhBtjZdnSVl6aFZkbfIcKVfGRVULNUjyVmP9QmQ?= =?iso-8859-1?Q?16uXiU2kLsm5PTDL+wmRvi3RyeL9NifyMc6unjTPdwO382Zvc6Ag+La7TN?= =?iso-8859-1?Q?2Q6taDBV5C6K5cY6Li6UGds3MeM01tkqnR?= MIME-Version: 1.0 X-OriginatorOrg: ami.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5185.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b3d99d3-4079-4422-db2a-08da8151a5b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Aug 2022 19:41:29.8945 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 27e97857-e15f-486c-b58e-86c2b3040f93 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6j/coGf4qKANXxU6izGnbenV1Q/J8uF3uir78wgEy2buUmwBtojKfSNadBX1pOdu X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3035 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable There is no function to send POST request with the ContentType different from "application\json". There is no function to send DELETE request with the body. Cc: Abner Chang Cc: Nickle Wang Signed-off-by: Igor Kulchytskyy --- RedfishPkg/Include/Library/RedfishLib.h = | 80 +++++++++ RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c = | 189 ++++++++++++++++++++ RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService= .h | 8 + RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c = | 41 ++++- 4 files changed, 316 insertions(+), 2 deletions(-) diff --git a/RedfishPkg/Include/Library/RedfishLib.h b/RedfishPkg/Include/L= ibrary/RedfishLib.h index b2488ab..ce39ce3 100644 --- a/RedfishPkg/Include/Library/RedfishLib.h +++ b/RedfishPkg/Include/Library/RedfishLib.h @@ -380,6 +380,49 @@ RedfishPatchToPayload ( OUT REDFISH_RESPONSE *RedResponse ); + +/** + Use HTTP POST to create new Redfish resource in the Resource Collection. + + The POST request should be submitted to the Resource Collection in which= the new resource + is to belong. The Resource Collection is addressed by URI. The Redfish m= ay + ignore any service controlled properties. The corresponding redfish resp= onse will returned, + including HTTP StatusCode, Headers and Payload which record any HTTP res= ponse messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be up= date. + @param[in] ContentSize Size of the Content to be send to Re= dfish service + @param[in] ContentType Type of the Content to be send to Re= dfish service + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX. The Redfish r= esource will be returned + in Payload within RedResponse if server = send it back in the HTTP + response message body. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResp= onse is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishPostToUri ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + IN UINTN ContentSize, + IN CONST CHAR8 *ContentType, + OUT REDFISH_RESPONSE *RedResponse + ); + + /** Use HTTP POST to create a new resource in target payload. @@ -451,6 +494,43 @@ RedfishDeleteByUri ( ); /** + Use HTTP DELETE to remove a resource. + + This function uses the RedfishService to remove a Redfish resource which= is addressed + by input Uri (only the relative path is required). The corresponding red= fish response will + returned, including HTTP StatusCode, Headers and Payload which record an= y HTTP response + messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be de= leted. + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX, the Redfish r= esource has been removed. + If there is any message returned from se= rver, it will be returned + in Payload within RedResponse. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, or RedResponse is N= ULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishDeleteByUriEx ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + OUT REDFISH_RESPONSE *RedResponse + ); + +/** Dump text in fractions. @param[in] String ASCII string to dump. diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c b/RedfishPkg= /PrivateLibrary/RedfishLib/RedfishLib.c index 9f9d377..6c0f426 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c @@ -583,6 +583,104 @@ RedfishPatchToPayload ( return EFI_SUCCESS; } + +/** + Use HTTP POST to create new Redfish resource in the Resource Collection. + + The POST request should be submitted to the Resource Collection in which= the new resource + is to belong. The Resource Collection is addressed by URI. The Redfish m= ay + ignore any service controlled properties. The corresponding redfish resp= onse will returned, + including HTTP StatusCode, Headers and Payload which record any HTTP res= ponse messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be up= date. + @param[in] ContentSize Size of the Content to be send to Re= dfish service + @param[in] ContentType Type of the Content to be send to Re= dfish service + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX. The Redfish r= esource will be returned + in Payload within RedResponse if server = send it back in the HTTP + response message body. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResp= onse is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishPostToUri ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + IN UINTN ContentSize, + IN CONST CHAR8 *ContentType, + OUT REDFISH_RESPONSE *RedResponse + ) +{ + EFI_STATUS Status; + EDKII_JSON_VALUE JsonValue; + + Status =3D EFI_SUCCESS; + JsonValue =3D NULL; + + if ((RedfishService =3D=3D NULL) || (Uri =3D=3D NULL) || (Content =3D=3D= NULL) || (RedResponse =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE)); + + JsonValue =3D (EDKII_JSON_VALUE)postUriFromService ( + RedfishService, + Uri, + Content, + ContentSize, + ContentType, + &(RedResponse->StatusCode) + ); + + // + // 1. If the returned StatusCode is NULL, indicates any error happen. + // + if (RedResponse->StatusCode =3D=3D NULL) { + Status =3D EFI_DEVICE_ERROR; + goto ON_EXIT; + } + + // + // 2. If the returned StatusCode is not NULL and the value is not 2XX, i= ndicates any error happen. + // NOTE: If there is any error message returned from server, it will = be returned in + // Payload within RedResponse. + // + if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \ + (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)) + { + Status =3D EFI_DEVICE_ERROR; + } + +ON_EXIT: + if (JsonValue !=3D NULL) { + RedResponse->Payload =3D createRedfishPayload (JsonValue, RedfishServi= ce); + if (RedResponse->Payload =3D=3D NULL) { + // + // Ignore the error when create RedfishPayload, just free the JsonVa= lue since it's not what + // we care about if the returned StatusCode is 2XX. + // + JsonValueFree (JsonValue); + } + } + + return Status; +} + + /** Use HTTP POST to create a new resource in target payload. @@ -738,6 +836,97 @@ ON_EXIT: return Status; } + +/** + Use HTTP DELETE to remove a resource. + + This function uses the RedfishService to remove a Redfish resource which= is addressed + by input Uri (only the relative path is required). The corresponding red= fish response will + returned, including HTTP StatusCode, Headers and Payload which record an= y HTTP response + messages. + + Callers are responsible for freeing the HTTP StatusCode, Headers and Pay= load returned in + redfish response data. + + @param[in] RedfishService The Service to access the Redfish re= sources. + @param[in] Uri Relative path to address the resourc= e. + @param[in] Content JSON represented properties to be de= leted. + @param[out] RedResponse Pointer to the Redfish response data= . + + @retval EFI_SUCCESS The opeartion is successful, indicates t= he HTTP StatusCode is not + NULL and the value is 2XX, the Redfish r= esource has been removed. + If there is any message returned from se= rver, it will be returned + in Payload within RedResponse. + @retval EFI_INVALID_PARAMETER RedfishService, Uri, or RedResponse is N= ULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error oc= curred. Callers can get + more error info from returned HTTP Statu= sCode, Headers and Payload + within RedResponse: + 1. If the returned StatusCode is NULL, i= ndicates any error happen. + 2. If the returned StatusCode is not NUL= L and the value is not 2XX, + indicates any error happen. +**/ +EFI_STATUS +EFIAPI +RedfishDeleteByUriEx ( + IN REDFISH_SERVICE RedfishService, + IN CONST CHAR8 *Uri, + IN CONST CHAR8 *Content, + OUT REDFISH_RESPONSE *RedResponse + ) +{ + EFI_STATUS Status; + EDKII_JSON_VALUE JsonValue; + + Status =3D EFI_SUCCESS; + JsonValue =3D NULL; + + if ((RedfishService =3D=3D NULL) || (Content =3D=3D NULL) || (Uri =3D=3D= NULL) || (RedResponse =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE)); + + JsonValue =3D (EDKII_JSON_VALUE)deleteUriFromServiceEx ( + RedfishService, + Uri, + Content, + &(RedResponse->StatusCode) + ); + + // + // 1. If the returned StatusCode is NULL, indicates any error happen. + // + if (RedResponse->StatusCode =3D=3D NULL) { + Status =3D EFI_DEVICE_ERROR; + goto ON_EXIT; + } + + // + // 2. If the returned StatusCode is not NULL and the value is not 2XX, i= ndicates any error happen. + // NOTE: If there is any error message returned from server, it will = be returned in + // Payload within RedResponse. + // + if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \ + (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)) + { + Status =3D EFI_DEVICE_ERROR; + } + +ON_EXIT: + if (JsonValue !=3D NULL) { + RedResponse->Payload =3D createRedfishPayload (JsonValue, RedfishServi= ce); + if (RedResponse->Payload =3D=3D NULL) { + // + // Ignore the error when create RedfishPayload, just free the JsonVa= lue since it's not what + // we care about if the returned StatusCode is 2XX. + // + JsonValueFree (JsonValue); + } + } + + return Status; +} + /** Dump text in fractions. diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/re= dfishService.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/includ= e/redfishService.h index 5c13b68..75afadc 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishSe= rvice.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishSe= rvice.h @@ -129,6 +129,14 @@ deleteUriFromService ( EFI_HTTP_STATUS_CODE **StatusCode ); +json_t * +deleteUriFromServiceEx ( + redfishService *service, + const char *uri, + const char *content, + EFI_HTTP_STATUS_CODE **StatusCode + ); + redfishPayload * getRedfishServiceRoot ( redfishService *service, diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/servic= e.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c index afa172b..086e04a 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c @@ -923,10 +923,12 @@ ON_EXIT: return ret; } + json_t * -deleteUriFromService ( +deleteUriFromServiceEx ( redfishService *service, const char *uri, + const char *content, EFI_HTTP_STATUS_CODE **StatusCode ) { @@ -937,6 +939,8 @@ deleteUriFromService ( EFI_HTTP_REQUEST_DATA *RequestData =3D NULL; EFI_HTTP_MESSAGE *RequestMsg =3D NULL; EFI_HTTP_MESSAGE ResponseMsg; + CHAR8 ContentLengthStr[80]; + size_t contentLength; ret =3D NULL; @@ -956,7 +960,7 @@ deleteUriFromService ( // // Step 1: Create HTTP request message with 4 headers: // - HttpIoHeader =3D HttpIoCreateHeader ((service->sessionToken || service->= basicAuthStr) ? 5 : 4); + HttpIoHeader =3D HttpIoCreateHeader ((service->sessionToken || service->= basicAuthStr) ? 8 : 7); if (HttpIoHeader =3D=3D NULL) { ret =3D NULL; goto ON_EXIT; @@ -979,6 +983,23 @@ deleteUriFromService ( Status =3D HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive"); ASSERT_EFI_ERROR (Status); + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/j= son"); + ASSERT_EFI_ERROR (Status); + + if(content !=3D NULL){ + contentLength =3D strlen (content); + AsciiSPrint ( + ContentLengthStr, + sizeof (ContentLengthStr), + "%lu", + (UINT64)contentLength + ); + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentL= engthStr); + ASSERT_EFI_ERROR (Status); + Status =3D HttpIoSetHeader (HttpIoHeader, "OData-Version", "4.0"); + ASSERT_EFI_ERROR (Status); + } + // // Step 2: build the rest of HTTP request info. // @@ -1004,6 +1025,11 @@ deleteUriFromService ( RequestMsg->HeaderCount =3D HttpIoHeader->HeaderCount; RequestMsg->Headers =3D HttpIoHeader->Headers; + if(content !=3D NULL){ + RequestMsg->BodyLength =3D contentLength; + RequestMsg->Body =3D (VOID *)content; + } + ZeroMem (&ResponseMsg, sizeof (ResponseMsg)); // @@ -1057,6 +1083,17 @@ ON_EXIT: return ret; } +json_t * +deleteUriFromService ( + redfishService *service, + const char *uri, + EFI_HTTP_STATUS_CODE **StatusCode + ) +{ + return deleteUriFromServiceEx(service, uri, NULL, StatusCode); +} + + redfishPayload * getRedfishServiceRoot ( redfishService *service, -- 2.6.1.windows.1 -The information contained in this message may be confidential and propriet= ary to American Megatrends (AMI). This communication is intended to be read= only by the individual or entity to whom it is addressed or by their desig= nee. If the reader of this message is not the intended recipient, you are o= n notice that any distribution of this message, in any form, is strictly pr= ohibited. Please promptly notify the sender by reply e-mail or by telephone= at 770-246-8600, and then delete or destroy all copies of the transmission= .