Skip to content

Commit

Permalink
RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
Browse files Browse the repository at this point in the history
- 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>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
  • Loading branch information
changab committed Jan 16, 2024
1 parent feb9738 commit fa52467
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
35 changes: 35 additions & 0 deletions RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3412,6 +3412,42 @@ 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.
Expand Down Expand Up @@ -3935,6 +3971,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[LibraryClasses]
BaseLib
BaseMemoryLib
ConverterCommonLib
DebugLib
MemoryAllocationLib
RedfishLib
Expand Down

0 comments on commit fa52467

Please sign in to comment.