public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces.
@ 2023-10-24  8:38 Nickle Wang via groups.io
  2023-10-26  6:04 ` Chang, Abner via groups.io
  0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang via groups.io @ 2023-10-24  8:38 UTC (permalink / raw)
  To: devel; +Cc: Abner Chang, Igor Kulchytskyy, Nick Ramirez

Add two new interface: RedfishServiceInPayload() and RedfishPutToUri()
for Redfish HTTP protocol implementation. Fix several typos and add
missing JsonLib in INF file.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 .../PrivateLibrary/RedfishLib/RedfishLib.inf  |   2 +
 RedfishPkg/Include/Library/RedfishLib.h       |  95 +++++++++--
 .../PrivateLibrary/RedfishLib/RedfishLib.c    | 153 ++++++++++++++++--
 .../PrivateLibrary/RedfishLib/RedfishMisc.c   |  13 +-
 4 files changed, 226 insertions(+), 37 deletions(-)

diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
index 128d511df7c9..124ecb1e3aae 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
 #  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 #    SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -42,6 +43,7 @@
   BaseLib
   BaseMemoryLib
   DebugLib
+  JsonLib
   HttpLib
   MemoryAllocationLib
   NetLib
diff --git a/RedfishPkg/Include/Library/RedfishLib.h b/RedfishPkg/Include/Library/RedfishLib.h
index 28c2b290e613..8309a67c769f 100644
--- a/RedfishPkg/Include/Library/RedfishLib.h
+++ b/RedfishPkg/Include/Library/RedfishLib.h
@@ -61,6 +61,7 @@
 
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -183,6 +184,23 @@ RedfishJsonInPayload (
   IN REDFISH_PAYLOAD  Payload
   );
 
+/**
+  This function returns the Redfish service of a REDFISH_PAYLOAD.
+
+  Caller doesn't need to free the returned JSON value because it will be released
+  in corresponding RedfishCleanupService() function.
+
+  @param[in]    Payload     A REDFISH_PAYLOAD instance.
+
+  @return     Redfish service of the payload.
+
+**/
+REDFISH_SERVICE
+EFIAPI
+RedfishServiceInPayload (
+  IN REDFISH_PAYLOAD  Payload
+  );
+
 /**
   Fill the input RedPath string with system UUID from SMBIOS table or use the customized
   ID if  FromSmbios == FALSE.
@@ -222,7 +240,7 @@ RedfishBuildPathWithSystemUuid (
                                       from the root node.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The corresponding redfish resource has
                                   been returned in Payload within RedResponse.
   @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or RedResponse is NULL.
@@ -252,7 +270,7 @@ RedfishGetByService (
   @param[in]    URI               String to address a resource.
   @param[out]   RedResponse       Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The corresponding redfish resource has
                                   been returned in Payload within RedResponse.
   @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or RedResponse is NULL.
@@ -282,7 +300,7 @@ RedfishGetByUri (
   @param[in]    RedPath           Relative RedPath string to address a resource inside Payload.
   @param[out]   RedResponse       Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful:
+  @retval EFI_SUCCESS             The operation is successful:
                                   1. The HTTP StatusCode is NULL and the returned Payload in
                                   RedResponse is not NULL, indicates the Redfish resource has
                                   been parsed from the input payload directly.
@@ -323,7 +341,7 @@ RedfishGetByPayload (
   @param[in]    Content               JSON represented properties to be update.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -357,10 +375,10 @@ RedfishPatchToUri (
   redfish response data.
 
   @param[in]    Target           The target payload to be updated.
-  @param[in]    Payload          Palyoad with properties to be changed.
+  @param[in]    Payload          Payload with properties to be changed.
   @param[out]   RedResponse      Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -398,7 +416,7 @@ RedfishPatchToPayload (
   @param[in]    ContentType           Type of the Content to be send to Redfish service
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -416,8 +434,8 @@ RedfishPostToUri (
   IN     REDFISH_SERVICE   RedfishService,
   IN     CONST CHAR8       *Uri,
   IN     CONST CHAR8       *Content,
-  IN     UINTN             ContentSize,
-  IN     CONST CHAR8       *ContentType,
+  IN     UINTN             ContentSize OPTIONAL,
+  IN     CONST CHAR8       *ContentType OPTIONAL,
   OUT    REDFISH_RESPONSE  *RedResponse
   );
 
@@ -436,7 +454,7 @@ RedfishPostToUri (
   @param[in]    Payload         The new resource to be created.
   @param[out]   RedResponse     Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -471,7 +489,7 @@ RedfishPostToPayload (
   @param[in]    Uri                   Relative path to address the resource.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX, the Redfish resource has been removed.
                                   If there is any message returned from server, it will be returned
                                   in Payload within RedResponse.
@@ -507,7 +525,7 @@ RedfishDeleteByUri (
   @param[in]    Content               JSON represented properties to be deleted.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX, the Redfish resource has been removed.
                                   If there is any message returned from server, it will be returned
                                   in Payload within RedResponse.
@@ -528,6 +546,49 @@ RedfishDeleteByUriEx (
   OUT    REDFISH_RESPONSE  *RedResponse
   );
 
+/**
+  Use HTTP PUT to create new Redfish resource in the Resource Collection.
+
+  This function uses the RedfishService to put a Redfish resource addressed by
+  Uri (only the relative path is required). Changes to one or more properties within
+  the target resource are represented in the input Content, properties not specified
+  in Content won't be changed by this request. The corresponding redfish response will
+  returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
+  messages.
+
+  Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
+  redfish response data.
+
+  @param[in]    RedfishService        The Service to access the Redfish resources.
+  @param[in]    Uri                   Relative path to address the resource.
+  @param[in]    Content               JSON represented properties to be update.
+  @param[in]    ContentSize           Size of the Content to be send to Redfish service
+  @param[in]    ContentType           Type of the Content to be send to Redfish service
+  @param[out]   RedResponse           Pointer to the Redfish response data.
+
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
+                                  NULL and the value is 2XX. The Redfish resource 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 RedResponse is NULL.
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. Callers can get
+                                  more error info from returned HTTP StatusCode, Headers and Payload
+                                  within RedResponse:
+                                  1. If the returned StatusCode is NULL, indicates any error happen.
+                                  2. If the returned StatusCode is not NULL and the value is not 2XX,
+                                     indicates any error happen.
+**/
+EFI_STATUS
+EFIAPI
+RedfishPutToUri (
+  IN     REDFISH_SERVICE   RedfishService,
+  IN     CONST CHAR8       *Uri,
+  IN     CONST CHAR8       *Content,
+  IN     UINTN             ContentSize OPTIONAL,
+  IN     CONST CHAR8       *ContentType OPTIONAL,
+  OUT    REDFISH_RESPONSE  *RedResponse
+  );
+
 /**
   Dump text in fractions.
 
@@ -582,7 +643,7 @@ RedfishFreeResponse (
   Check if the "@odata.type" in Payload is valid or not.
 
   @param[in]  Payload                  The Redfish payload to be checked.
-  @param[in]  OdataTypeName            OdataType will be retrived from mapping list.
+  @param[in]  OdataTypeName            OdataType will be retrieved from mapping list.
   @param[in]  OdataTypeMappingList     The list of OdataType.
   @param[in]  OdataTypeMappingListSize The number of mapping list
 
@@ -616,7 +677,7 @@ RedfishIsPayloadCollection (
   @param[in]  Payload         The Redfish collection payload
   @param[in]  CollectionSize  Size of this collection
 
-  @return EFI_SUCCESS              Coolection size is returned in CollectionSize
+  @return EFI_SUCCESS              Collection size is returned in CollectionSize
   @return EFI_INVALID_PARAMETER    The payload is not a collection.
 **/
 EFI_STATUS
@@ -674,18 +735,18 @@ RedfishGetServiceVersion (
 /**
   This function returns the string of Redfish service version.
 
-  @param[in]   ServiceVerisonStr The string of Redfish service version.
+  @param[in]   ServiceVersionStr The string of Redfish service version.
   @param[in]   Url               The URL to build Redpath with ID.
                                  Start with "/", for example "/Registries"
   @param[in]   Id                ID string
-  @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
+  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
                                  the memory allocated for this string.
   @return     EFI_STATUS
 
 **/
 EFI_STATUS
 RedfishBuildRedpathUseId (
-  IN  CHAR8  *ServiceVerisonStr,
+  IN  CHAR8  *ServiceVersionStr,
   IN  CHAR8  *Url,
   IN  CHAR8  *Id,
   OUT CHAR8  **Redpath
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
index cca0ea774893..f4045044829a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
@@ -4,6 +4,7 @@
 
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -167,6 +168,30 @@ RedfishJsonInPayload (
   return ((redfishPayload *)Payload)->json;
 }
 
+/**
+  This function returns the Redfish service of a REDFISH_PAYLOAD.
+
+  Caller doesn't need to free the returned JSON value because it will be released
+  in corresponding RedfishCleanupService() function.
+
+  @param[in]    Payload     A REDFISH_PAYLOAD instance.
+
+  @return     Redfish service of the payload.
+
+**/
+REDFISH_SERVICE
+EFIAPI
+RedfishServiceInPayload (
+  IN REDFISH_PAYLOAD  Payload
+  )
+{
+  if (Payload == NULL) {
+    return NULL;
+  }
+
+  return ((redfishPayload *)Payload)->service;
+}
+
 /**
   Fill the input RedPath string with system UUID from SMBIOS table or use the customized
   ID if  FromSmbios == FALSE.
@@ -244,7 +269,7 @@ RedfishBuildPathWithSystemUuid (
                                       from the root node.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The corresponding redfish resource has
                                   been returned in Payload within RedResponse.
   @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or RedResponse is NULL.
@@ -304,7 +329,7 @@ RedfishGetByService (
   @param[in]    Uri               String to address a resource.
   @param[out]   RedResponse       Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The corresponding redfish resource has
                                   been returned in Payload within RedResponse.
   @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or RedResponse is NULL.
@@ -367,7 +392,7 @@ RedfishGetByUri (
   @param[in]    RedPath           Relative RedPath string to address a resource inside Payload.
   @param[out]   RedResponse       Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful:
+  @retval EFI_SUCCESS             The operation is successful:
                                   1. The HTTP StatusCode is NULL and the returned Payload in
                                   RedResponse is not NULL, indicates the Redfish resource has
                                   been parsed from the input payload directly.
@@ -440,7 +465,7 @@ RedfishGetByPayload (
   @param[in]    Content               JSON represented properties to be update.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -527,10 +552,10 @@ ON_EXIT:
   redfish response data.
 
   @param[in]    Target           The target payload to be updated.
-  @param[in]    Payload          Palyoad with properties to be changed.
+  @param[in]    Payload          Payload with properties to be changed.
   @param[out]   RedResponse      Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -601,7 +626,7 @@ RedfishPatchToPayload (
   @param[in]    ContentType           Type of the Content to be send to Redfish service
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -619,8 +644,8 @@ RedfishPostToUri (
   IN     REDFISH_SERVICE   RedfishService,
   IN     CONST CHAR8       *Uri,
   IN     CONST CHAR8       *Content,
-  IN     UINTN             ContentSize,
-  IN     CONST CHAR8       *ContentType,
+  IN     UINTN             ContentSize OPTIONAL,
+  IN     CONST CHAR8       *ContentType OPTIONAL,
   OUT    REDFISH_RESPONSE  *RedResponse
   )
 {
@@ -694,7 +719,7 @@ ON_EXIT:
   @param[in]    Payload         The new resource to be created.
   @param[out]   RedResponse     Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX. The Redfish resource will be returned
                                   in Payload within RedResponse if server send it back in the HTTP
                                   response message body.
@@ -762,7 +787,7 @@ RedfishPostToPayload (
   @param[in]    Uri                   Relative path to address the resource.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX, the Redfish resource has been removed.
                                   If there is any message returned from server, it will be returned
                                   in Payload within RedResponse.
@@ -850,7 +875,7 @@ ON_EXIT:
   @param[in]    Content               JSON represented properties to be deleted.
   @param[out]   RedResponse           Pointer to the Redfish response data.
 
-  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
                                   NULL and the value is 2XX, the Redfish resource has been removed.
                                   If there is any message returned from server, it will be returned
                                   in Payload within RedResponse.
@@ -1060,7 +1085,7 @@ RedfishFreeResponse (
   Check if the "@odata.type" in Payload is valid or not.
 
   @param[in]  Payload                  The Redfish payload to be checked.
-  @param[in]  OdataTypeName            OdataType will be retrived from mapping list.
+  @param[in]  OdataTypeName            OdataType will be retrieved from mapping list.
   @param[in]  OdataTypeMappingList     The list of OdataType.
   @param[in]  OdataTypeMappingListSize The number of mapping list
 
@@ -1127,7 +1152,7 @@ RedfishIsPayloadCollection (
   @param[in]  Payload         The Redfish collection payload
   @param[in]  CollectionSize  Size of this collection
 
-  @return EFI_SUCCESS              Coolection size is returned in CollectionSize
+  @return EFI_SUCCESS              Collection size is returned in CollectionSize
   @return EFI_INVALID_PARAMETER    The payload is not a collection.
 **/
 EFI_STATUS
@@ -1217,3 +1242,103 @@ RedfishCheckIfRedpathExist (
 
   return EFI_SUCCESS;
 }
+
+/**
+  Use HTTP PUT to create new Redfish resource in the Resource Collection.
+
+  This function uses the RedfishService to put a Redfish resource addressed by
+  Uri (only the relative path is required). Changes to one or more properties within
+  the target resource are represented in the input Content, properties not specified
+  in Content won't be changed by this request. The corresponding redfish response will
+  returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
+  messages.
+
+  Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
+  redfish response data.
+
+  @param[in]    RedfishService        The Service to access the Redfish resources.
+  @param[in]    Uri                   Relative path to address the resource.
+  @param[in]    Content               JSON represented properties to be update.
+  @param[in]    ContentSize           Size of the Content to be send to Redfish service
+  @param[in]    ContentType           Type of the Content to be send to Redfish service
+  @param[out]   RedResponse           Pointer to the Redfish response data.
+
+  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
+                                  NULL and the value is 2XX. The Redfish resource 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 RedResponse is NULL.
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. Callers can get
+                                  more error info from returned HTTP StatusCode, Headers and Payload
+                                  within RedResponse:
+                                  1. If the returned StatusCode is NULL, indicates any error happen.
+                                  2. If the returned StatusCode is not NULL and the value is not 2XX,
+                                     indicates any error happen.
+**/
+EFI_STATUS
+EFIAPI
+RedfishPutToUri (
+  IN     REDFISH_SERVICE   RedfishService,
+  IN     CONST CHAR8       *Uri,
+  IN     CONST CHAR8       *Content,
+  IN     UINTN             ContentSize OPTIONAL,
+  IN     CONST CHAR8       *ContentType OPTIONAL,
+  OUT    REDFISH_RESPONSE  *RedResponse
+  )
+{
+  EFI_STATUS        Status;
+  EDKII_JSON_VALUE  JsonValue;
+
+  Status    = EFI_SUCCESS;
+  JsonValue = NULL;
+
+  if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
+
+  JsonValue = (EDKII_JSON_VALUE)putUriFromServiceEx (
+                                  RedfishService,
+                                  Uri,
+                                  Content,
+                                  ContentSize,
+                                  ContentType,
+                                  &(RedResponse->Headers),
+                                  &(RedResponse->HeaderCount),
+                                  &(RedResponse->StatusCode)
+                                  );
+
+  //
+  // 1. If the returned StatusCode is NULL, indicates any error happen.
+  //
+  if (RedResponse->StatusCode == NULL) {
+    Status = EFI_DEVICE_ERROR;
+    goto ON_EXIT;
+  }
+
+  //
+  // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates 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 = EFI_DEVICE_ERROR;
+  }
+
+ON_EXIT:
+  if (JsonValue != NULL) {
+    RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
+    if (RedResponse->Payload == NULL) {
+      //
+      // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
+      // we care about if the returned StatusCode is 2XX.
+      //
+      JsonValueFree (JsonValue);
+    }
+  }
+
+  return Status;
+}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
index 0eb23196d2c2..b6e9a111785a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
@@ -3,6 +3,7 @@
 
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -168,18 +169,18 @@ RedfishGetAuthInfo (
 /**
   This function returns the string of Redfish service version.
 
-  @param[in]   ServiceVerisonStr The string of Redfish service version.
+  @param[in]   ServiceVersionStr The string of Redfish service version.
   @param[in]   Url               The URL to build Redpath with ID.
                                  Start with "/", for example "/Registries"
   @param[in]   Id                ID string
-  @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
+  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
                                  the memory allocated for this string.
   @return     EFI_STATUS
 
 **/
 EFI_STATUS
 RedfishBuildRedpathUseId (
-  IN  CHAR8  *ServiceVerisonStr,
+  IN  CHAR8  *ServiceVersionStr,
   IN  CHAR8  *Url,
   IN  CHAR8  *Id,
   OUT CHAR8  **Redpath
@@ -187,12 +188,12 @@ RedfishBuildRedpathUseId (
 {
   UINTN  RedpathSize;
 
-  if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id == NULL)) {
+  if ((Redpath == NULL) || (ServiceVersionStr == NULL) || (Url == NULL) || (Id == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
 
   RedpathSize = AsciiStrLen ("/") +
-                AsciiStrLen (ServiceVerisonStr) +
+                AsciiStrLen (ServiceVersionStr) +
                 AsciiStrLen (Url) +
                 AsciiStrLen ("[Id=]") +
                 AsciiStrLen (Id) + 1;
@@ -201,6 +202,6 @@ RedfishBuildRedpathUseId (
     return EFI_OUT_OF_RESOURCES;
   }
 
-  AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url, Id);
+  AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVersionStr, Url, Id);
   return EFI_SUCCESS;
 }
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109991): https://edk2.groups.io/g/devel/message/109991
Mute This Topic: https://groups.io/mt/102154011/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces.
  2023-10-24  8:38 [edk2-devel] [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces Nickle Wang via groups.io
@ 2023-10-26  6:04 ` Chang, Abner via groups.io
  0 siblings, 0 replies; 2+ messages in thread
