public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner via groups.io" <abner.chang=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Nickle Wang <nicklew@nvidia.com>, Igor Kulchytskyy <igork@ami.com>
Subject: [edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
Date: Fri, 12 Jan 2024 11:26:21 +0800	[thread overview]
Message-ID: <20240112032622.274-2-abner.chang@amd.com> (raw)
In-Reply-To: <20240112032622.274-1-abner.chang@amd.com>

From: Abner Chang <abner.chang@amd.com>

- Add RedfishRemoveUnchangeableProperties () to remove
  unchangeable Redfish properties such as @OData.id.
- Add DestoryRedfishCharArray () to free Redfish string
  array.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../RedfishFeatureUtilityLib.inf              |  1 +
 .../Library/RedfishFeatureUtilityLib.h        | 35 ++++++++
 .../RedfishFeatureUtilityLib.c                | 79 +++++++++++++++++++
 3 files changed, 115 insertions(+)

diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
index 63330c8e9d..d8f3da3732 100644
--- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
+++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
@@ -37,6 +37,7 @@
 [LibraryClasses]
   BaseLib
   BaseMemoryLib
+  ConverterCommonLib
   DebugLib
   MemoryAllocationLib
   RedfishLib
diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
index 0f8aede5c4..1b6d3f4cf8 100644
--- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
+++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
@@ -821,6 +821,23 @@ AddRedfishCharArray (
   IN      UINTN                 ArraySize
   );
 
+/**
+
+  Destroy Redfish string array
+
+  @param[in]    Head          The head of string array.
+  @param[in]    ArraySize     The size of StringArray.
+
+  @retval     EFI_SUCCESS       String array is destroyed successfully.
+  @retval     Others            Error happens
+
+**/
+EFI_STATUS
+DestoryRedfishCharArray (
+  IN      RedfishCS_char_Array  *Head,
+  IN      UINTN                 ArraySize
+  );
+
 /**
 
   Create numeric array and append to array node in Redfish JSON convert format.
@@ -1024,4 +1041,22 @@ ValidateRedfishStringArrayValues (
   OUT BOOLEAN              *ValueChanged
   );
 
+/**
+  This function removes the unchangeable Redfish properties from input JsonString.
+  New JSON string is returned in JsonString and the memory of original pointer to input
+  JsonString was freed. Caller is responsible to free the memory pointed by output
+  JsonString.
+
+  @param[in,out]  JsonString  On input, this is the pointer to original JSON string.
+                              On output, this is the new pointer to the updated JSON string.
+
+  @retval  EFI_SUCCESS  The unchangeable Redfish properties were removed from original JSON string.
+  @retval  Others       There are problems to remove unchangeable Redfish properties.
+
+**/
+EFI_STATUS
+RedfishRemoveUnchangeableProperties (
+  IN OUT  CHAR8  **JsonString
+  );
+
 #endif
diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index aa723264e8..b16a811bb1 100644
--- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -3412,6 +3412,40 @@ AddRedfishCharArray (
   return EFI_SUCCESS;
 }
 
+/**
+
+  Destroy Redfish string array
+
+  @param[in]    Head          The head of string array.
+  @param[in]    ArraySize     The size of StringArray.
+
+  @retval     EFI_SUCCESS       String array is destroyed successfully.
+  @retval     Others            Error happens
+
+**/
+EFI_STATUS
+DestoryRedfishCharArray (
+  IN      RedfishCS_char_Array  *Head,
+  IN      UINTN                 ArraySize
+  )
+{
+  UINTN                 Index;
+  RedfishCS_char_Array  *NextPointer;
+
+  if ((Head == NULL) || (ArraySize == 0)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  for (Index = 0; Index < ArraySize; Index++) {
+    NextPointer = Head->Next;
+    if (Head != NULL) {
+      FreePool (Head);
+    }
+    Head = NextPointer;
+  }
+  return EFI_SUCCESS;
+}
+
 /**
 
   Create numeric array and append to array node in Redfish JSON convert format.
@@ -3935,6 +3969,51 @@ ValidateRedfishStringArrayValues (
   return EFI_SUCCESS;
 }
 
+/**
+  This function removes the unchangeable Redfish properties from input JsonString.
+  New JSON string is returned in JsonString and the memory of original pointer to input
+  JsonString was freed. Caller is responsible to free the memory pointed by output
+  JsonString.
+
+  @param[in,out]  JsonString  On input, this is the pointer to original JSON string.
+                              On output, this is the new pointer to the updated JSON string.
+
+  @retval  EFI_SUCCESS  The unchangeable Redfish properties were removed from original JSON string.
+  @retval  Others       There are problems to remove unchangeable Redfish properties.
+
+**/
+EFI_STATUS
+RedfishRemoveUnchangeableProperties (
+  IN OUT  CHAR8  **JsonString
+  )
+{
+  RedfishCS_status  Status;
+  CHAR8             *UpdatedJsonString;
+
+  if ((JsonString == NULL) || (*JsonString == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  UpdatedJsonString = AllocateZeroPool (AsciiStrSize (*JsonString));
+  if (UpdatedJsonString == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Insufficient memory for UpdatedJsonString.\n", __func__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  Status = RemoveUnchangeableProperties (
+             (RedfishCS_char *)*JsonString,
+             (RedfishCS_char *)UpdatedJsonString,
+             (RedfishCS_uint32)AsciiStrSize (*JsonString)
+             );
+  if (Status != RedfishCS_status_success) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  FreePool (*JsonString);
+  *JsonString = UpdatedJsonString;
+  return EFI_SUCCESS;
+}
+
 /**
 
   Install Boot Maintenance Manager Menu driver.
-- 
2.37.1.windows.1



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



  reply	other threads:[~2024-01-12  3:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12  3:26 [edk2-devel] [edk2-redfish-client][PATCH 1/3] RedfishClientPkg/jansson: Define json_object_del Chang, Abner via groups.io
2024-01-12  3:26 ` Chang, Abner via groups.io [this message]
2024-01-16  3:14   ` [edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions Nickle Wang via groups.io
2024-01-12  3:26 ` [edk2-devel] [edk2-redfish-client][PATCH 3/3] RedfishClientPkg/ConverterLib: Function to remove Redfish unchangeable properties Chang, Abner via groups.io
2024-01-16  3:17   ` Nickle Wang via groups.io
2024-01-16  4:08     ` Chang, Abner via groups.io
2024-01-16  6:20       ` Nickle Wang via groups.io
2024-01-16  8:31         ` Chang, Abner via groups.io
2024-01-16  3:07 ` [edk2-devel] [edk2-redfish-client][PATCH 1/3] RedfishClientPkg/jansson: Define json_object_del Nickle Wang via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240112032622.274-2-abner.chang@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox