Re: [edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
Please see my comments below. Regards, Nickle > -Original Message- > From: abner.ch...@amd.com > Sent: Friday, January 12, 2024 11:26 AM > To: devel@edk2.groups.io > Cc: Nickle Wang ; Igor Kulchytskyy > Subject: [edk2-redfish-client][PATCH 2/3] > RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions > > External email: Use caution opening links or attachments > > > From: Abner Chang > > - Add RedfishRemoveUnchangeableProperties () to remove > unchangeable Redfish properties such as @OData.id. > - Add DestoryRedfishCharArray () to free Redfish string > array. > > Signed-off-by: Abner Chang > Cc: Nickle Wang > Cc: Igor Kulchytskyy > --- > .../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/RedfishFeatureUt > +++ ilityLib.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 OthersError 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 > + ); 1) I am thinking that can we use "ReadOnly" instead of "Unchangeable"? 2) Can we have two parameters for input and output string? Caller can decide when to release input string and this function does not do this for caller. For example: RedfishRemoveReadOnlyProperties ( IN CHAR8 *JsonString, OUT CHAR8 **ModifedString ); > + > #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/RedfishFeatureUt > +++ ilityLib.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 OthersError 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); I suggest setting Head to NULL after FreePool call. So, no one can use this memory
[edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
From: Abner Chang - Add RedfishRemoveUnchangeableProperties () to remove unchangeable Redfish properties such as @OData.id. - Add DestoryRedfishCharArray () to free Redfish string array. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy --- .../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 OthersError 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 OthersError 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