From: Chang, Abner via groups.io @ 2023-10-26  6:04 UTC (permalink / raw)
  To: Nickle Wang, devel@edk2.groups.io; +Cc: Igor Kulchytskyy, Nick Ramirez

[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Tuesday, October 24, 2023 4:39 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
> Subject: [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces.
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Add two new interface: RedfishServiceInPayload() and RedfishPutToUri()
> for Redfish HTTP protocol implementation. Fix several typos and add
> missing JsonLib in INF file.
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  .../PrivateLibrary/RedfishLib/RedfishLib.inf  |   2 +
>  RedfishPkg/Include/Library/RedfishLib.h       |  95 +++++++++--
>  .../PrivateLibrary/RedfishLib/RedfishLib.c    | 153 ++++++++++++++++--
>  .../PrivateLibrary/RedfishLib/RedfishMisc.c   |  13 +-
>  4 files changed, 226 insertions(+), 37 deletions(-)
>
> diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
> b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
> index 128d511df7c9..124ecb1e3aae 100644
> --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
> +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf
> @@ -3,6 +3,7 @@
>  #
>  #  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>  #  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> +#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>  #
>  #    SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -42,6 +43,7 @@
>    BaseLib
>    BaseMemoryLib
>    DebugLib
> +  JsonLib
>    HttpLib
>    MemoryAllocationLib
>    NetLib
> diff --git a/RedfishPkg/Include/Library/RedfishLib.h
> b/RedfishPkg/Include/Library/RedfishLib.h
> index 28c2b290e613..8309a67c769f 100644
> --- a/RedfishPkg/Include/Library/RedfishLib.h
> +++ b/RedfishPkg/Include/Library/RedfishLib.h
> @@ -61,6 +61,7 @@
>
>    Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>    (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -183,6 +184,23 @@ RedfishJsonInPayload (
>    IN REDFISH_PAYLOAD  Payload
>    );
>
> +/**
> +  This function returns the Redfish service of a REDFISH_PAYLOAD.
> +
> +  Caller doesn't need to free the returned JSON value because it will be
> released
> +  in corresponding RedfishCleanupService() function.
> +
> +  @param[in]    Payload     A REDFISH_PAYLOAD instance.
> +
> +  @return     Redfish service of the payload.
> +
> +**/
> +REDFISH_SERVICE
> +EFIAPI
> +RedfishServiceInPayload (
> +  IN REDFISH_PAYLOAD  Payload
> +  );
> +
>  /**
>    Fill the input RedPath string with system UUID from SMBIOS table or use the
> customized
>    ID if  FromSmbios == FALSE.
> @@ -222,7 +240,7 @@ RedfishBuildPathWithSystemUuid (
>                                        from the root node.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The corresponding redfish
> resource has
>                                    been returned in Payload within RedResponse.
>    @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or
> RedResponse is NULL.
> @@ -252,7 +270,7 @@ RedfishGetByService (
>    @param[in]    URI               String to address a resource.
>    @param[out]   RedResponse       Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The corresponding redfish
> resource has
>                                    been returned in Payload within RedResponse.
>    @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or
> RedResponse is NULL.
> @@ -282,7 +300,7 @@ RedfishGetByUri (
>    @param[in]    RedPath           Relative RedPath string to address a resource
> inside Payload.
>    @param[out]   RedResponse       Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful:
> +  @retval EFI_SUCCESS             The operation is successful:
>                                    1. The HTTP StatusCode is NULL and the returned Payload in
>                                    RedResponse is not NULL, indicates the Redfish resource has
>                                    been parsed from the input payload directly.
> @@ -323,7 +341,7 @@ RedfishGetByPayload (
>    @param[in]    Content               JSON represented properties to be update.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -357,10 +375,10 @@ RedfishPatchToUri (
>    redfish response data.
>
>    @param[in]    Target           The target payload to be updated.
> -  @param[in]    Payload          Palyoad with properties to be changed.
> +  @param[in]    Payload          Payload with properties to be changed.
>    @param[out]   RedResponse      Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -398,7 +416,7 @@ RedfishPatchToPayload (
>    @param[in]    ContentType           Type of the Content to be send to Redfish
> service
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -416,8 +434,8 @@ RedfishPostToUri (
>    IN     REDFISH_SERVICE   RedfishService,
>    IN     CONST CHAR8       *Uri,
>    IN     CONST CHAR8       *Content,
> -  IN     UINTN             ContentSize,
> -  IN     CONST CHAR8       *ContentType,
> +  IN     UINTN             ContentSize OPTIONAL,
> +  IN     CONST CHAR8       *ContentType OPTIONAL,
>    OUT    REDFISH_RESPONSE  *RedResponse
>    );
>
> @@ -436,7 +454,7 @@ RedfishPostToUri (
>    @param[in]    Payload         The new resource to be created.
>    @param[out]   RedResponse     Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -471,7 +489,7 @@ RedfishPostToPayload (
>    @param[in]    Uri                   Relative path to address the resource.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX, the Redfish resource has been
> removed.
>                                    If there is any message returned from server, it will be
> returned
>                                    in Payload within RedResponse.
> @@ -507,7 +525,7 @@ RedfishDeleteByUri (
>    @param[in]    Content               JSON represented properties to be deleted.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX, the Redfish resource has been
> removed.
>                                    If there is any message returned from server, it will be
> returned
>                                    in Payload within RedResponse.
> @@ -528,6 +546,49 @@ RedfishDeleteByUriEx (
>    OUT    REDFISH_RESPONSE  *RedResponse
>    );
>
> +/**
> +  Use HTTP PUT to create new Redfish resource in the Resource Collection.
> +
> +  This function uses the RedfishService to put a Redfish resource addressed by
> +  Uri (only the relative path is required). Changes to one or more properties
> within
> +  the target resource are represented in the input Content, properties not
> specified
> +  in Content won't be changed by this request. The corresponding redfish
> response will
> +  returned, including HTTP StatusCode, Headers and Payload which record
> any HTTP response
> +  messages.
> +
> +  Callers are responsible for freeing the HTTP StatusCode, Headers and
> Payload returned in
> +  redfish response data.
> +
> +  @param[in]    RedfishService        The Service to access the Redfish resources.
> +  @param[in]    Uri                   Relative path to address the resource.
> +  @param[in]    Content               JSON represented properties to be update.
> +  @param[in]    ContentSize           Size of the Content to be send to Redfish
> service
> +  @param[in]    ContentType           Type of the Content to be send to Redfish
> service
> +  @param[out]   RedResponse           Pointer to the Redfish response data.
> +
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
> +                                  NULL and the value is 2XX. The Redfish resource 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
> RedResponse is NULL.
> +  @retval EFI_DEVICE_ERROR        An unexpected system or network error
> occurred. Callers can get
> +                                  more error info from returned HTTP StatusCode, Headers
> and Payload
> +                                  within RedResponse:
> +                                  1. If the returned StatusCode is NULL, indicates any error
> happen.
> +                                  2. If the returned StatusCode is not NULL and the value is
> not 2XX,
> +                                     indicates any error happen.
> +**/
> +EFI_STATUS
> +EFIAPI
> +RedfishPutToUri (
> +  IN     REDFISH_SERVICE   RedfishService,
> +  IN     CONST CHAR8       *Uri,
> +  IN     CONST CHAR8       *Content,
> +  IN     UINTN             ContentSize OPTIONAL,
> +  IN     CONST CHAR8       *ContentType OPTIONAL,
> +  OUT    REDFISH_RESPONSE  *RedResponse
> +  );
> +
>  /**
>    Dump text in fractions.
>
> @@ -582,7 +643,7 @@ RedfishFreeResponse (
>    Check if the "@odata.type" in Payload is valid or not.
>
>    @param[in]  Payload                  The Redfish payload to be checked.
> -  @param[in]  OdataTypeName            OdataType will be retrived from
> mapping list.
> +  @param[in]  OdataTypeName            OdataType will be retrieved from
> mapping list.
>    @param[in]  OdataTypeMappingList     The list of OdataType.
>    @param[in]  OdataTypeMappingListSize The number of mapping list
>
> @@ -616,7 +677,7 @@ RedfishIsPayloadCollection (
>    @param[in]  Payload         The Redfish collection payload
>    @param[in]  CollectionSize  Size of this collection
>
> -  @return EFI_SUCCESS              Coolection size is returned in CollectionSize
> +  @return EFI_SUCCESS              Collection size is returned in CollectionSize
>    @return EFI_INVALID_PARAMETER    The payload is not a collection.
>  **/
>  EFI_STATUS
> @@ -674,18 +735,18 @@ RedfishGetServiceVersion (
>  /**
>    This function returns the string of Redfish service version.
>
> -  @param[in]   ServiceVerisonStr The string of Redfish service version.
> +  @param[in]   ServiceVersionStr The string of Redfish service version.
>    @param[in]   Url               The URL to build Redpath with ID.
>                                   Start with "/", for example "/Registries"
>    @param[in]   Id                ID string
> -  @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
> +  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
>                                   the memory allocated for this string.
>    @return     EFI_STATUS
>
>  **/
>  EFI_STATUS
>  RedfishBuildRedpathUseId (
> -  IN  CHAR8  *ServiceVerisonStr,
> +  IN  CHAR8  *ServiceVersionStr,
>    IN  CHAR8  *Url,
>    IN  CHAR8  *Id,
>    OUT CHAR8  **Redpath
> diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
> b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
> index cca0ea774893..f4045044829a 100644
> --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
> +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
> @@ -4,6 +4,7 @@
>
>    Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>    (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -167,6 +168,30 @@ RedfishJsonInPayload (
>    return ((redfishPayload *)Payload)->json;
>  }
>
> +/**
> +  This function returns the Redfish service of a REDFISH_PAYLOAD.
> +
> +  Caller doesn't need to free the returned JSON value because it will be
> released
> +  in corresponding RedfishCleanupService() function.
> +
> +  @param[in]    Payload     A REDFISH_PAYLOAD instance.
> +
> +  @return     Redfish service of the payload.
> +
> +**/
> +REDFISH_SERVICE
> +EFIAPI
> +RedfishServiceInPayload (
> +  IN REDFISH_PAYLOAD  Payload
> +  )
> +{
> +  if (Payload == NULL) {
> +    return NULL;
> +  }
> +
> +  return ((redfishPayload *)Payload)->service;
> +}
> +
>  /**
>    Fill the input RedPath string with system UUID from SMBIOS table or use the
> customized
>    ID if  FromSmbios == FALSE.
> @@ -244,7 +269,7 @@ RedfishBuildPathWithSystemUuid (
>                                        from the root node.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The corresponding redfish
> resource has
>                                    been returned in Payload within RedResponse.
>    @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or
> RedResponse is NULL.
> @@ -304,7 +329,7 @@ RedfishGetByService (
>    @param[in]    Uri               String to address a resource.
>    @param[out]   RedResponse       Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The corresponding redfish
> resource has
>                                    been returned in Payload within RedResponse.
>    @retval EFI_INVALID_PARAMETER   RedfishService, RedPath, or
> RedResponse is NULL.
> @@ -367,7 +392,7 @@ RedfishGetByUri (
>    @param[in]    RedPath           Relative RedPath string to address a resource
> inside Payload.
>    @param[out]   RedResponse       Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful:
> +  @retval EFI_SUCCESS             The operation is successful:
>                                    1. The HTTP StatusCode is NULL and the returned Payload in
>                                    RedResponse is not NULL, indicates the Redfish resource has
>                                    been parsed from the input payload directly.
> @@ -440,7 +465,7 @@ RedfishGetByPayload (
>    @param[in]    Content               JSON represented properties to be update.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -527,10 +552,10 @@ ON_EXIT:
>    redfish response data.
>
>    @param[in]    Target           The target payload to be updated.
> -  @param[in]    Payload          Palyoad with properties to be changed.
> +  @param[in]    Payload          Payload with properties to be changed.
>    @param[out]   RedResponse      Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -601,7 +626,7 @@ RedfishPatchToPayload (
>    @param[in]    ContentType           Type of the Content to be send to Redfish
> service
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -619,8 +644,8 @@ RedfishPostToUri (
>    IN     REDFISH_SERVICE   RedfishService,
>    IN     CONST CHAR8       *Uri,
>    IN     CONST CHAR8       *Content,
> -  IN     UINTN             ContentSize,
> -  IN     CONST CHAR8       *ContentType,
> +  IN     UINTN             ContentSize OPTIONAL,
> +  IN     CONST CHAR8       *ContentType OPTIONAL,
>    OUT    REDFISH_RESPONSE  *RedResponse
>    )
>  {
> @@ -694,7 +719,7 @@ ON_EXIT:
>    @param[in]    Payload         The new resource to be created.
>    @param[out]   RedResponse     Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX. The Redfish resource will be
> returned
>                                    in Payload within RedResponse if server send it back in the
> HTTP
>                                    response message body.
> @@ -762,7 +787,7 @@ RedfishPostToPayload (
>    @param[in]    Uri                   Relative path to address the resource.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX, the Redfish resource has been
> removed.
>                                    If there is any message returned from server, it will be
> returned
>                                    in Payload within RedResponse.
> @@ -850,7 +875,7 @@ ON_EXIT:
>    @param[in]    Content               JSON represented properties to be deleted.
>    @param[out]   RedResponse           Pointer to the Redfish response data.
>
> -  @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP
> StatusCode is not
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
>                                    NULL and the value is 2XX, the Redfish resource has been
> removed.
>                                    If there is any message returned from server, it will be
> returned
>                                    in Payload within RedResponse.
> @@ -1060,7 +1085,7 @@ RedfishFreeResponse (
>    Check if the "@odata.type" in Payload is valid or not.
>
>    @param[in]  Payload                  The Redfish payload to be checked.
> -  @param[in]  OdataTypeName            OdataType will be retrived from
> mapping list.
> +  @param[in]  OdataTypeName            OdataType will be retrieved from
> mapping list.
>    @param[in]  OdataTypeMappingList     The list of OdataType.
>    @param[in]  OdataTypeMappingListSize The number of mapping list
>
> @@ -1127,7 +1152,7 @@ RedfishIsPayloadCollection (
>    @param[in]  Payload         The Redfish collection payload
>    @param[in]  CollectionSize  Size of this collection
>
> -  @return EFI_SUCCESS              Coolection size is returned in CollectionSize
> +  @return EFI_SUCCESS              Collection size is returned in CollectionSize
>    @return EFI_INVALID_PARAMETER    The payload is not a collection.
>  **/
>  EFI_STATUS
> @@ -1217,3 +1242,103 @@ RedfishCheckIfRedpathExist (
>
>    return EFI_SUCCESS;
>  }
> +
> +/**
> +  Use HTTP PUT to create new Redfish resource in the Resource Collection.
> +
> +  This function uses the RedfishService to put a Redfish resource addressed by
> +  Uri (only the relative path is required). Changes to one or more properties
> within
> +  the target resource are represented in the input Content, properties not
> specified
> +  in Content won't be changed by this request. The corresponding redfish
> response will
> +  returned, including HTTP StatusCode, Headers and Payload which record
> any HTTP response
> +  messages.
> +
> +  Callers are responsible for freeing the HTTP StatusCode, Headers and
> Payload returned in
> +  redfish response data.
> +
> +  @param[in]    RedfishService        The Service to access the Redfish resources.
> +  @param[in]    Uri                   Relative path to address the resource.
> +  @param[in]    Content               JSON represented properties to be update.
> +  @param[in]    ContentSize           Size of the Content to be send to Redfish
> service
> +  @param[in]    ContentType           Type of the Content to be send to Redfish
> service
> +  @param[out]   RedResponse           Pointer to the Redfish response data.
> +
> +  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP
> StatusCode is not
> +                                  NULL and the value is 2XX. The Redfish resource 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
> RedResponse is NULL.
> +  @retval EFI_DEVICE_ERROR        An unexpected system or network error
> occurred. Callers can get
> +                                  more error info from returned HTTP StatusCode, Headers
> and Payload
> +                                  within RedResponse:
> +                                  1. If the returned StatusCode is NULL, indicates any error
> happen.
> +                                  2. If the returned StatusCode is not NULL and the value is
> not 2XX,
> +                                     indicates any error happen.
> +**/
> +EFI_STATUS
> +EFIAPI
> +RedfishPutToUri (
> +  IN     REDFISH_SERVICE   RedfishService,
> +  IN     CONST CHAR8       *Uri,
> +  IN     CONST CHAR8       *Content,
> +  IN     UINTN             ContentSize OPTIONAL,
> +  IN     CONST CHAR8       *ContentType OPTIONAL,
> +  OUT    REDFISH_RESPONSE  *RedResponse
> +  )
> +{
> +  EFI_STATUS        Status;
> +  EDKII_JSON_VALUE  JsonValue;
> +
> +  Status    = EFI_SUCCESS;
> +  JsonValue = NULL;
> +
> +  if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) ||
> (RedResponse == NULL)) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
> +
> +  JsonValue = (EDKII_JSON_VALUE)putUriFromServiceEx (
> +                                  RedfishService,
> +                                  Uri,
> +                                  Content,
> +                                  ContentSize,
> +                                  ContentType,
> +                                  &(RedResponse->Headers),
> +                                  &(RedResponse->HeaderCount),
> +                                  &(RedResponse->StatusCode)
> +                                  );
> +
> +  //
> +  // 1. If the returned StatusCode is NULL, indicates any error happen.
> +  //
> +  if (RedResponse->StatusCode == NULL) {
> +    Status = EFI_DEVICE_ERROR;
> +    goto ON_EXIT;
> +  }
> +
> +  //
> +  // 2. If the returned StatusCode is not NULL and the value is not 2XX,
> indicates 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 = EFI_DEVICE_ERROR;
> +  }
> +
> +ON_EXIT:
> +  if (JsonValue != NULL) {
> +    RedResponse->Payload = createRedfishPayload (JsonValue,
> RedfishService);
> +    if (RedResponse->Payload == NULL) {
> +      //
> +      // Ignore the error when create RedfishPayload, just free the JsonValue
> since it's not what
> +      // we care about if the returned StatusCode is 2XX.
> +      //
> +      JsonValueFree (JsonValue);
> +    }
> +  }
> +
> +  return Status;
> +}
> diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
> b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
> index 0eb23196d2c2..b6e9a111785a 100644
> --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
> +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
> @@ -3,6 +3,7 @@
>
>    Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
>    (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -168,18 +169,18 @@ RedfishGetAuthInfo (
>  /**
>    This function returns the string of Redfish service version.
>
> -  @param[in]   ServiceVerisonStr The string of Redfish service version.
> +  @param[in]   ServiceVersionStr The string of Redfish service version.
>    @param[in]   Url               The URL to build Redpath with ID.
>                                   Start with "/", for example "/Registries"
>    @param[in]   Id                ID string
> -  @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
> +  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
>                                   the memory allocated for this string.
>    @return     EFI_STATUS
>
>  **/
>  EFI_STATUS
>  RedfishBuildRedpathUseId (
> -  IN  CHAR8  *ServiceVerisonStr,
> +  IN  CHAR8  *ServiceVersionStr,
>    IN  CHAR8  *Url,
>    IN  CHAR8  *Id,
>    OUT CHAR8  **Redpath
> @@ -187,12 +188,12 @@ RedfishBuildRedpathUseId (
>  {
>    UINTN  RedpathSize;
>
> -  if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id
> == NULL)) {
> +  if ((Redpath == NULL) || (ServiceVersionStr == NULL) || (Url == NULL) || (Id
> == NULL)) {
>      return EFI_INVALID_PARAMETER;
>    }
>
>    RedpathSize = AsciiStrLen ("/") +
> -                AsciiStrLen (ServiceVerisonStr) +
> +                AsciiStrLen (ServiceVersionStr) +
>                  AsciiStrLen (Url) +
>                  AsciiStrLen ("[Id=]") +
>                  AsciiStrLen (Id) + 1;
> @@ -201,6 +202,6 @@ RedfishBuildRedpathUseId (
>      return EFI_OUT_OF_RESOURCES;
>    }
>
> -  AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url,
> Id);
> +  AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVersionStr, Url,
> Id);
>    return EFI_SUCCESS;
>  }
> --
> 2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110074): https://edk2.groups.io/g/devel/message/110074
Mute This Topic: https://groups.io/mt/102154011/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-26  6:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-24  8:38 [edk2-devel] [PATCH 1/3] RedfishPkg/RedfishLib: introduce new interfaces Nickle Wang via groups.io
2023-10-26  6:04 ` Chang, Abner via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox