From: Abner Chang <abner.ch...@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.ch...@amd.com>
Cc: Nickle Wang <nick...@nvidia.com>
Cc: Igor Kulchytskyy <ig...@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/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to