From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 20B89740052 for ; Thu, 26 Oct 2023 06:09:43 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PZWnhW8kr1751v5RxP2EtSmygV6xHH77hHKFq6XQywI=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1698300582; v=1; b=f0TbzUd8IuePDtw8vqhtQXgjuMzWTP0+n7nHvwGfF3grSre3KnjAeZU4eurBkM12VS+mAOgB 6DPa9w+elMQ22HvewABH/h4NjhZiJHlVDMdrfSFARtatMJOXRikWPjaHKeZbASZ7aEXQK1DQSrC Ki7y6Ju7qMLD+ofHFT5Mhhyk= X-Received: by 127.0.0.2 with SMTP id wAQgYY7687511xp2J97Wa4O6; Wed, 25 Oct 2023 23:09:42 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.76]) by mx.groups.io with SMTP id smtpd.web11.64350.1698300576973000190 for ; Wed, 25 Oct 2023 23:09:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K3ZvO35L6piLTfndNxypVhbzqTp875T/2+fnEashkDYafXQifbQ2JtY8lmK0HdDngjVgCrbB3i6+2kElByjUdzd7omD8UIxRpHQfp/bXArUjhfKo/JlErIwrZZrWVrG+mJgY+K37LHH44qXgn35JxQ9BaMN4bTa5pfw0O4FOpaH0GCKHrgU+vwIlvn9KFBLqn6/6z+jomxrc8zq4LEjIBK4o8rPUqJOf/lNr3dJjJlsZsDBtbXShl7l654sgL/+3JEj/kqGE00HYtqd9vxn028y5FCyFPK1yyb4eszR2Yea+99Wc3s/rNG/E0Ptx1Ufs16Sg0KpPWJdt3Z4vsNcCDA== 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=nki25ULIKiZtaUJY2/njJYlIpJ31FSiZqBIqG12KIrg=; b=XZEI4LCpxX3IWcPtg2MpAh7Qjr3viUwjl6aioZBoO2ZezqIHFeXo4WE5UTJcoKOYVF5YGd5G/DwFkxS6kQMITrXwhK3Phao3HnOEmhkHf7bbdcdGgba/egCU2n9ksHk0+JCNAYjzS/0EhmEwQvWX34La6mDRnB2AXDaEaI+9KF6lPvx1vwbNQEZvPFHLoIXE/q6KsEfEY1NXvr0l1ptIYM0WYqhI2hgEdlwn4y8e8uFyO4lOi7gJ3ZvIkRxUF+QgwHL9xLkx2WvvozLJEzSh26yf6EKW2UTgWQ4lAbOiYjM6WGnspvQ+xyH0CnlNYfSH6S8Rce4aj9Xn99AUBpO+nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by SA1PR12MB7245.namprd12.prod.outlook.com (2603:10b6:806:2bf::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.29; Thu, 26 Oct 2023 06:09:34 +0000 X-Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::e670:e45f:fa32:2420]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::e670:e45f:fa32:2420%6]) with mapi id 15.20.6933.019; Thu, 26 Oct 2023 06:09:33 +0000 From: "Chang, Abner via groups.io" To: Nickle Wang , "devel@edk2.groups.io" CC: Igor Kulchytskyy , Nick Ramirez Subject: Re: [edk2-devel] [PATCH 2/3] RedfishPkg/libredfish: introduce new interfaces. Thread-Topic: [PATCH 2/3] RedfishPkg/libredfish: introduce new interfaces. Thread-Index: AQHaBlWaleMWLF7R30+KjtclRImMeLBbmUug Date: Thu, 26 Oct 2023 06:09:33 +0000 Message-ID: References: <20231024083906.16121-1-nicklew@nvidia.com> In-Reply-To: <20231024083906.16121-1-nicklew@nvidia.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=bc95f1ea-e11f-40b0-9eef-7666ccc77a45;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=0;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2023-10-26T06:09:30Z;MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|SA1PR12MB7245:EE_ x-ms-office365-filtering-correlation-id: 749253a8-3f4b-479a-178f-08dbd5ea1ff5 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: jewstBWKzddsejGKc/X8P3jQ67PUTx6e55JkIe6NEj0/ClfTKPVHazafp3IRM4YlWFHEjf/Rco7Y9CP/kT3wJBSc3nSXixbP+SQKZgiwVCyVCnM3qj2ELBOnhjNJkZca0Vt8QggOYLL04hnmXkIoUjHaB4j+IVgikTYd5Rc55vcOY0xATuS8RQwWA/UNXHbnJ9JUhc6rqgv1y4GaCBYmDr7BOBvXm+TjSNLmUbz87vw3fJTOZ8sY0RgtTJOJPZESIYE6Oj+k74zCSi2n5jFZPNt0F9e+ftflcONrUXcuCvkFAUKBCkh9en7qGSM7R5h36OdmzuX2QN++zSzJRPwHVU1OueSyRdU8EYTNWrbZysWEOHDclJAajX8cf6ZPvjutJuyVU9OfvZu5PpSD/jfTEMkYXWZGOEdJHjdBTPRKJkgjLFuS8CP1pFUhMStOlNQFF/XYq+OVS/iLHLIwTk97D+x52C1ey0D4KcO+ehwtZcLcuyWx5L+f+vP7VuRwU2uKgOK6Ys8wX14shxP8cHQWKJmFN575XAS8CqCqfnqne4ATEKOEMw/O4W937KFzupuYtq8CwbizcCAMQiG8oiOqmoz/7uEzawLpNpHZX2Gk0EcqeB2ecJgPYU212eOh2y/0 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?LRoK4qvII2JW+8sELhUJq/rrhnyRSAIt+7Y4AbGdOOiZf3lC6cZ5DQOF+RnM?= =?us-ascii?Q?hYjBg04VvDxUizQBOdoItK7b6Js4xadOSgW9Dw1FVKVeu6ZxqYa6lheV2hb9?= =?us-ascii?Q?dvIWNMsef+EXiojAt/YxfFJDtnnvsq4IGLNil45kbsHWz+2E93eb6ApN5Omh?= =?us-ascii?Q?SovbwP9HRijSd1bQ2+RhtM3AHAQPuqdeH10k0ms0tlfi1OpPiCMxg7QiEocT?= =?us-ascii?Q?PXTeqcgLAWdfW+RuFC4VQCaG2GyvBUSmuLc89IxN2yOtqpDAZZNOzlx53/xv?= =?us-ascii?Q?VAy/yImjE5NCIdqJg++4kUDQ1Dlu6PTKlsaSLNjh+f904ou5ed7gyblKkP0p?= =?us-ascii?Q?RK5dVF1TdZLzLe6iRxJuf6RqgXluFBJJqoCC9mEPVCGfGkOJ2SQItdkxGbwL?= =?us-ascii?Q?LDbFJMASy1OUfiTGToKIrzmmnMmgqaNCw0VB294FHeKT5en5yGO8a1cc2THZ?= =?us-ascii?Q?lGBB45IxPWQ3Gv8CnWoLXhwRjEW4fINXKfORU3QcUzdqRMevydl637O/4anq?= =?us-ascii?Q?9OrCaYV68j8NywbSc8dHrJrGbp9aDGNbVXA3f1yDVjbtO/RItXh4GsgSboa9?= =?us-ascii?Q?nXEvcTaqBAdaxggIGcvLIDnRG5fw6xXmkw8obHjGDzRJ3p5XltG7cw4Fd98D?= =?us-ascii?Q?X765+MbkblBvjJALhd36EqGglRj8mLE2HSDk+25T52wQs244utX5hIVH8r3C?= =?us-ascii?Q?+JcK7VnRhA6NueHYSl0btHi15Y4PJz9PRCJQANB1cBHcmJs8++2v7HSAq1aQ?= =?us-ascii?Q?GuYtTXADEPkPndgJ7Qo/h+iLzVnIYAxoHIiwuBAMRfNa25hpebQ4HMwWkKq8?= =?us-ascii?Q?nXFH2GjMnyh8MefGjmQQMeK+iu6jAHisxDkpdqFbW0kIHG9D+sjx7CfeOrfQ?= =?us-ascii?Q?+ayfHpktNv6IULNl4gVRYtSve1MgkqUpOaT0H/qr93u1I1jpypZ+CEOGAWnx?= =?us-ascii?Q?oxb0jdfIxexiR+NjvJw2n7wxDw3QzCIBm9d8nEu/GaxRr/QBmW4Ua2cggSvx?= =?us-ascii?Q?+vJqthsridcxwwmICLlR4qiU3ZbtBa9IaYq8+79shpjXTTVutkXplJ50MsMK?= =?us-ascii?Q?SZnDccv9fGAVWrBg+YxMYgD8Bc2g+DaDWI+Fesk1siEYEBcGKDvN38qAwuM7?= =?us-ascii?Q?cr0MO5yudagBv9siVxP6785hYi/yiTDao1iPtdoP5XexRTpuWONFm5FmP1Rb?= =?us-ascii?Q?JdWPOIMAtTiWMiaAlJ2/kxDFivLwf01tQwiA1f+5EHDKSa0YBa8V+P+inFfz?= =?us-ascii?Q?1CcSsE04pil1xX8kwUGa6IUCkTtsw+zsxFWuCWbdJG9ld9LonpEjaiTLe7KF?= =?us-ascii?Q?Ni3XuIVnOTLnwt/11ulknSw0+5BAc6Lv4QuVHDCjThQuzD/6BtJT/Sl+3DsG?= =?us-ascii?Q?PaS2jG72IxBynaySLEE/8xLnTJ1gY8ET3riCjD5TdnMmnR/SK2MKSFEg7lZ3?= =?us-ascii?Q?bF8nWE51UrkFKvLE6c+KT9X47BoGWqTPUHW0HypBBkRk/peOOAVoHqGbTtxb?= =?us-ascii?Q?pOUSp89r2WNqBH1PPDDeFHjmSPVMLNEhNWINZ0Yp4MzVS0dnV+BwbC4CjYa/?= =?us-ascii?Q?h3qgnVp0MsNqeqGO1tIvJfvVb0GHWtXH6J3B2ecf?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 749253a8-3f4b-479a-178f-08dbd5ea1ff5 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Oct 2023 06:09:33.8169 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: GMtIxWQpNa1bZjGqi6C2KpdWzHG79JHPxwdR+swz53IiiZE6ICPct3jc/zg9CNR6ocPUrklCC2WQrfCPSKOIaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7245 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: LeCgJpUbm9BPEhcH86RjevC6x7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=f0TbzUd8; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") [AMD Official Use Only - General] Reviewed-by: Abner Chang > -----Original Message----- > From: Nickle Wang > Sent: Tuesday, October 24, 2023 4:39 PM > To: devel@edk2.groups.io > Cc: Chang, Abner ; Igor Kulchytskyy > ; Nick Ramirez > Subject: [PATCH 2/3] RedfishPkg/libredfish: introduce new interfaces. > > Caution: This message originated from an External Source. Use proper caut= ion > when opening attachments, clicking links, or responding. > > > - Add new interfaces to return HTTP headers back to caller. > New interfaces are: getUriFromServiceEx(), patchUriFromServiceEx(), > postUriFromServiceEx() and putUriFromServiceEx(). > - Fix compile error in payload.c > > Signed-off-by: Nickle Wang > Cc: Abner Chang > Cc: Igor Kulchytskyy > Cc: Nick Ramirez > --- > .../edk2libredfish/include/redfishPayload.h | 3 +- > .../edk2libredfish/include/redfishService.h | 44 +++ > .../RedfishLib/edk2libredfish/src/payload.c | 3 +- > .../RedfishLib/edk2libredfish/src/service.c | 369 ++++++++++++++++-- > 4 files changed, 394 insertions(+), 25 deletions(-) > > diff --git > a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayl= oa > d.h > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayl= oa > d.h > index 445153060a2a..25bd0b548192 100644 > --- > a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayl= oa > d.h > +++ > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayl= oa > d.h > @@ -10,6 +10,7 @@ > > Copyright (c) 2019, Intel Corporation. All rights reserved.
> (C) Copyright 2021 Hewlett Packard Enterprise Development LP
> + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights > reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -19,7 +20,7 @@ > #define LIBREDFISH_REDFISH_PAYLOAD_H_ > > #include > - > +#include > #include > #include > #include > diff --git > a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishServ= ice > .h > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishServ= ice > .h > index 75afadc0cece..30f839ea2e8e 100644 > --- > a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishServ= ice > .h > +++ > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishServ= ice > .h > @@ -10,6 +10,7 @@ > > Copyright (c) 2019, Intel Corporation. All rights reserved.
> (C) Copyright 2021 Hewlett Packard Enterprise Development LP
> + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights > reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -104,6 +105,15 @@ getUriFromService ( > EFI_HTTP_STATUS_CODE **StatusCode > ); > > +json_t * > +getUriFromServiceEx ( > + redfishService *service, > + const char *uri, > + EFI_HTTP_HEADER **Headers, > + UINTN *HeaderCount, > + EFI_HTTP_STATUS_CODE **StatusCode > + ); > + > json_t * > patchUriFromService ( > redfishService *service, > @@ -112,6 +122,16 @@ patchUriFromService ( > EFI_HTTP_STATUS_CODE **StatusCode > ); > > +json_t * > +patchUriFromServiceEx ( > + redfishService *service, > + const char *uri, > + const char *content, > + EFI_HTTP_HEADER **Headers, > + UINTN *HeaderCount, > + EFI_HTTP_STATUS_CODE **StatusCode > + ); > + > json_t * > postUriFromService ( > redfishService *service, > @@ -122,6 +142,30 @@ postUriFromService ( > EFI_HTTP_STATUS_CODE **StatusCode > ); > > +json_t * > +postUriFromServiceEx ( > + redfishService *service, > + const char *uri, > + const char *content, > + size_t contentLength, > + const char *contentType, > + EFI_HTTP_HEADER **Headers, > + UINTN *HeaderCount, > + EFI_HTTP_STATUS_CODE **StatusCode > + ); > + > +json_t * > +putUriFromServiceEx ( > + redfishService *service, > + const char *uri, > + const char *content, > + size_t contentLength, > + const char *contentType, > + EFI_HTTP_HEADER **Headers, > + UINTN *HeaderCount, > + EFI_HTTP_STATUS_CODE **StatusCode > + ); > + > json_t * > deleteUriFromService ( > redfishService *service, > diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payl= oad.c > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c > index 6c6e2246abe3..8fb24a5928a3 100644 > --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c > +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c > @@ -10,6 +10,7 @@ > > Copyright (c) 2019, Intel Corporation. All rights reserved.
> (C) Copyright 2021 Hewlett Packard Enterprise Development LP
> + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights > reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -524,7 +525,7 @@ getOpResult ( > } > > stringProp =3D prop->json; > - jsonType =3D prop->json->type; > + jsonType =3D JsonGetType (prop->json); > switch (jsonType) { > case JSON_OBJECT: > stringProp =3D json_object_get (prop->json, propName); > diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/serv= ice.c > b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c > index 286f298e6a35..3377b431f8a5 100644 > --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c > +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c > @@ -10,6 +10,7 @@ > > Copyright (c) 2019, Intel Corporation. All rights reserved.
> (C) Copyright 2021 Hewlett Packard Enterprise Development LP
> + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights > reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -401,10 +402,41 @@ ON_EXIT: > return ret; > } > > +EFI_HTTP_HEADER * > +cloneHttpHeaders ( > + EFI_HTTP_MESSAGE *message, > + UINTN *HeaderCount > + ) > +{ > + EFI_HTTP_HEADER *Buffer; > + UINTN Index; > + > + if ((message =3D=3D NULL) || (HeaderCount =3D=3D NULL)) { > + return NULL; > + } > + > + *HeaderCount =3D message->HeaderCount; > + Buffer =3D AllocatePool (sizeof (EFI_HTTP_HEADER) * message- > >HeaderCount); > + if (Buffer =3D=3D NULL) { > + return NULL; > + } > + > + for (Index =3D 0; Index < message->HeaderCount; Index++) { > + Buffer[Index].FieldName =3D AllocateCopyPool (AsciiStrSize (message- > >Headers[Index].FieldName), message->Headers[Index].FieldName); > + ASSERT (Buffer[Index].FieldName !=3D NULL); > + Buffer[Index].FieldValue =3D AllocateCopyPool (AsciiStrSize (message= - > >Headers[Index].FieldValue), message->Headers[Index].FieldValue); > + ASSERT (Buffer[Index].FieldValue !=3D NULL); > + } > + > + return Buffer; > +} > + > json_t * > -getUriFromService ( > +getUriFromServiceEx ( > redfishService *service, > const char *uri, > + EFI_HTTP_HEADER **Headers OPTIONAL, > + UINTN *HeaderCount OPTIONAL, > EFI_HTTP_STATUS_CODE **StatusCode > ) > { > @@ -422,13 +454,20 @@ getUriFromService ( > } > > *StatusCode =3D NULL; > + if (HeaderCount !=3D NULL) { > + *HeaderCount =3D 0; > + } > + > + if (Headers !=3D NULL) { > + *Headers =3D NULL; > + } > > url =3D makeUrlForService (service, uri); > if (!url) { > return NULL; > } > > - DEBUG ((DEBUG_MANAGEABILITY, "libredfish: getUriFromService(): %a\n", > url)); > + DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url)); > > // > // Step 1: Create HTTP request message with 4 headers: > @@ -491,6 +530,23 @@ getUriFromService ( > Status =3D service->RestEx->SendReceive (service->RestEx, RequestMsg, > &ResponseMsg); > if (EFI_ERROR (Status)) { > ret =3D NULL; > + > + // > + // Deliver status code to caller when error happens so caller can do= error > handling. > + // > + if (ResponseMsg.Data.Response !=3D NULL) { > + *StatusCode =3D AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE)); > + if (*StatusCode =3D=3D NULL) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + // > + // The caller shall take the responsibility to free the buffer. > + // > + **StatusCode =3D ResponseMsg.Data.Response->StatusCode; > + } > + > goto ON_EXIT; > } > > @@ -510,6 +566,10 @@ getUriFromService ( > **StatusCode =3D ResponseMsg.Data.Response->StatusCode; > } > > + if ((ResponseMsg.Headers !=3D NULL) && (Headers !=3D NULL) && > (HeaderCount !=3D NULL)) { > + *Headers =3D cloneHttpHeaders (&ResponseMsg, HeaderCount); > + } > + > if ((ResponseMsg.BodyLength !=3D 0) && (ResponseMsg.Body !=3D NULL)) { > // > // Check if data is encoded. > @@ -558,10 +618,14 @@ ON_EXIT: > } > > json_t * > -patchUriFromService ( > +putUriFromServiceEx ( > redfishService *service, > const char *uri, > const char *content, > + size_t contentLength, > + const char *contentType, > + EFI_HTTP_HEADER **Headers OPTIONAL, > + UINTN *HeaderCount OPTIONAL, > EFI_HTTP_STATUS_CODE **StatusCode > ) > { > @@ -581,13 +645,224 @@ patchUriFromService ( > } > > *StatusCode =3D NULL; > + if (HeaderCount !=3D NULL) { > + *HeaderCount =3D 0; > + } > + > + if (Headers !=3D NULL) { > + *Headers =3D NULL; > + } > + > + url =3D makeUrlForService (service, uri); > + if (url =3D=3D NULL) { > + return NULL; > + } > + > + DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url)); > + > + if (contentLength =3D=3D 0) { > + contentLength =3D strlen (content); > + } > + > + // > + // Step 1: Create HTTP request message with 4 headers: > + // > + HttpIoHeader =3D HttpIoCreateHeader ((service->sessionToken !=3D NULL = || > service->basicAuthStr !=3D NULL) ? 9 : 8); > + if (HttpIoHeader =3D=3D NULL) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + if (service->sessionToken) { > + Status =3D HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service- > >sessionToken); > + ASSERT_EFI_ERROR (Status); > + } else if (service->basicAuthStr) { > + Status =3D HttpIoSetHeader (HttpIoHeader, "Authorization", service- > >basicAuthStr); > + ASSERT_EFI_ERROR (Status); > + } > + > + if (contentType =3D=3D NULL) { > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Type", > "application/json"); > + ASSERT_EFI_ERROR (Status); > + } else { > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 > *)contentType); > + ASSERT_EFI_ERROR (Status); > + } > + > + Status =3D HttpIoSetHeader (HttpIoHeader, "Host", service- > >HostHeaderValue); > + ASSERT_EFI_ERROR (Status); > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Type", > "application/json"); > + ASSERT_EFI_ERROR (Status); > + Status =3D HttpIoSetHeader (HttpIoHeader, "Accept", "application/json"= ); > + ASSERT_EFI_ERROR (Status); > + Status =3D HttpIoSetHeader (HttpIoHeader, "User-Agent", "libredfish"); > + ASSERT_EFI_ERROR (Status); > + Status =3D HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive"); > + ASSERT_EFI_ERROR (Status); > + > + AsciiSPrint ( > + ContentLengthStr, > + sizeof (ContentLengthStr), > + "%lu", > + (UINT64)contentLength > + ); > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Length", > ContentLengthStr); > + 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. > + // > + RequestData =3D AllocateZeroPool (sizeof (EFI_HTTP_REQUEST_DATA)); > + if (RequestData =3D=3D NULL) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + RequestData->Method =3D HttpMethodPut; > + RequestData->Url =3D C8ToC16 (url); > + > + // > + // Step 3: fill in EFI_HTTP_MESSAGE > + // > + RequestMsg =3D AllocateZeroPool (sizeof (EFI_HTTP_MESSAGE)); > + if (RequestMsg =3D=3D NULL) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + EncodedContent =3D (CHAR8 *)content; > + EncodedContentLen =3D contentLength; > + // > + // We currently only support gzip Content-Encoding. > + // > + Status =3D EncodeRequestContent ((CHAR8 > *)HTTP_CONTENT_ENCODING_GZIP, (CHAR8 *)content, (VOID > **)&EncodedContent, &EncodedContentLen); > + if (Status =3D=3D EFI_INVALID_PARAMETER) { > + DEBUG ((DEBUG_ERROR, "%a: Error to encode content.\n", __func__)); > + ret =3D NULL; > + goto ON_EXIT; > + } else if (Status =3D=3D EFI_UNSUPPORTED) { > + DEBUG ((DEBUG_MANAGEABILITY, "No content coding for %a! Use raw > data instead.\n", HTTP_CONTENT_ENCODING_GZIP)); > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Encoding", > HTTP_CONTENT_ENCODING_IDENTITY); > + ASSERT_EFI_ERROR (Status); > + } else { > + Status =3D HttpIoSetHeader (HttpIoHeader, "Content-Encoding", > HTTP_CONTENT_ENCODING_GZIP); > + ASSERT_EFI_ERROR (Status); > + } > + > + RequestMsg->Data.Request =3D RequestData; > + RequestMsg->HeaderCount =3D HttpIoHeader->HeaderCount; > + RequestMsg->Headers =3D HttpIoHeader->Headers; > + RequestMsg->BodyLength =3D EncodedContentLen; > + RequestMsg->Body =3D (VOID *)EncodedContent; > + > + ZeroMem (&ResponseMsg, sizeof (ResponseMsg)); > + > + // > + // Step 4: call RESTEx to get response from REST service. > + // > + Status =3D service->RestEx->SendReceive (service->RestEx, RequestMsg, > &ResponseMsg); > + if (EFI_ERROR (Status)) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + // > + // Step 5: Return the HTTP StatusCode and Body message. > + // > + if (ResponseMsg.Data.Response !=3D NULL) { > + *StatusCode =3D AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE)); > + if (*StatusCode =3D=3D NULL) { > + ret =3D NULL; > + goto ON_EXIT; > + } > + > + // > + // The caller shall take the responsibility to free the buffer. > + // > + **StatusCode =3D ResponseMsg.Data.Response->StatusCode; > + } > + > + if ((ResponseMsg.Headers !=3D NULL) && (Headers !=3D NULL) && > (HeaderCount !=3D NULL)) { > + *Headers =3D cloneHttpHeaders (&ResponseMsg, HeaderCount); > + } > + > + if (EncodedContent !=3D content) { > + FreePool (EncodedContent); > + } > + > + if ((ResponseMsg.BodyLength !=3D 0) && (ResponseMsg.Body !=3D NULL)) { > + ret =3D json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, > NULL); > + } else { > + // > + // There is no message body returned from server. > + // > + ret =3D NULL; > + } > + > +ON_EXIT: > + if (url !=3D NULL) { > + free (url); > + } > + > + if (HttpIoHeader !=3D NULL) { > + HttpIoFreeHeader (HttpIoHeader); > + } > + > + if (RequestData !=3D NULL) { > + RestConfigFreeHttpRequestData (RequestData); > + } > + > + if (RequestMsg !=3D NULL) { > + FreePool (RequestMsg); > + } > + > + RestConfigFreeHttpMessage (&ResponseMsg, FALSE); > + > + return ret; > +} > + > +json_t * > +patchUriFromServiceEx ( > + redfishService *service, > + const char *uri, > + const char *content, > + EFI_HTTP_HEADER **Headers OPTIONAL, > + UINTN *HeaderCount OPTIONAL, > + EFI_HTTP_STATUS_CODE **StatusCode > + ) > +{ > + char *url; > + json_t *ret; > + HTTP_IO_HEADER *HttpIoHeader =3D NULL; > + EFI_STATUS Status; > + EFI_HTTP_REQUEST_DATA *RequestData =3D NULL; > + EFI_HTTP_MESSAGE *RequestMsg =3D NULL; > + EFI_HTTP_MESSAGE ResponseMsg; > + CHAR8 ContentLengthStr[80]; > + CHAR8 *EncodedContent; > + UINTN EncodedContentLen; > + > + if ((service =3D=3D NULL) || (uri =3D=3D NULL) || (content =3D=3D NULL= ) || (StatusCode =3D=3D > NULL)) { > + return NULL; > + } > + > + *StatusCode =3D NULL; > + if (HeaderCount !=3D NULL) { > + *HeaderCount =3D 0; > + } > + > + if (Headers !=3D NULL) { > + *Headers =3D NULL; > + } > > url =3D makeUrlForService (service, uri); > if (!url) { > return NULL; > } > > - DEBUG ((DEBUG_MANAGEABILITY, "libredfish: patchUriFromService(): > %a\n", url)); > + DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url)); > > // > // Step 1: Create HTTP request message with 4 headers: > @@ -701,6 +976,10 @@ patchUriFromService ( > **StatusCode =3D ResponseMsg.Data.Response->StatusCode; > } > > + if ((ResponseMsg.Headers !=3D NULL) && (Headers !=3D NULL) && > (HeaderCount !=3D NULL)) { > + *Headers =3D cloneHttpHeaders (&ResponseMsg, HeaderCount); > + } > + > if (EncodedContent !=3D content) { > FreePool (EncodedContent); > } > @@ -737,12 +1016,14 @@ ON_EXIT: > } > > json_t * > -postUriFromService ( > +postUriFromServiceEx ( > redfishService *service, > const char *uri, > const char *content, > size_t contentLength, > const char *contentType, > + EFI_HTTP_HEADER **Headers OPTIONAL, > + UINTN *HeaderCount OPTIONAL, > EFI_HTTP_STATUS_CODE **StatusCode > ) > { > @@ -763,13 +1044,20 @@ postUriFromService ( > } > > *StatusCode =3D NULL; > + if (HeaderCount !=3D NULL) { > + *HeaderCount =3D 0; > + } > + > + if (Headers !=3D NULL) { > + *Headers =3D NULL; > + } > > url =3D makeUrlForService (service, uri); > if (!url) { > return NULL; > } > > - DEBUG ((DEBUG_MANAGEABILITY, "libredfish: postUriFromService(): > %a\n", url)); > + DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url)); > > if (contentLength =3D=3D 0) { > contentLength =3D strlen (content); > @@ -850,7 +1138,12 @@ postUriFromService ( > // > Status =3D service->RestEx->SendReceive (service->RestEx, RequestMsg, > &ResponseMsg); > if (EFI_ERROR (Status)) { > - goto ON_EXIT; > + // > + // If there is no response to handle, go to error exit. > + // > + if (ResponseMsg.Data.Response =3D=3D NULL) { > + goto ON_EXIT; > + } > } > > // > @@ -868,15 +1161,20 @@ postUriFromService ( > **StatusCode =3D ResponseMsg.Data.Response->StatusCode; > } > > + if ((ResponseMsg.Headers !=3D NULL) && (Headers !=3D NULL) && > (HeaderCount !=3D NULL)) { > + *Headers =3D cloneHttpHeaders (&ResponseMsg, HeaderCount); > + } > + > if ((ResponseMsg.BodyLength !=3D 0) && (ResponseMsg.Body !=3D NULL)) { > ret =3D json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NUL= L); > } > > // > - // Step 6: Parsing the HttpHeader to retrive the X-Auth-Token if the H= TTP > StatusCode is correct. > + // Step 6: Parsing the HttpHeader to retrieve the X-Auth-Token if the = HTTP > StatusCode is correct. > // > - if ((ResponseMsg.Data.Response->StatusCode =3D=3D HTTP_STATUS_200_OK) > || > - (ResponseMsg.Data.Response->StatusCode =3D=3D > HTTP_STATUS_204_NO_CONTENT)) > + if ((ResponseMsg.Data.Response !=3D NULL) && > + ((ResponseMsg.Data.Response->StatusCode =3D=3D HTTP_STATUS_200_OK) > || > + (ResponseMsg.Data.Response->StatusCode =3D=3D > HTTP_STATUS_204_NO_CONTENT))) > { > HttpHeader =3D HttpFindHeader (ResponseMsg.HeaderCount, > ResponseMsg.Headers, "X-Auth-Token"); > if (HttpHeader !=3D NULL) { > @@ -886,19 +1184,6 @@ postUriFromService ( > > service->sessionToken =3D AllocateCopyPool (AsciiStrSize (HttpHead= er- > >FieldValue), HttpHeader->FieldValue); > } > - > - /* > - // > - // Below opeation seems to be unnecessary. > - // Besides, the FieldValue for the Location is the full HTTP URI > (Http://0.0.0.0:5000/XXX), so we can't use it as the > - // parameter of getUriFromService () directly. > - // > - HttpHeader =3D HttpFindHeader (ResponseMsg.HeaderCount, > ResponseMsg.Headers, "Location"); > - if (HttpHeader !=3D NULL) { > - ret =3D getUriFromService(service, HttpHeader->FieldValue); > - goto ON_EXIT; > - } > - */ > } > > ON_EXIT: > @@ -923,6 +1208,40 @@ ON_EXIT: > return ret; > } > > +json_t * > +getUriFromService ( > + redfishService *service, > + const char *uri, > + EFI_HTTP_STATUS_CODE **StatusCode > + ) > +{ > + return getUriFromServiceEx (service, uri, NULL, NULL, StatusCode); > +} > + > +json_t * > +patchUriFromService ( > + redfishService *service, > + const char *uri, > + const char *content, > + EFI_HTTP_STATUS_CODE **StatusCode > + ) > +{ > + return patchUriFromServiceEx (service, uri, content, NULL, NULL, > StatusCode); > +} > + > +json_t * > +postUriFromService ( > + redfishService *service, > + const char *uri, > + const char *content, > + size_t contentLength, > + const char *contentType, > + EFI_HTTP_STATUS_CODE **StatusCode > + ) > +{ > + return postUriFromServiceEx (service, uri, content, contentLength, > contentType, NULL, NULL, StatusCode); > +} > + > json_t * > deleteUriFromServiceEx ( > redfishService *service, > @@ -1498,6 +1817,10 @@ makeUrlForService ( > } > > url =3D (char *)malloc (strlen (service->host)+strlen (uri)+1); > + if (url =3D=3D NULL) { > + return NULL; > + } > + > strcpy (url, service->host); > strcat (url, uri); > return url; > -- > 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110075): https://edk2.groups.io/g/devel/message/110075 Mute This Topic: https://groups.io/mt/102154013/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-