Skip to content

Commit

Permalink
RedfishClientPkg/ConverterLib: Remove unchangeable properties
Browse files Browse the repository at this point in the history
Update RedfishCsCommon.c to add a function to remove Redfish
unchangeable properties.

Signed-off-by: Abner Chang <[email protected]>
Cc: Nickle Wang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
  • Loading branch information
changab committed Jan 16, 2024
1 parent a1d67f5 commit 368a1f9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions RedfishClientPkg/ConverterLib/include/RedfishCsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ DestoryCsMemory (
RedfishCS_void *rootCs
);

/**
This function removes the unchangeable Redfish properties from JSON raw text
The content in JsonString is left unmodified, the caller has to give enoungh
memory pointed by NewJsonBuffer in the size of BufferSize.
JsonString Input JSON raw string
NewJsonBuffer Pointer to memory for the updated JSON raw string in
size of BufferSize.
BufferSize The buffer size of NewJsonBuffer
Return RedfishCS_status.
**/
RedfishCS_status
RemoveUnchangeableProperties (
RedfishCS_char *JsonString,
RedfishCS_char *NewJsonBuffer,
RedfishCS_uint32 BufferSize
);

typedef struct _RedfishCS_char_Array RedfishCS_char_Array;
typedef struct _RedfishCS_int64_Array RedfishCS_int64_Array;
typedef struct _RedfishCS_bool_Array RedfishCS_bool_Array;
Expand Down
55 changes: 55 additions & 0 deletions RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,3 +1461,58 @@ CsEmptyPropLinkToJson (

return RedfishCS_status_success;
}

/**
This function removes the unchangeable Redfish properties from JSON raw text
The content in JsonString is left unmodified, the caller has to give enoungh
memory pointed by NewJsonBuffer in the size of BufferSize.
JsonString Input JSON raw string
NewJsonBuffer Pointer to memory for the updated JSON raw string in
size of BufferSize.
BufferSize The buffer size of NewJsonBuffer
Return RedfishCS_status.
**/
RedfishCS_status
RemoveUnchangeableProperties (
RedfishCS_char *JsonString,
RedfishCS_char *NewJsonBuffer,
RedfishCS_uint32 BufferSize
)
{
json_t *JsonObj;
RedfishCS_char *TempChar;
RedfishCS_status Status;

if ((JsonString == NULL) || (NewJsonBuffer == NULL)) {
return RedfishCS_status_invalid_parameter;
}

JsonObj = json_loads (JsonString, 0, NULL);
if (JsonObj == NULL) {
return RedfishCS_status_unknown_error;
}

json_object_del (JsonObj, "@odata.type");
json_object_del (JsonObj, "@odata.id");
json_object_del (JsonObj, "Id");
json_object_del (JsonObj, "Name");

TempChar = json_dumps ((json_t *)JsonObj, JSON_INDENT (2));
if (TempChar != NULL) {
if ((strlen (TempChar) + 1) > BufferSize) {
Status = RedfishCS_status_insufficient_memory;
} else {
memcpy (NewJsonBuffer, TempChar, strlen (TempChar) + 1);
free (TempChar);
Status = RedfishCS_status_success;
}
} else {
Status = RedfishCS_status_unknown_error;
}

json_decref (JsonObj);
return Status;
}

0 comments on commit 368a1f9

Please sign in to comment.