summaryrefslogtreecommitdiffstats
path: root/RedfishPkg/PrivateLibrary
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:54:11 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commit39de741e2dcb8f11e9b4438e37224797643d8451 (patch)
treeddf957e0b215e0918dc53ad756c6bd047c9b7b16 /RedfishPkg/PrivateLibrary
parent5220bd211df890f2672c23c050082862cd1e82d6 (diff)
downloadedk2-39de741e2dcb8f11e9b4438e37224797643d8451.tar.gz
edk2-39de741e2dcb8f11e9b4438e37224797643d8451.tar.bz2
edk2-39de741e2dcb8f11e9b4438e37224797643d8451.zip
RedfishPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the RedfishPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Abner Chang <abner.chang@hpe.com>
Diffstat (limited to 'RedfishPkg/PrivateLibrary')
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c531
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c342
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c71
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h16
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h1
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h91
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h130
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h33
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c1252
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c344
-rw-r--r--RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c1033
11 files changed, 2206 insertions, 1638 deletions
diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
index 58ef4f8fdb..f240dfba13 100644
--- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
@@ -14,17 +14,20 @@
#include <Library/SortLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
-int errno = 0;
-char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n";
+int errno = 0;
+char errnum_message[] = "We don't support to map errnum to the error message on edk2 Redfish\n";
// This is required to keep VC++ happy if you use floating-point
-int _fltused = 1;
+int _fltused = 1;
/**
Determine if a particular character is an alphanumeric character
@return Returns 1 if c is an alphanumeric character, otherwise returns 0.
**/
-int isalnum (int c)
+int
+isalnum (
+ int c
+ )
{
//
// <alnum> ::= [0-9] | [a-z] | [A-Z]
@@ -39,7 +42,10 @@ int isalnum (int c)
@return Returns 1 if c is an digital character, otherwise returns 0.
**/
-int isdchar (int c)
+int
+isdchar (
+ int c
+ )
{
//
// [0-9] | [e +-.]
@@ -55,7 +61,10 @@ int isdchar (int c)
@return Returns 1 if c is a space character
**/
-int isspace (int c)
+int
+isspace (
+ int c
+ )
{
//
// <space> ::= [ ]
@@ -66,15 +75,21 @@ int isspace (int c)
/**
Allocates memory blocks
*/
-void *malloc (size_t size)
+void *
+malloc (
+ size_t size
+ )
{
- return AllocatePool ((UINTN) size);
+ return AllocatePool ((UINTN)size);
}
/**
De-allocates or frees a memory block
*/
-void free (void *ptr)
+void
+free (
+ void *ptr
+ )
{
//
// In Standard C, free() handles a null pointer argument transparently. This
@@ -90,15 +105,20 @@ void free (void *ptr)
@return Returns the pointer to duplicated string.
**/
-char * strdup(const char *str)
+char *
+strdup (
+ const char *str
+ )
{
- size_t len;
- char *copy;
+ size_t len;
+ char *copy;
- len = strlen(str) + 1;
- if ((copy = malloc(len)) == NULL)
+ len = strlen (str) + 1;
+ if ((copy = malloc (len)) == NULL) {
return (NULL);
- memcpy(copy, str, len);
+ }
+
+ memcpy (copy, str, len);
return (copy);
}
@@ -115,13 +135,14 @@ char * strdup(const char *str)
returned unchanged.
**/
int
-toupper(
- IN int c
+toupper (
+ IN int c
)
{
- if ( (c >= 'a') && (c <= 'z') ) {
+ if ((c >= 'a') && (c <= 'z')) {
c = c - ('a' - 'A');
}
+
return c;
}
@@ -131,15 +152,18 @@ toupper(
@return Returns the value of digit.
**/
int
-Digit2Val( int c)
+Digit2Val (
+ int c
+ )
{
- if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) { /* If c is one of [A-Za-z]... */
- c = toupper(c) - 7; // Adjust so 'A' is ('9' + 1)
+ if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) {
+ /* If c is one of [A-Za-z]... */
+ c = toupper (c) - 7; // Adjust so 'A' is ('9' + 1)
}
+
return c - '0'; // Value returned is between 0 and 35, inclusive.
}
-
/** The strtoll function converts the initial portion of the string pointed to
by nptr to long long int representation.
@@ -152,9 +176,13 @@ Digit2Val( int c)
and the value of the macro ERANGE is stored in errno.
**/
long long
-strtoll(const char * nptr, char ** endptr, int base)
+strtoll (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
+ const char *pEnd;
long long Result = 0;
long long Previous;
int temp;
@@ -162,71 +190,86 @@ strtoll(const char * nptr, char ** endptr, int base)
pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
Negative = FALSE;
++nptr;
- }
- else if(*nptr == '-') {
+ } else if (*nptr == '-') {
Negative = TRUE;
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = MultS64x64 (Result, base) + (long long int)temp;
- if( Result <= Previous) { // Detect Overflow
- if(Negative) {
+ Result = MultS64x64 (Result, base) + (long long int)temp;
+ if ( Result <= Previous) {
+ // Detect Overflow
+ if (Negative) {
Result = LLONG_MIN;
- }
- else {
+ } else {
Result = LLONG_MAX;
}
+
Negative = FALSE;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
- if(Negative) {
+
+ if (Negative) {
Result = -Result;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -285,9 +328,13 @@ strtoll(const char * nptr, char ** endptr, int base)
is stored in errno.
**/
long
-strtol(const char * nptr, char ** endptr, int base)
+strtol (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
+ const char *pEnd;
long Result = 0;
long Previous;
int temp;
@@ -295,71 +342,86 @@ strtol(const char * nptr, char ** endptr, int base)
pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
Negative = FALSE;
++nptr;
- }
- else if(*nptr == '-') {
+ } else if (*nptr == '-') {
Negative = TRUE;
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = (Result * base) + (long int)temp;
- if( Result <= Previous) { // Detect Overflow
- if(Negative) {
+ Result = (Result * base) + (long int)temp;
+ if ( Result <= Previous) {
+ // Detect Overflow
+ if (Negative) {
Result = LONG_MIN;
- }
- else {
+ } else {
Result = LONG_MAX;
}
+
Negative = FALSE;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
- if(Negative) {
+
+ if (Negative) {
Result = -Result;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -374,66 +436,85 @@ strtol(const char * nptr, char ** endptr, int base)
returned and the value of the macro ERANGE is stored in errno.
**/
unsigned long long
-strtoull(const char * nptr, char ** endptr, int base)
+strtoull (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
- unsigned long long Result = 0;
- unsigned long long Previous;
- int temp;
+ const char *pEnd;
+ unsigned long long Result = 0;
+ unsigned long long Previous;
+ int temp;
pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional + sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = DivU64x32 (Result, base) + (unsigned long long)temp;
- if( Result < Previous) { // If we overflowed
+ Result = DivU64x32 (Result, base) + (unsigned long long)temp;
+ if ( Result < Previous) {
+ // If we overflowed
Result = ULLONG_MAX;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -462,27 +543,34 @@ strtoull(const char * nptr, char ** endptr, int base)
@return Return 0.
**/
double
-strtod (const char * __restrict nptr, char ** __restrict endptr) {
-
- DEBUG((DEBUG_INFO, "We don't supprot double type on edk2 yet!"));
- ASSERT(FALSE);
- return (double)0;
+strtod (
+ const char *__restrict nptr,
+ char **__restrict endptr
+ )
+{
+ DEBUG ((DEBUG_INFO, "We don't supprot double type on edk2 yet!"));
+ ASSERT (FALSE);
+ return (double)0;
}
static UINT8 BitMask[] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
- };
+};
#define WHICH8(c) ((unsigned char)(c) >> 3)
#define WHICH_BIT(c) (BitMask[((c) & 0x7)])
-#define BITMAP64 ((UINT64 *)bitmap)
+#define BITMAP64 ((UINT64 *)bitmap)
static
void
-BuildBitmap(unsigned char * bitmap, const char *s2, int n)
+BuildBitmap (
+ unsigned char *bitmap,
+ const char *s2,
+ int n
+ )
{
- unsigned char bit;
- int index;
+ unsigned char bit;
+ int index;
// Initialize bitmap. Bit 0 is always 1 which corresponds to '\0'
for (BITMAP64[0] = index = 1; index < n; index++) {
@@ -490,9 +578,9 @@ BuildBitmap(unsigned char * bitmap, const char *s2, int n)
}
// Set bits in bitmap corresponding to the characters in s2
- for (; *s2 != '\0'; s2++) {
- index = WHICH8(*s2);
- bit = WHICH_BIT(*s2);
+ for ( ; *s2 != '\0'; s2++) {
+ index = WHICH8 (*s2);
+ bit = WHICH_BIT (*s2);
bitmap[index] = bitmap[index] | bit;
}
}
@@ -504,21 +592,25 @@ BuildBitmap(unsigned char * bitmap, const char *s2, int n)
null pointer if no character from s2 occurs in s1.
**/
char *
-strpbrk(const char *s1, const char *s2)
+strpbrk (
+ const char *s1,
+ const char *s2
+ )
{
- UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
- UINT8 bit;
- int index;
+ UINT8 bitmap[(((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ UINT8 bit;
+ int index;
- BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+ BuildBitmap (bitmap, s2, sizeof (bitmap) / sizeof (UINT64));
- for( ; *s1 != '\0'; ++s1) {
- index = WHICH8(*s1);
- bit = WHICH_BIT(*s1);
- if( (bitmap[index] & bit) != 0) {
+ for ( ; *s1 != '\0'; ++s1) {
+ index = WHICH8 (*s1);
+ bit = WHICH_BIT (*s1);
+ if ((bitmap[index] & bit) != 0) {
return (char *)s1;
}
}
+
return NULL;
}
@@ -535,7 +627,9 @@ strpbrk(const char *s1, const char *s2)
a subsequent call to the strerror function.
**/
char *
-strerror(int errnum)
+strerror (
+ int errnum
+ )
{
return errnum_message;
}
@@ -544,20 +638,24 @@ strerror(int errnum)
Allocate and zero-initialize array.
**/
void *
-calloc(size_t Num, size_t Size)
+calloc (
+ size_t Num,
+ size_t Size
+ )
{
- void *RetVal;
- size_t NumSize;
+ void *RetVal;
+ size_t NumSize;
NumSize = Num * Size;
RetVal = NULL;
if (NumSize != 0) {
- RetVal = malloc(NumSize);
- if( RetVal != NULL) {
- (VOID)ZeroMem( RetVal, NumSize);
- }
+ RetVal = malloc (NumSize);
+ if ( RetVal != NULL) {
+ (VOID)ZeroMem (RetVal, NumSize);
+ }
}
- DEBUG((DEBUG_POOL, "0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
+
+ DEBUG ((DEBUG_POOL, "0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
return RetVal;
}
@@ -567,7 +665,7 @@ calloc(size_t Num, size_t Size)
// month number used as the index (1 -> 12) for regular and leap years.
// The value at index 13 is for the whole year.
//
-UINTN CumulativeDays[2][14] = {
+UINTN CumulativeDays[2][14] = {
{
0,
0,
@@ -602,15 +700,18 @@ UINTN CumulativeDays[2][14] = {
}
};
-#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-#define SECSPERMIN (60)
-#define SECSPERHOUR (60 * 60)
-#define SECSPERDAY (24 * SECSPERHOUR)
+#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define SECSPERMIN (60)
+#define SECSPERHOUR (60 * 60)
+#define SECSPERDAY (24 * SECSPERHOUR)
/**
Get the system time as seconds elapsed since midnight, January 1, 1970.
**/
-time_t time (time_t *timer)
+time_t
+time (
+ time_t *timer
+ )
{
EFI_TIME Time;
time_t CalTime;
@@ -626,7 +727,7 @@ time_t time (time_t *timer)
// UTime should now be set to 00:00:00 on Jan 1 of the current year.
//
for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
- CalTime = CalTime + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);
+ CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
}
//
@@ -634,7 +735,7 @@ time_t time (time_t *timer)
//
CalTime = CalTime +
(time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +
- (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) +
+ (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
(time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
(time_t)(Time.Hour * SECSPERHOUR) +
(time_t)(Time.Minute * 60) +
@@ -650,9 +751,14 @@ time_t time (time_t *timer)
/**
Performs a quick sort
**/
-void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
+void
+qsort (
+ void *base,
+ size_t num,
+ size_t width,
+ int ( *compare )(const void *, const void *)
+ )
{
-
ASSERT (base != NULL);
ASSERT (compare != NULL);
@@ -666,54 +772,93 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
@return Returns the character currently pointed by the internal file position indicator of the specified stream
**/
-int fgetc(FILE * _File){
- return EOF;
+int
+fgetc (
+ FILE *_File
+ )
+{
+ return EOF;
}
+
/**
Open stream file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-FILE *fopen (const char *filename, const char *mode) {
+FILE *
+fopen (
+ const char *filename,
+ const char *mode
+ )
+{
return NULL;
}
+
/**
Read stream from file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {
+size_t
+fread (
+ void *ptr,
+ size_t size,
+ size_t count,
+ FILE *stream
+ )
+{
return 0;
}
+
/**
Write stream from file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-size_t fwrite (const void * ptr, size_t size, size_t count, FILE * stream) {
+size_t
+fwrite (
+ const void *ptr,
+ size_t size,
+ size_t count,
+ FILE *stream
+ )
+{
return 0;
}
+
/**
Close file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-int fclose (FILE * stream) {
+int
+fclose (
+ FILE *stream
+ )
+{
return EOF;
}
+
/**
Write the formatted string to file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-int fprintf (FILE * stream, const char * format, ...) {
+int
+fprintf (
+ FILE *stream,
+ const char *format,
+ ...
+ )
+{
return -1;
}
+
/**
This function check if this is the formating string specifier.
@@ -730,12 +875,12 @@ int fprintf (FILE * stream, const char * format, ...) {
**/
BOOLEAN
CheckFormatingString (
- IN CONST CHAR8 *FormatString,
- IN OUT UINTN *CurrentPosition,
- IN UINTN StrLength
+ IN CONST CHAR8 *FormatString,
+ IN OUT UINTN *CurrentPosition,
+ IN UINTN StrLength
)
{
- CHAR8 FormatStringParamater;
+ CHAR8 FormatStringParamater;
while (*(FormatString + *CurrentPosition) != 's') {
//
@@ -749,14 +894,17 @@ CheckFormatingString (
(FormatStringParamater != '*') &&
(FormatStringParamater != '.') &&
!(((UINTN)FormatStringParamater >= (UINTN)'0') && ((UINTN)FormatStringParamater <= (UINTN)'9'))
- ) {
+ )
+ {
return FALSE;
}
+
(*CurrentPosition)++;
if (*CurrentPosition >= StrLength) {
return FALSE;
}
- };
+ }
+
return TRUE;
}
@@ -772,15 +920,15 @@ CheckFormatingString (
**/
CHAR8 *
ReplaceUnicodeToAsciiStrFormat (
- IN CONST CHAR8 *FormatString
-)
+ IN CONST CHAR8 *FormatString
+ )
{
- UINTN FormatStrSize;
- UINTN FormatStrIndex;
- UINTN FormatStrSpecifier;
- BOOLEAN PercentageMark;
- CHAR8 *TempFormatBuffer;
- BOOLEAN IsFormatString;
+ UINTN FormatStrSize;
+ UINTN FormatStrIndex;
+ UINTN FormatStrSpecifier;
+ BOOLEAN PercentageMark;
+ CHAR8 *TempFormatBuffer;
+ BOOLEAN IsFormatString;
//
// Error checking.
@@ -788,15 +936,18 @@ ReplaceUnicodeToAsciiStrFormat (
if (FormatString == NULL) {
return NULL;
}
- FormatStrSize = AsciiStrSize(FormatString);
+
+ FormatStrSize = AsciiStrSize (FormatString);
if (FormatStrSize == 0) {
return NULL;
}
- TempFormatBuffer = AllocatePool(FormatStrSize); // Allocate memory for the
- // new string.
- if (TempFormatBuffer== NULL) {
+
+ TempFormatBuffer = AllocatePool (FormatStrSize); // Allocate memory for the
+ // new string.
+ if (TempFormatBuffer == NULL) {
return NULL;
}
+
//
// Clone *FormatString but replace "%s" wih "%a".
// "%%" is not considered as the format tag.
@@ -809,18 +960,21 @@ ReplaceUnicodeToAsciiStrFormat (
// Previous character is "%".
//
PercentageMark = FALSE;
- if (*(FormatString + FormatStrIndex) != '%') { // Check if this is double "%".
+ if (*(FormatString + FormatStrIndex) != '%') {
+ // Check if this is double "%".
FormatStrSpecifier = FormatStrIndex;
//
// Check if this is the formating string specifier.
//
IsFormatString = CheckFormatingString (FormatString, &FormatStrSpecifier, FormatStrSize);
if ((FormatStrSpecifier - FormatStrIndex) != 0) {
- CopyMem((VOID *)(TempFormatBuffer + FormatStrIndex),
- (VOID *)(FormatString + FormatStrIndex),
- FormatStrSpecifier - FormatStrIndex
- );
+ CopyMem (
+ (VOID *)(TempFormatBuffer + FormatStrIndex),
+ (VOID *)(FormatString + FormatStrIndex),
+ FormatStrSpecifier - FormatStrIndex
+ );
}
+
FormatStrIndex = FormatStrSpecifier;
if (IsFormatString == TRUE) {
//
@@ -828,18 +982,22 @@ ReplaceUnicodeToAsciiStrFormat (
// format on edk2 environment.
//
*(TempFormatBuffer + FormatStrSpecifier) = 'a';
- FormatStrIndex ++;
+ FormatStrIndex++;
}
+
continue;
}
+
goto ContinueCheck;
}
+
if (*(FormatString + FormatStrIndex) == '%') {
//
// This character is "%", set the flag.
//
PercentageMark = TRUE;
}
+
ContinueCheck:
//
// Clone character to the new string and advance FormatStrIndex
@@ -847,7 +1005,8 @@ ContinueCheck:
//
*(TempFormatBuffer + FormatStrIndex) = *(FormatString + FormatStrIndex);
FormatStrIndex++;
- };
+ }
+
return TempFormatBuffer;
}
@@ -870,14 +1029,14 @@ ContinueCheck:
UINTN
EFIAPI
RedfishAsciiVSPrint (
- OUT CHAR8 *StartOfBuffer,
- IN UINTN BufferSize,
- IN CONST CHAR8 *FormatString,
- IN VA_LIST Marker
+ OUT CHAR8 *StartOfBuffer,
+ IN UINTN BufferSize,
+ IN CONST CHAR8 *FormatString,
+ IN VA_LIST Marker
)
{
- CHAR8 *TempFormatBuffer;
- UINTN LenStrProduced;
+ CHAR8 *TempFormatBuffer;
+ UINTN LenStrProduced;
//
// Looking for "%s" in the format string and replace it
@@ -888,6 +1047,7 @@ RedfishAsciiVSPrint (
if (TempFormatBuffer == NULL) {
return 0;
}
+
LenStrProduced = AsciiVSPrint (StartOfBuffer, BufferSize, (CONST CHAR8 *)TempFormatBuffer, Marker);
FreePool (TempFormatBuffer);
return LenStrProduced;
@@ -919,11 +1079,10 @@ RedfishAsciiSPrint (
...
)
{
- VA_LIST Marker;
- UINTN LenStrProduced;
+ VA_LIST Marker;
+ UINTN LenStrProduced;
- VA_START(Marker, FormatString);
+ VA_START (Marker, FormatString);
LenStrProduced = RedfishAsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
return LenStrProduced;
}
-
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
index 18aa4646e8..9f9d37790e 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c
@@ -27,7 +27,7 @@
REDFISH_SERVICE
EFIAPI
RedfishCreateService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
)
{
REDFISH_SERVICE RedfishService;
@@ -69,7 +69,8 @@ ON_EXIT:
if (UserId != NULL) {
FreePool (UserId);
}
- if (Password!= NULL) {
+
+ if (Password != NULL) {
FreePool (Password);
}
@@ -85,7 +86,7 @@ ON_EXIT:
VOID
EFIAPI
RedfishCleanupService (
- IN REDFISH_SERVICE RedfishService
+ IN REDFISH_SERVICE RedfishService
)
{
if (RedfishService == NULL) {
@@ -94,6 +95,7 @@ RedfishCleanupService (
cleanupServiceEnumerator (RedfishService);
}
+
/**
Create REDFISH_PAYLOAD instance in local with JSON represented resource value and
the Redfish Service.
@@ -112,11 +114,11 @@ RedfishCleanupService (
REDFISH_PAYLOAD
EFIAPI
RedfishCreatePayload (
- IN EDKII_JSON_VALUE Value,
- IN REDFISH_SERVICE RedfishService
+ IN EDKII_JSON_VALUE Value,
+ IN REDFISH_SERVICE RedfishService
)
{
- EDKII_JSON_VALUE CopyValue;
+ EDKII_JSON_VALUE CopyValue;
CopyValue = JsonValueClone (Value);
return createRedfishPayload (CopyValue, RedfishService);
@@ -131,14 +133,14 @@ RedfishCreatePayload (
VOID
EFIAPI
RedfishCleanupPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
if (Payload == NULL) {
return;
}
- cleanupPayload ((redfishPayload *) Payload);
+ cleanupPayload ((redfishPayload *)Payload);
}
/**
@@ -155,14 +157,14 @@ RedfishCleanupPayload (
EDKII_JSON_VALUE
EFIAPI
RedfishJsonInPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
if (Payload == NULL) {
return NULL;
}
- return ((redfishPayload*)Payload)->json;
+ return ((redfishPayload *)Payload)->json;
}
/**
@@ -187,15 +189,15 @@ RedfishJsonInPayload (
CHAR8 *
EFIAPI
RedfishBuildPathWithSystemUuid (
- IN CONST CHAR8 *RedPath,
- IN BOOLEAN FromSmbios,
- IN CHAR8 *IdString OPTIONAL
+ IN CONST CHAR8 *RedPath,
+ IN BOOLEAN FromSmbios,
+ IN CHAR8 *IdString OPTIONAL
)
{
- UINTN BufSize;
- CHAR8* RetRedPath;
- EFI_GUID SystemUuid;
- EFI_STATUS Status;
+ UINTN BufSize;
+ CHAR8 *RetRedPath;
+ EFI_GUID SystemUuid;
+ EFI_STATUS Status;
if (RedPath == NULL) {
return NULL;
@@ -205,10 +207,11 @@ RedfishBuildPathWithSystemUuid (
// Find system UUID from SMBIOS table.
//
if (FromSmbios) {
- Status = NetLibGetSystemGuid(&SystemUuid);
+ Status = NetLibGetSystemGuid (&SystemUuid);
if (EFI_ERROR (Status)) {
return NULL;
}
+
// AsciiStrLen ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") = 36
BufSize = AsciiStrSize (RedPath) + AsciiStrLen ("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
} else {
@@ -219,13 +222,16 @@ RedfishBuildPathWithSystemUuid (
if (RetRedPath == NULL) {
return NULL;
}
+
if (FromSmbios) {
AsciiSPrint (RetRedPath, BufSize, RedPath, &SystemUuid);
} else {
AsciiSPrint (RetRedPath, BufSize, RedPath, IdString);
}
+
return RetRedPath;
}
+
/**
Get a redfish response addressed by a RedPath string, including HTTP StatusCode, Headers
and Payload which record any HTTP response messages.
@@ -252,24 +258,24 @@ RedfishBuildPathWithSystemUuid (
EFI_STATUS
EFIAPI
RedfishGetByService (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (RedfishService == NULL || RedPath == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) getPayloadByPath (RedfishService, RedPath, &(RedResponse->StatusCode));
+ RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadByPath (RedfishService, RedPath, &(RedResponse->StatusCode));
//
// 1. If the returned Payload is NULL, indicates any error happen.
// 2. If the returned StatusCode is NULL, indicates any error happen.
//
- if (RedResponse->Payload == NULL || RedResponse->StatusCode == NULL) {
+ if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
return EFI_DEVICE_ERROR;
}
@@ -278,13 +284,15 @@ RedfishGetByService (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Get a redfish response addressed by URI, including HTTP StatusCode, Headers
and Payload which record any HTTP response messages.
@@ -310,27 +318,27 @@ RedfishGetByService (
EFI_STATUS
EFIAPI
RedfishGetByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EDKII_JSON_VALUE JsonValue;
+ EDKII_JSON_VALUE JsonValue;
- if (RedfishService == NULL || Uri == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = getUriFromService (RedfishService, Uri, &RedResponse->StatusCode);
- RedResponse->Payload = createRedfishPayload(JsonValue, RedfishService);
+ JsonValue = getUriFromService (RedfishService, Uri, &RedResponse->StatusCode);
+ RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
//
// 1. If the returned Payload is NULL, indicates any error happen.
// 2. If the returned StatusCode is NULL, indicates any error happen.
//
- if (RedResponse->Payload == NULL || RedResponse->StatusCode == NULL) {
+ if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
return EFI_DEVICE_ERROR;
}
@@ -339,12 +347,15 @@ RedfishGetByUri (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
+
return EFI_SUCCESS;
}
+
/**
Get a redfish response addressed by the input Payload and relative RedPath string,
including HTTP StatusCode, Headers and Payload which record any HTTP response messages.
@@ -374,18 +385,18 @@ RedfishGetByUri (
EFI_STATUS
EFIAPI
RedfishGetByPayload (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Payload == NULL || RedPath == NULL || RedResponse == NULL) {
+ if ((Payload == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) getPayloadForPathString (Payload, RedPath, &(RedResponse->StatusCode));
+ RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadForPathString (Payload, RedPath, &(RedResponse->StatusCode));
//
// 1. If the returned Payload is NULL, indicates any error happen.
@@ -400,15 +411,17 @@ RedfishGetByPayload (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (RedResponse->StatusCode != NULL && \
- (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT
- )) {
+ if ((RedResponse->StatusCode != NULL) && \
+ ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)
+ ))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP PATCH to perform updates on pre-existing Redfish resource.
@@ -442,30 +455,30 @@ RedfishGetByPayload (
EFI_STATUS
EFIAPI
RedfishPatchToUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- IN CONST CHAR8 *Content,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ IN CONST CHAR8 *Content,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EFI_STATUS Status;
- EDKII_JSON_VALUE JsonValue;
+ EFI_STATUS Status;
+ EDKII_JSON_VALUE JsonValue;
Status = EFI_SUCCESS;
JsonValue = NULL;
- if (RedfishService == NULL || Uri == NULL || Content == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = (EDKII_JSON_VALUE) patchUriFromService (
- RedfishService,
- Uri,
- Content,
- &(RedResponse->StatusCode)
- );
+ JsonValue = (EDKII_JSON_VALUE)patchUriFromService (
+ RedfishService,
+ Uri,
+ Content,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -480,8 +493,9 @@ RedfishPatchToUri (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
Status = EFI_DEVICE_ERROR;
}
@@ -499,6 +513,7 @@ ON_EXIT:
return Status;
}
+
/**
Use HTTP PATCH to perform updates on target payload. Patch to odata.id in Payload directly.
@@ -530,22 +545,22 @@ ON_EXIT:
EFI_STATUS
EFIAPI
RedfishPatchToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Target == NULL || Payload == NULL || RedResponse == NULL) {
+ if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) patchPayload (
- Target,
- Payload,
- &(RedResponse->StatusCode)
- );
+ RedResponse->Payload = (REDFISH_PAYLOAD)patchPayload (
+ Target,
+ Payload,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -559,13 +574,15 @@ RedfishPatchToPayload (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP POST to create a new resource in target payload.
@@ -596,22 +613,22 @@ RedfishPatchToPayload (
EFI_STATUS
EFIAPI
RedfishPostToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Target == NULL || Payload == NULL || RedResponse == NULL) {
+ if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) postPayload (
- Target,
- Payload,
- &(RedResponse->StatusCode)
- );
+ RedResponse->Payload = (REDFISH_PAYLOAD)postPayload (
+ Target,
+ Payload,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -625,13 +642,15 @@ RedfishPostToPayload (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP DELETE to remove a resource.
@@ -662,28 +681,28 @@ RedfishPostToPayload (
EFI_STATUS
EFIAPI
RedfishDeleteByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EFI_STATUS Status;
- EDKII_JSON_VALUE JsonValue;
+ EFI_STATUS Status;
+ EDKII_JSON_VALUE JsonValue;
Status = EFI_SUCCESS;
JsonValue = NULL;
- if (RedfishService == NULL || Uri == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = (EDKII_JSON_VALUE) deleteUriFromService (
- RedfishService,
- Uri,
- &(RedResponse->StatusCode)
- );
+ JsonValue = (EDKII_JSON_VALUE)deleteUriFromService (
+ RedfishService,
+ Uri,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -698,8 +717,9 @@ RedfishDeleteByUri (
// NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
Status = EFI_DEVICE_ERROR;
}
@@ -717,6 +737,7 @@ ON_EXIT:
return Status;
}
+
/**
Dump text in fractions.
@@ -725,37 +746,40 @@ ON_EXIT:
**/
VOID
RedfishDumpJsonStringFractions (
- IN CHAR8 *String
+ IN CHAR8 *String
)
{
- CHAR8 *NextFraction;
- UINTN StringFractionSize;
- UINTN StrLen;
- UINTN Count;
- CHAR8 BackupChar;
+ CHAR8 *NextFraction;
+ UINTN StringFractionSize;
+ UINTN StrLen;
+ UINTN Count;
+ CHAR8 BackupChar;
StringFractionSize = 200;
if (String == NULL) {
- return ;
+ return;
}
- DEBUG((DEBUG_INFO, "JSON text:\n"));
+ DEBUG ((DEBUG_INFO, "JSON text:\n"));
NextFraction = String;
- StrLen = AsciiStrLen (String);
+ StrLen = AsciiStrLen (String);
if (StrLen == 0) {
return;
}
+
for (Count = 0; Count < (StrLen / StringFractionSize); Count++) {
- BackupChar = *(NextFraction + StringFractionSize);
+ BackupChar = *(NextFraction + StringFractionSize);
*(NextFraction + StringFractionSize) = 0;
- DEBUG((DEBUG_INFO, "%a", NextFraction));
+ DEBUG ((DEBUG_INFO, "%a", NextFraction));
*(NextFraction + StringFractionSize) = BackupChar;
- NextFraction += StringFractionSize;
+ NextFraction += StringFractionSize;
}
+
if ((StrLen % StringFractionSize) != 0) {
- DEBUG((DEBUG_INFO, "%a\n\n", NextFraction));
+ DEBUG ((DEBUG_INFO, "%a\n\n", NextFraction));
}
}
+
/**
Dump text in JSON value.
@@ -767,15 +791,17 @@ RedfishDumpJson (
IN EDKII_JSON_VALUE JsonValue
)
{
- CHAR8 *String;
+ CHAR8 *String;
String = JsonDumpString (JsonValue, 0);
if (String == NULL) {
return;
}
+
RedfishDumpJsonStringFractions (String);
- FreePool(String);
+ FreePool (String);
}
+
/**
Extract the JSON text content from REDFISH_PAYLOAD and dump to debug console.
@@ -784,14 +810,14 @@ RedfishDumpJson (
**/
VOID
RedfishDumpPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
- EDKII_JSON_VALUE JsonValue;
- CHAR8 *String;
+ EDKII_JSON_VALUE JsonValue;
+ CHAR8 *String;
JsonValue = NULL;
- String = NULL;
+ String = NULL;
if (Payload == NULL) {
return;
@@ -808,8 +834,9 @@ RedfishDumpPayload (
}
RedfishDumpJsonStringFractions (String);
- FreePool(String);
+ FreePool (String);
}
+
/**
This function will cleanup the HTTP header and Redfish payload resources.
@@ -832,8 +859,8 @@ RedfishFreeResponse (
StatusCode = NULL;
}
- if (HeaderCount != 0 && Headers != NULL) {
- HttpFreeHeaderFields(Headers, HeaderCount);
+ if ((HeaderCount != 0) && (Headers != NULL)) {
+ HttpFreeHeaderFields (Headers, HeaderCount);
Headers = NULL;
}
@@ -842,6 +869,7 @@ RedfishFreeResponse (
Payload = NULL;
}
}
+
/**
Check if the "@odata.type" in Payload is valid or not.
@@ -855,17 +883,17 @@ RedfishFreeResponse (
**/
BOOLEAN
RedfishIsValidOdataType (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *OdataTypeName,
- IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
- IN UINTN OdataTypeMappingListSize
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *OdataTypeName,
+ IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
+ IN UINTN OdataTypeMappingListSize
)
{
- UINTN Index;
- EDKII_JSON_VALUE OdataType;
- EDKII_JSON_VALUE JsonValue;
+ UINTN Index;
+ EDKII_JSON_VALUE OdataType;
+ EDKII_JSON_VALUE JsonValue;
- if (Payload == NULL || OdataTypeName == NULL) {
+ if ((Payload == NULL) || (OdataTypeName == NULL)) {
return FALSE;
}
@@ -875,19 +903,22 @@ RedfishIsValidOdataType (
}
OdataType = JsonObjectGetValue (JsonValueGetObject (JsonValue), "@odata.type");
- if (!JsonValueIsString (OdataType) || JsonValueGetAsciiString (OdataType) == NULL) {
+ if (!JsonValueIsString (OdataType) || (JsonValueGetAsciiString (OdataType) == NULL)) {
return FALSE;
}
- for (Index = 0; Index < OdataTypeMappingListSize; Index ++) {
- if (AsciiStrCmp (OdataTypeMappingList[Index].OdataTypeName, OdataTypeName) == 0 &&
- AsciiStrCmp (OdataTypeMappingList[Index].OdataType, JsonValueGetAsciiString (OdataType)) == 0) {
+ for (Index = 0; Index < OdataTypeMappingListSize; Index++) {
+ if ((AsciiStrCmp (OdataTypeMappingList[Index].OdataTypeName, OdataTypeName) == 0) &&
+ (AsciiStrCmp (OdataTypeMappingList[Index].OdataType, JsonValueGetAsciiString (OdataType)) == 0))
+ {
return TRUE;
}
}
+
DEBUG ((DEBUG_INFO, "%a: This Odata type is not in the list.\n", __FUNCTION__));
return FALSE;
}
+
/**
Check if the payload is collection
@@ -898,11 +929,12 @@ RedfishIsValidOdataType (
**/
BOOLEAN
RedfishIsPayloadCollection (
- IN REDFISH_PAYLOAD Payload
-)
+ IN REDFISH_PAYLOAD Payload
+ )
{
return isPayloadCollection (Payload);
}
+
/**
Get collection size.
@@ -913,21 +945,23 @@ RedfishIsPayloadCollection (
@return EFI_INVALID_PARAMETER The payload is not a collection.
**/
EFI_STATUS
-RedfishGetCollectionSize(
- IN REDFISH_PAYLOAD Payload,
- IN UINTN *CollectionSize
+RedfishGetCollectionSize (
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN *CollectionSize
)
{
- if (Payload == NULL || CollectionSize == NULL) {
+ if ((Payload == NULL) || (CollectionSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
- if (!RedfishIsPayloadCollection(Payload)) {
+
+ if (!RedfishIsPayloadCollection (Payload)) {
return EFI_INVALID_PARAMETER;
}
- *CollectionSize = (UINTN)getCollectionSize(Payload);
+ *CollectionSize = (UINTN)getCollectionSize (Payload);
return EFI_SUCCESS;
}
+
/**
Get Redfish payload of collection member
@@ -939,20 +973,23 @@ RedfishGetCollectionSize(
**/
REDFISH_PAYLOAD
RedfishGetPayloadByIndex (
- IN REDFISH_PAYLOAD Payload,
- IN UINTN Index
-)
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN Index
+ )
{
- REDFISH_RESPONSE RedfishResponse;
- REDFISH_PAYLOAD PayloadReturn;
+ REDFISH_RESPONSE RedfishResponse;
+ REDFISH_PAYLOAD PayloadReturn;
PayloadReturn = (VOID *)getPayloadByIndex (Payload, Index, &RedfishResponse.StatusCode);
- if(PayloadReturn == NULL ||
- (*(RedfishResponse.StatusCode) < HTTP_STATUS_200_OK && *(RedfishResponse.StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)){
+ if ((PayloadReturn == NULL) ||
+ ((*(RedfishResponse.StatusCode) < HTTP_STATUS_200_OK) && (*(RedfishResponse.StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)))
+ {
return NULL;
}
+
return PayloadReturn;
}
+
/**
Check and return Redfish resource of the given Redpath.
@@ -964,30 +1001,33 @@ RedfishGetPayloadByIndex (
**/
EFI_STATUS
RedfishCheckIfRedpathExist (
- IN REDFISH_SERVICE RedfishService,
- IN CHAR8 *Redpath,
- IN REDFISH_RESPONSE *Response OPTIONAL
+ IN REDFISH_SERVICE RedfishService,
+ IN CHAR8 *Redpath,
+ IN REDFISH_RESPONSE *Response OPTIONAL
)
{
- EFI_STATUS Status;
- REDFISH_RESPONSE TempResponse;
+ EFI_STATUS Status;
+ REDFISH_RESPONSE TempResponse;
if (Redpath == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Status = RedfishGetByService (RedfishService, Redpath, &TempResponse);
if (EFI_ERROR (Status)) {
return Status;
}
+
if (Response == NULL) {
- RedfishFreeResponse(
+ RedfishFreeResponse (
TempResponse.StatusCode,
TempResponse.HeaderCount,
TempResponse.Headers,
TempResponse.Payload
- );
+ );
} else {
CopyMem ((VOID *)Response, (VOID *)&TempResponse, sizeof (REDFISH_RESPONSE));
}
+
return EFI_SUCCESS;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
index 7077c37154..0eb23196d2 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c
@@ -10,7 +10,7 @@
#include "RedfishMisc.h"
-EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
+EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
/**
This function returns the string of Redfish service version.
@@ -23,25 +23,28 @@ EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
**/
EFI_STATUS
RedfishGetServiceVersion (
- IN REDFISH_SERVICE RedfishService,
- OUT CHAR8 **ServiceVersionStr
+ IN REDFISH_SERVICE RedfishService,
+ OUT CHAR8 **ServiceVersionStr
)
{
- redfishService *Redfish;
- CHAR8 **KeysArray;
- UINTN KeysNum;
+ redfishService *Redfish;
+ CHAR8 **KeysArray;
+ UINTN KeysNum;
- if (RedfishService == NULL || ServiceVersionStr == NULL) {
+ if ((RedfishService == NULL) || (ServiceVersionStr == NULL)) {
return EFI_INVALID_PARAMETER;
}
+
Redfish = (redfishService *)RedfishService;
if (Redfish->versions == NULL) {
return EFI_INVALID_PARAMETER;
}
+
KeysArray = JsonObjectGetKeys (Redfish->versions, &KeysNum);
- if (KeysNum == 0 || KeysArray == NULL) {
+ if ((KeysNum == 0) || (KeysArray == NULL)) {
return EFI_NOT_FOUND;
}
+
*ServiceVersionStr = *KeysArray;
return EFI_SUCCESS;
}
@@ -65,18 +68,17 @@ RedfishGetServiceVersion (
**/
REDFISH_SERVICE
RedfishCreateLibredfishService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
- IN CHAR8 *UserId,
- IN CHAR8 *Password
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
+ IN CHAR8 *UserId,
+ IN CHAR8 *Password
)
{
+ UINTN Flags;
+ enumeratorAuthentication Auth;
+ redfishService *Redfish;
- UINTN Flags;
- enumeratorAuthentication Auth;
- redfishService* Redfish;
-
- Redfish = NULL;
+ Redfish = NULL;
ZeroMem (&Auth, sizeof (Auth));
if (AuthMethod == AuthMethodHttpBasic) {
@@ -84,25 +86,26 @@ RedfishCreateLibredfishService (
} else if (AuthMethod == AuthMethodRedfishSession) {
Auth.authType = REDFISH_AUTH_SESSION;
}
+
Auth.authCodes.userPass.username = UserId;
Auth.authCodes.userPass.password = Password;
Flags = REDFISH_FLAG_SERVICE_NO_VERSION_DOC;
if (AuthMethod != AuthMethodNone) {
- Redfish = createServiceEnumerator(RedfishConfigServiceInfo, NULL, &Auth, (unsigned int ) Flags);
+ Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, &Auth, (unsigned int)Flags);
} else {
- Redfish = createServiceEnumerator(RedfishConfigServiceInfo, NULL, NULL, (unsigned int) Flags);
+ Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, NULL, (unsigned int)Flags);
}
//
// Zero the Password after use.
//
if (Password != NULL) {
- ZeroMem (Password, AsciiStrLen(Password));
+ ZeroMem (Password, AsciiStrLen (Password));
}
- return (REDFISH_SERVICE) Redfish;
+ return (REDFISH_SERVICE)Redfish;
}
/**
@@ -130,14 +133,14 @@ RedfishCreateLibredfishService (
**/
EFI_STATUS
RedfishGetAuthInfo (
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ OUT CHAR8 **Password
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- if (AuthMethod == NULL || UserId == NULL || Password == NULL) {
+ if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -161,6 +164,7 @@ RedfishGetAuthInfo (
return Status;
}
+
/**
This function returns the string of Redfish service version.
@@ -175,15 +179,15 @@ RedfishGetAuthInfo (
**/
EFI_STATUS
RedfishBuildRedpathUseId (
- IN CHAR8 *ServiceVerisonStr,
- IN CHAR8 *Url,
- IN CHAR8 *Id,
- OUT CHAR8 **Redpath
+ IN CHAR8 *ServiceVerisonStr,
+ IN CHAR8 *Url,
+ IN CHAR8 *Id,
+ OUT CHAR8 **Redpath
)
{
- UINTN RedpathSize;
+ UINTN RedpathSize;
- if (Redpath == NULL || ServiceVerisonStr == NULL || Url == NULL || Id == NULL) {
+ if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -192,10 +196,11 @@ RedfishBuildRedpathUseId (
AsciiStrLen (Url) +
AsciiStrLen ("[Id=]") +
AsciiStrLen (Id) + 1;
- *Redpath = AllocatePool(RedpathSize);
+ *Redpath = AllocatePool (RedpathSize);
if (*Redpath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url, Id);
return EFI_SUCCESS;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h
index d01a433d1a..3b066c1172 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h
@@ -22,7 +22,7 @@
#include <Protocol/EdkIIRedfishCredential.h>
#include <redfish.h>
-#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
+#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
/**
Creates a REDFISH_SERVICE which can be later used to access the Redfish resources.
@@ -43,10 +43,10 @@
**/
REDFISH_SERVICE
RedfishCreateLibredfishService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
- IN CHAR8 *UserId,
- IN CHAR8 *Password
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
+ IN CHAR8 *UserId,
+ IN CHAR8 *Password
);
/**
@@ -74,9 +74,9 @@ RedfishCreateLibredfishService (
**/
EFI_STATUS
RedfishGetAuthInfo (
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ OUT CHAR8 **Password
);
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h
index de1feb22fb..e9b9b3fa55 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h
@@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDFISH_H_
#define LIBREDFISH_REDFISH_H_
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
index 43149f3c89..445153060a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
@@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDFISH_PAYLOAD_H_
#define LIBREDFISH_REDFISH_PAYLOAD_H_
@@ -23,17 +24,83 @@
#include <redfishService.h>
#include <redpath.h>
-redfishPayload* createRedfishPayload(json_t* value, redfishService* service);
-redfishPayload* getPayloadByNodeName(redfishPayload* payload, const char* nodeName, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadByIndex(redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadForPath(redfishPayload* payload, redPathNode* redpath, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadForPathString(redfishPayload* payload, const char* string, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* patchPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* postContentToPayload(redfishPayload* target, const char* data, size_t dataSize, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
-void cleanupPayload(redfishPayload* payload);
-bool isPayloadCollection (redfishPayload *Payload);
-size_t getCollectionSize(redfishPayload* payload);
-redfishPayload* getPayloadByIndex (redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
+redfishPayload *
+createRedfishPayload (
+ json_t *value,
+ redfishService *service
+ );
+
+redfishPayload *
+getPayloadByNodeName (
+ redfishPayload *payload,
+ const char *nodeName,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadForPath (
+ redfishPayload *payload,
+ redPathNode *redpath,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadForPathString (
+ redfishPayload *payload,
+ const char *string,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+patchPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+postContentToPayload (
+ redfishPayload *target,
+ const char *data,
+ size_t dataSize,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+postPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+void
+cleanupPayload (
+ redfishPayload *payload
+ );
+
+bool
+isPayloadCollection (
+ redfishPayload *Payload
+ );
+
+size_t
+getCollectionSize (
+ redfishPayload *payload
+ );
+
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
index 0215caccfc..5c13b682a3 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
@@ -38,64 +38,114 @@
#include <jansson.h>
typedef struct {
- char* host;
- json_t* versions;
- unsigned int flags;
- char* sessionToken;
- char* basicAuthStr;
- //
- // point to the <HOST> part in above "host" field, which will be put into
- // the "Host" header of HTTP request message.
- //
- char* HostHeaderValue;
- EFI_REST_EX_PROTOCOL *RestEx;
+ char *host;
+ json_t *versions;
+ unsigned int flags;
+ char *sessionToken;
+ char *basicAuthStr;
+ //
+ // point to the <HOST> part in above "host" field, which will be put into
+ // the "Host" header of HTTP request message.
+ //
+ char *HostHeaderValue;
+ EFI_REST_EX_PROTOCOL *RestEx;
} redfishService;
typedef struct {
- json_t* json;
- redfishService* service;
+ json_t *json;
+ redfishService *service;
} redfishPayload;
-#define REDFISH_AUTH_BASIC 0
-#define REDFISH_AUTH_BEARER_TOKEN 1
-#define REDFISH_AUTH_SESSION 2
+#define REDFISH_AUTH_BASIC 0
+#define REDFISH_AUTH_BEARER_TOKEN 1
+#define REDFISH_AUTH_SESSION 2
-#define REDFISH_HTTP_RESPONSE_TIMEOUT 5000 /// 5 seconds in uints of millisecond.
+#define REDFISH_HTTP_RESPONSE_TIMEOUT 5000 /// 5 seconds in uints of millisecond.
///
/// Library class public defines
///
-#define HTTP_FLAG L"http://"
-#define HTTPS_FLAG L"https://"
+#define HTTP_FLAG L"http://"
+#define HTTPS_FLAG L"https://"
///
/// The redfish first URL should be "/redfish/v1/", while we use "/redfish/v1" here without "/"
/// in the end is to avoid the 301 Perment redirect response from Redfish profile simulator.
///
-#define REDFISH_FIRST_URL L"/redfish/v1"
+#define REDFISH_FIRST_URL L"/redfish/v1"
typedef struct {
- unsigned int authType;
- union {
- struct {
- char* username;
- char* password;
- } userPass;
- struct {
- char* token;
- } authToken;
- } authCodes;
+ unsigned int authType;
+ union {
+ struct {
+ char *username;
+ char *password;
+ } userPass;
+ struct {
+ char *token;
+ } authToken;
+ } authCodes;
} enumeratorAuthentication;
-//Values for flags
-#define REDFISH_FLAG_SERVICE_NO_VERSION_DOC 0x00000001 //The Redfish Service lacks the version document (in violation of the Redfish spec)
-redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, const char* rootUri, enumeratorAuthentication* auth, unsigned int flags);
-json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* patchUriFromService(redfishService* service, const char* uri, const char* content, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* postUriFromService(redfishService* service, const char* uri, const char* content, size_t contentLength, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getRedfishServiceRoot(redfishService* service, const char* version, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadByPath(redfishService* service, const char* path, EFI_HTTP_STATUS_CODE** StatusCode);
-void cleanupServiceEnumerator(redfishService* service);
+// Values for flags
+#define REDFISH_FLAG_SERVICE_NO_VERSION_DOC 0x00000001// The Redfish Service lacks the version document (in violation of the Redfish spec)
+redfishService *
+createServiceEnumerator (
+ REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ const char *rootUri,
+ enumeratorAuthentication *auth,
+ unsigned int flags
+ );
+
+json_t *
+getUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+patchUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+postUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ size_t contentLength,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+deleteUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getRedfishServiceRoot (
+ redfishService *service,
+ const char *version,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadByPath (
+ redfishService *service,
+ const char *path,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+void
+cleanupServiceEnumerator (
+ redfishService *service
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
index 24413a648a..c1a1568bf0 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
@@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDPATH_H_
#define LIBREDFISH_REDPATH_H_
@@ -21,22 +22,28 @@
#include <jansson.h>
-typedef struct _redPathNode
-{
- bool isRoot;
- bool isIndex;
+typedef struct _redPathNode {
+ bool isRoot;
+ bool isIndex;
- char* version;
- char* nodeName;
- size_t index;
- char* op;
- char* propName;
- char* value;
+ char *version;
+ char *nodeName;
+ size_t index;
+ char *op;
+ char *propName;
+ char *value;
- struct _redPathNode* next;
+ struct _redPathNode *next;
} redPathNode;
-redPathNode* parseRedPath(const char* path);
-void cleanupRedPath(redPathNode* node);
+redPathNode *
+parseRedPath (
+ const char *path
+ );
+
+void
+cleanupRedPath (
+ redPathNode *node
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c
index 3d60acd926..3f2b83e834 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c
@@ -16,717 +16,797 @@
**/
#include <redfishPayload.h>
-static redfishPayload* getOpResult(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* collectionEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* arrayEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* createCollection(redfishService* service, size_t count, redfishPayload** payloads);
-static json_t* json_object_get_by_index(json_t* json, size_t index);
-
-bool isPayloadCollection(redfishPayload* payload)
+static redfishPayload *
+getOpResult (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+collectionEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+arrayEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+createCollection (
+ redfishService *service,
+ size_t count,
+ redfishPayload **payloads
+ );
+
+static json_t *
+json_object_get_by_index (
+ json_t *json,
+ size_t index
+ );
+
+bool
+isPayloadCollection (
+ redfishPayload *payload
+ )
{
- json_t* members;
- json_t* count;
+ json_t *members;
+ json_t *count;
- if(!payload || !json_is_object(payload->json))
- {
- return false;
- }
- members = json_object_get(payload->json, "Members");
- count = json_object_get(payload->json, "Members@odata.count");
- return ((members != NULL) && (count != NULL));
+ if (!payload || !json_is_object (payload->json)) {
+ return false;
+ }
+
+ members = json_object_get (payload->json, "Members");
+ count = json_object_get (payload->json, "Members@odata.count");
+ return ((members != NULL) && (count != NULL));
}
-size_t getCollectionSize(redfishPayload* payload)
+size_t
+getCollectionSize (
+ redfishPayload *payload
+ )
{
- json_t* members;
- json_t* count;
+ json_t *members;
+ json_t *count;
- if(!payload || !json_is_object(payload->json))
- {
- return 0;
- }
- members = json_object_get(payload->json, "Members");
- count = json_object_get(payload->json, "Members@odata.count");
- if(!members || !count)
- {
- return 0;
- }
- return (size_t)json_integer_value(count);
+ if (!payload || !json_is_object (payload->json)) {
+ return 0;
+ }
+
+ members = json_object_get (payload->json, "Members");
+ count = json_object_get (payload->json, "Members@odata.count");
+ if (!members || !count) {
+ return 0;
+ }
+
+ return (size_t)json_integer_value (count);
}
-bool isPayloadArray(redfishPayload* payload)
+bool
+isPayloadArray (
+ redfishPayload *payload
+ )
{
- if(!payload || !json_is_array(payload->json))
- {
- return false;
- }
- return true;
+ if (!payload || !json_is_array (payload->json)) {
+ return false;
+ }
+
+ return true;
}
-char* payloadToString(redfishPayload* payload, bool prettyPrint)
+char *
+payloadToString (
+ redfishPayload *payload,
+ bool prettyPrint
+ )
{
- size_t flags = 0;
- if(!payload)
- {
- return NULL;
- }
- if(prettyPrint)
- {
- flags = JSON_INDENT(2);
- }
- return json_dumps(payload->json, flags);
+ size_t flags = 0;
+
+ if (!payload) {
+ return NULL;
+ }
+
+ if (prettyPrint) {
+ flags = JSON_INDENT (2);
+ }
+
+ return json_dumps (payload->json, flags);
}
-redfishPayload* createRedfishPayload(json_t* value, redfishService* service)
+redfishPayload *
+createRedfishPayload (
+ json_t *value,
+ redfishService *service
+ )
{
- redfishPayload* payload;
- payload = (redfishPayload*)malloc(sizeof(redfishPayload));
- if(payload != NULL)
- {
- payload->json = value;
- payload->service = service;
- }
- return payload;
+ redfishPayload *payload;
+
+ payload = (redfishPayload *)malloc (sizeof (redfishPayload));
+ if (payload != NULL) {
+ payload->json = value;
+ payload->service = service;
+ }
+
+ return payload;
}
-redfishPayload* getPayloadByNodeName(redfishPayload* payload, const char* nodeName, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByNodeName (
+ redfishPayload *payload,
+ const char *nodeName,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value;
- json_t* odataId;
- const char* uri;
+ json_t *value;
+ json_t *odataId;
+ const char *uri;
- if(!payload || !nodeName || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!payload || !nodeName || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- value = json_object_get(payload->json, nodeName);
- if(value == NULL)
- {
+ value = json_object_get (payload->json, nodeName);
+ if (value == NULL) {
+ return NULL;
+ }
+
+ json_incref (value);
+ if (json_object_size (value) == 1) {
+ odataId = json_object_get (value, "@odata.id");
+ if (odataId != NULL) {
+ json_incref (odataId);
+ uri = json_string_value (odataId);
+ json_decref (value);
+ value = getUriFromService (payload->service, uri, StatusCode);
+ json_decref (odataId);
+ if ((value == NULL) || (*StatusCode == NULL)) {
return NULL;
- }
- json_incref(value);
- if(json_object_size(value) == 1)
- {
- odataId = json_object_get(value, "@odata.id");
- if(odataId != NULL)
- {
- json_incref(odataId);
- uri = json_string_value(odataId);
- json_decref(value);
- value = getUriFromService(payload->service, uri, StatusCode);
- json_decref(odataId);
- if(value == NULL || *StatusCode == NULL)
- {
- return NULL;
- }
- }
- }
- if (*StatusCode == NULL || (**StatusCode >= HTTP_STATUS_200_OK && **StatusCode <= HTTP_STATUS_206_PARTIAL_CONTENT)) {
- if(json_is_string(value))
- {
- odataId = json_object();
- json_object_set(odataId, nodeName, value);
- json_decref(value);
- value = odataId;
}
}
+ }
+
+ if ((*StatusCode == NULL) || ((**StatusCode >= HTTP_STATUS_200_OK) && (**StatusCode <= HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ if (json_is_string (value)) {
+ odataId = json_object ();
+ json_object_set (odataId, nodeName, value);
+ json_decref (value);
+ value = odataId;
+ }
+ }
- return createRedfishPayload(value, payload->service);
+ return createRedfishPayload (value, payload->service);
}
-redfishPayload* getPayloadByIndex(redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value = NULL;
- json_t* odataId;
- const char* uri;
- BOOLEAN FromServerFlag = FALSE;
+ json_t *value = NULL;
+ json_t *odataId;
+ const char *uri;
+ BOOLEAN FromServerFlag = FALSE;
- if(!payload || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!payload || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- if(isPayloadCollection(payload))
+ if (isPayloadCollection (payload)) {
+ redfishPayload *members = getPayloadByNodeName (payload, "Members", StatusCode);
+ if (((*StatusCode == NULL) && (members == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- redfishPayload* members = getPayloadByNodeName(payload, "Members", StatusCode);
- if ((*StatusCode == NULL && members == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return members;
- }
+ return members;
+ }
- if (*StatusCode != NULL) {
- //
- // The Payload (members) are retrived from server.
- //
- FreePool (*StatusCode);
- *StatusCode = NULL;
- FromServerFlag = TRUE;
- }
+ if (*StatusCode != NULL) {
+ //
+ // The Payload (members) are retrived from server.
+ //
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ FromServerFlag = TRUE;
+ }
+
+ redfishPayload *ret = getPayloadByIndex (members, index, StatusCode);
+ if ((*StatusCode == NULL) && (ret != NULL) && FromServerFlag) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (members) directly.
+ // Since the members are retrived from server, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ ret = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
+ }
+ }
- redfishPayload* ret = getPayloadByIndex(members, index, StatusCode);
- if (*StatusCode == NULL && ret != NULL && FromServerFlag) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (members) directly.
- // Since the members are retrived from server, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- ret = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
- }
+ cleanupPayload (members);
+ return ret;
+ }
- cleanupPayload(members);
- return ret;
- }
+ if (json_is_array (payload->json)) {
+ //
+ // The valid range for index is from 0 to the return value of json_array_size() minus 1
+ //
+ value = json_array_get (payload->json, index);
+ } else if (json_is_object (payload->json)) {
+ value = json_object_get_by_index (payload->json, index);
+ }
- if(json_is_array(payload->json))
- {
- //
- // The valid range for index is from 0 to the return value of json_array_size() minus 1
- //
- value = json_array_get(payload->json, index);
- }
- else if(json_is_object(payload->json))
- {
- value = json_object_get_by_index(payload->json, index);
- }
+ if (value == NULL) {
+ return NULL;
+ }
- if(value == NULL)
- {
+ json_incref (value);
+ if (json_object_size (value) == 1) {
+ odataId = json_object_get (value, "@odata.id");
+ if (odataId != NULL) {
+ uri = json_string_value (odataId);
+ json_decref (value);
+ value = getUriFromService (payload->service, uri, StatusCode);
+ if (value == NULL) {
return NULL;
+ }
}
+ }
- json_incref(value);
- if(json_object_size(value) == 1)
- {
- odataId = json_object_get(value, "@odata.id");
- if(odataId != NULL)
- {
- uri = json_string_value(odataId);
- json_decref(value);
- value = getUriFromService(payload->service, uri, StatusCode);
- if(value == NULL)
- {
- return NULL;
- }
- }
- }
- return createRedfishPayload(value, payload->service);
+ return createRedfishPayload (value, payload->service);
}
-redfishPayload* getPayloadForPath(redfishPayload* payload, redPathNode* redpath, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadForPath (
+ redfishPayload *payload,
+ redPathNode *redpath,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret = NULL;
- redfishPayload* tmp;
+ redfishPayload *ret = NULL;
+ redfishPayload *tmp;
- if(!payload || !redpath || StatusCode == NULL)
- {
- return NULL;
- }
-
- *StatusCode = NULL;
- BOOLEAN FromServerFlag = FALSE;
+ if (!payload || !redpath || (StatusCode == NULL)) {
+ return NULL;
+ }
- if(redpath->nodeName)
- {
- ret = getPayloadByNodeName(payload, redpath->nodeName, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else if(redpath->isIndex)
- {
- ASSERT (redpath->index >= 1);
- ret = getPayloadByIndex(payload, redpath->index - 1, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else if(redpath->op)
- {
- ret = getOpResult(payload, redpath->propName, redpath->op, redpath->value, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else
- {
- return NULL;
- }
+ *StatusCode = NULL;
+ BOOLEAN FromServerFlag = FALSE;
+
+ if (redpath->nodeName) {
+ ret = getPayloadByNodeName (payload, redpath->nodeName, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else if (redpath->isIndex) {
+ ASSERT (redpath->index >= 1);
+ ret = getPayloadByIndex (payload, redpath->index - 1, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else if (redpath->op) {
+ ret = getOpResult (payload, redpath->propName, redpath->op, redpath->value, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else {
+ return NULL;
+ }
- if(redpath->next == NULL || ret == NULL)
- {
- return ret;
+ if ((redpath->next == NULL) || (ret == NULL)) {
+ return ret;
+ } else {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ FromServerFlag = TRUE;
+ }
+
+ tmp = getPayloadForPath (ret, redpath->next, StatusCode);
+ if ((*StatusCode == NULL) && (tmp != NULL) && FromServerFlag) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (ret) directly.
+ // Since the ret are retrived from server, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ tmp = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
+ }
}
- else
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- FromServerFlag = TRUE;
- }
- tmp = getPayloadForPath(ret, redpath->next, StatusCode);
- if (*StatusCode == NULL && tmp != NULL && FromServerFlag) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (ret) directly.
- // Since the ret are retrived from server, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- tmp = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
- }
-
- cleanupPayload(ret);
- return tmp;
- }
+ cleanupPayload (ret);
+ return tmp;
+ }
}
-redfishPayload* getPayloadForPathString(redfishPayload* payload, const char* string, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadForPathString (
+ redfishPayload *payload,
+ const char *string,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redPathNode* redpath;
- redfishPayload* ret;
+ redPathNode *redpath;
+ redfishPayload *ret;
- if(!string || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!string || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- redpath = parseRedPath(string);
- if(redpath == NULL)
- {
- return NULL;
- }
- ret = getPayloadForPath(payload, redpath, StatusCode);
- cleanupRedPath(redpath);
- return ret;
+ redpath = parseRedPath (string);
+ if (redpath == NULL) {
+ return NULL;
+ }
+
+ ret = getPayloadForPath (payload, redpath, StatusCode);
+ cleanupRedPath (redpath);
+ return ret;
}
-redfishPayload* patchPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+patchPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* json;
- char* content;
- char* uri;
+ json_t *json;
+ char *content;
+ char *uri;
- if(!target || !payload || StatusCode == NULL)
- {
+ if (!target || !payload || (StatusCode == NULL)) {
return NULL;
}
*StatusCode = NULL;
- json = json_object_get(target->json, "@odata.id");
- if(json == NULL)
- {
+ json = json_object_get (target->json, "@odata.id");
+ if (json == NULL) {
return NULL;
}
- uri = strdup(json_string_value(json));
- content = json_dumps(payload->json, 0);
- json_decref(json);
+ uri = strdup (json_string_value (json));
- json = patchUriFromService(target->service, uri, content, StatusCode);
- free(uri);
- free(content);
- if(json == NULL)
- {
+ content = json_dumps (payload->json, 0);
+ json_decref (json);
+
+ json = patchUriFromService (target->service, uri, content, StatusCode);
+ free (uri);
+ free (content);
+ if (json == NULL) {
return NULL;
}
- return createRedfishPayload(json, target->service);
+ return createRedfishPayload (json, target->service);
}
-redfishPayload* postContentToPayload(redfishPayload* target, const char* data, size_t dataSize, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+postContentToPayload (
+ redfishPayload *target,
+ const char *data,
+ size_t dataSize,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* json;
- char* uri;
+ json_t *json;
+ char *uri;
- if(!target || !data || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!target || !data || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- json = json_object_get(target->json, "@odata.id");
- if(json == NULL)
- {
- json = json_object_get(target->json, "target");
- if(json == NULL)
- {
- return NULL;
- }
- }
- uri = strdup(json_string_value(json));
- json = postUriFromService(target->service, uri, data, dataSize, contentType, StatusCode);
- free(uri);
- if(json == NULL)
- {
- return NULL;
+ json = json_object_get (target->json, "@odata.id");
+ if (json == NULL) {
+ json = json_object_get (target->json, "target");
+ if (json == NULL) {
+ return NULL;
}
+ }
+
+ uri = strdup (json_string_value (json));
+ json = postUriFromService (target->service, uri, data, dataSize, contentType, StatusCode);
+ free (uri);
+ if (json == NULL) {
+ return NULL;
+ }
- return createRedfishPayload(json, target->service);
+ return createRedfishPayload (json, target->service);
}
-redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+postPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* content;
- redfishPayload* ret;
+ char *content;
+ redfishPayload *ret;
- if(!target || !payload || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!target || !payload || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- if(!json_is_object(payload->json))
- {
- return NULL;
- }
- content = payloadToString(payload, false);
- ret = postContentToPayload(target, content, strlen(content), NULL, StatusCode);
- free(content);
- return ret;
-}
+ if (!json_is_object (payload->json)) {
+ return NULL;
+ }
-void cleanupPayload(redfishPayload* payload)
-{
- if(!payload)
- {
- return;
- }
- json_decref(payload->json);
- //Don't free payload->service, let the caller handle cleaning up the service
- free(payload);
+ content = payloadToString (payload, false);
+ ret = postContentToPayload (target, content, strlen (content), NULL, StatusCode);
+ free (content);
+ return ret;
}
-static redfishPayload* getOpResult(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+void
+cleanupPayload (
+ redfishPayload *payload
+ )
{
- const char* propStr;
- json_t* stringProp;
- bool ret = false;
- redfishPayload* prop;
- long long intVal, intPropVal;
- json_type jsonType;
-
- if(isPayloadCollection(payload))
- {
- return collectionEvalOp(payload, propName, op, value, StatusCode);
- }
- if(isPayloadArray(payload))
- {
- return arrayEvalOp(payload, propName, op, value, StatusCode);
- }
+ if (!payload) {
+ return;
+ }
- prop = getPayloadByNodeName(payload, propName, StatusCode);
- if ((*StatusCode == NULL && prop == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return prop;
- }
- stringProp = prop->json;
- jsonType = prop->json->type;
- switch(jsonType)
- {
- case JSON_OBJECT:
- stringProp = json_object_get(prop->json, propName);
- case JSON_STRING:
- if(strcmp(op, "=") == 0)
- {
- propStr = json_string_value(stringProp);
- if(propStr == NULL)
- {
- cleanupPayload(prop);
- return NULL;
- }
- ret = (strcmp(propStr, value) == 0);
- } else if(strcmp(op, "~") == 0)
- {
- propStr = json_string_value(stringProp);
- if(propStr == NULL)
- {
- cleanupPayload(prop);
- return NULL;
- }
- ret = (strcasecmp(propStr, value) == 0);
- }
- break;
- case JSON_TRUE:
- if(strcmp(op, "=") == 0)
- {
- ret = (strcmp(value, "true") == 0);
- }
- break;
- case JSON_FALSE:
- if(strcmp(op, "=") == 0)
- {
- ret = (strcmp(value, "false") == 0);
- }
- break;
- case JSON_INTEGER:
- intPropVal = json_integer_value(prop->json);
- intVal = strtoll(value, NULL, 0);
- if(strcmp(op, "=") == 0)
- {
- ret = (intPropVal == intVal);
- }
- else if(strcmp(op, "<") == 0)
- {
- ret = (intPropVal < intVal);
- }
- else if(strcmp(op, ">") == 0)
- {
- ret = (intPropVal > intVal);
- }
- else if(strcmp(op, "<=") == 0)
- {
- ret = (intPropVal <= intVal);
- }
- else if(strcmp(op, ">=") == 0)
- {
- ret = (intPropVal >= intVal);
- }
- break;
- default:
- break;
- }
- cleanupPayload(prop);
- if(ret)
- {
- return payload;
- }
- else
- {
- return NULL;
- }
+ json_decref (payload->json);
+ // Don't free payload->service, let the caller handle cleaning up the service
+ free (payload);
}
-static redfishPayload* collectionEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+static redfishPayload *
+getOpResult (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- redfishPayload* tmp;
- redfishPayload* members;
- redfishPayload** valid;
- size_t validMax;
- size_t validCount = 0;
- size_t i;
-
- validMax = getCollectionSize(payload);
- if(validMax == 0)
- {
- return NULL;
- }
+ const char *propStr;
+ json_t *stringProp;
+ bool ret = false;
+ redfishPayload *prop;
+ long long intVal, intPropVal;
+ json_type jsonType;
+
+ if (isPayloadCollection (payload)) {
+ return collectionEvalOp (payload, propName, op, value, StatusCode);
+ }
- valid = (redfishPayload**)calloc(validMax, sizeof(redfishPayload*));
- if(valid == NULL)
- {
- return NULL;
- }
- /*Technically getPayloadByIndex would do this, but this optimizes things*/
- members = getPayloadByNodeName(payload, "Members", StatusCode);
- if ((*StatusCode == NULL && members == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return members;
- }
+ if (isPayloadArray (payload)) {
+ return arrayEvalOp (payload, propName, op, value, StatusCode);
+ }
- for(i = 0; i < validMax; i++)
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
+ prop = getPayloadByNodeName (payload, propName, StatusCode);
+ if (((*StatusCode == NULL) && (prop == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ return prop;
+ }
- tmp = getPayloadByIndex(members, i, StatusCode);
- if ((*StatusCode == NULL && tmp == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return tmp;
+ stringProp = prop->json;
+ jsonType = prop->json->type;
+ switch (jsonType) {
+ case JSON_OBJECT:
+ stringProp = json_object_get (prop->json, propName);
+ case JSON_STRING:
+ if (strcmp (op, "=") == 0) {
+ propStr = json_string_value (stringProp);
+ if (propStr == NULL) {
+ cleanupPayload (prop);
+ return NULL;
}
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
+ ret = (strcmp (propStr, value) == 0);
+ } else if (strcmp (op, "~") == 0) {
+ propStr = json_string_value (stringProp);
+ if (propStr == NULL) {
+ cleanupPayload (prop);
+ return NULL;
}
- valid[validCount] = getOpResult(tmp, propName, op, value, StatusCode);
- /*
- if ((*StatusCode == NULL && valid[validCount] == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return valid[validCount];
- }
- */
- if(valid[validCount] != NULL)
- {
- validCount++;
- }
- else
- {
- cleanupPayload(tmp);
- }
- }
- cleanupPayload(members);
- if(validCount == 0)
- {
- free(valid);
- return NULL;
- }
- if(validCount == 1)
- {
- ret = valid[0];
- free(valid);
- return ret;
- }
- else
- {
- ret = createCollection(payload->service, validCount, valid);
- free(valid);
- return ret;
- }
+ ret = (strcasecmp (propStr, value) == 0);
+ }
+
+ break;
+ case JSON_TRUE:
+ if (strcmp (op, "=") == 0) {
+ ret = (strcmp (value, "true") == 0);
+ }
+
+ break;
+ case JSON_FALSE:
+ if (strcmp (op, "=") == 0) {
+ ret = (strcmp (value, "false") == 0);
+ }
+
+ break;
+ case JSON_INTEGER:
+ intPropVal = json_integer_value (prop->json);
+ intVal = strtoll (value, NULL, 0);
+ if (strcmp (op, "=") == 0) {
+ ret = (intPropVal == intVal);
+ } else if (strcmp (op, "<") == 0) {
+ ret = (intPropVal < intVal);
+ } else if (strcmp (op, ">") == 0) {
+ ret = (intPropVal > intVal);
+ } else if (strcmp (op, "<=") == 0) {
+ ret = (intPropVal <= intVal);
+ } else if (strcmp (op, ">=") == 0) {
+ ret = (intPropVal >= intVal);
+ }
+
+ break;
+ default:
+ break;
+ }
+
+ cleanupPayload (prop);
+ if (ret) {
+ return payload;
+ } else {
+ return NULL;
+ }
}
-static redfishPayload* arrayEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+static redfishPayload *
+collectionEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- redfishPayload* tmp;
- redfishPayload** valid;
- size_t validMax;
- size_t validCount = 0;
- size_t i;
-
- validMax = json_array_size(payload->json);
- if(validMax == 0)
- {
- return NULL;
+ redfishPayload *ret;
+ redfishPayload *tmp;
+ redfishPayload *members;
+ redfishPayload **valid;
+ size_t validMax;
+ size_t validCount = 0;
+ size_t i;
+
+ validMax = getCollectionSize (payload);
+ if (validMax == 0) {
+ return NULL;
+ }
+
+ valid = (redfishPayload **)calloc (validMax, sizeof (redfishPayload *));
+ if (valid == NULL) {
+ return NULL;
+ }
+
+ /*Technically getPayloadByIndex would do this, but this optimizes things*/
+ members = getPayloadByNodeName (payload, "Members", StatusCode);
+ if (((*StatusCode == NULL) && (members == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ return members;
+ }
+
+ for (i = 0; i < validMax; i++) {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
}
- valid = (redfishPayload**)calloc(validMax, sizeof(redfishPayload*));
- if(valid == NULL)
+ tmp = getPayloadByIndex (members, i, StatusCode);
+ if (((*StatusCode == NULL) && (tmp == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- return NULL;
+ return tmp;
}
- for(i = 0; i < validMax; i++)
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
- tmp = getPayloadByIndex(payload, i, StatusCode);
- if ((*StatusCode == NULL && tmp == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return tmp;
- }
-
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ }
- valid[validCount] = getOpResult(tmp, propName, op, value, StatusCode);
- /*
- if ((*StatusCode == NULL && valid[validCount] == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return valid[validCount];
- }
- */
+ valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
- if(valid[validCount] != NULL)
- {
- validCount++;
- }
- else
- {
- cleanupPayload(tmp);
- }
- }
- if(validCount == 0)
- {
- free(valid);
- return NULL;
- }
- if(validCount == 1)
- {
- ret = valid[0];
- free(valid);
- return ret;
+ /*
+ if ((*StatusCode == NULL && valid[validCount] == NULL) ||
+ (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ return valid[validCount];
}
- else
- {
- ret = createCollection(payload->service, validCount, valid);
- free(valid);
- return ret;
+ */
+ if (valid[validCount] != NULL) {
+ validCount++;
+ } else {
+ cleanupPayload (tmp);
}
+ }
+
+ cleanupPayload (members);
+ if (validCount == 0) {
+ free (valid);
+ return NULL;
+ }
+
+ if (validCount == 1) {
+ ret = valid[0];
+ free (valid);
+ return ret;
+ } else {
+ ret = createCollection (payload->service, validCount, valid);
+ free (valid);
+ return ret;
+ }
}
-static redfishPayload* createCollection(redfishService* service, size_t count, redfishPayload** payloads)
+static redfishPayload *
+arrayEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- json_t* collectionJson = json_object();
- json_t* jcount = json_integer((json_int_t)count);
- json_t* members = json_array();
- size_t i;
+ redfishPayload *ret;
+ redfishPayload *tmp;
+ redfishPayload **valid;
+ size_t validMax;
+ size_t validCount = 0;
+ size_t i;
+
+ validMax = json_array_size (payload->json);
+ if (validMax == 0) {
+ return NULL;
+ }
- if(!collectionJson)
- {
- return NULL;
+ valid = (redfishPayload **)calloc (validMax, sizeof (redfishPayload *));
+ if (valid == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < validMax; i++) {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
}
- if(!members)
+
+ tmp = getPayloadByIndex (payload, i, StatusCode);
+ if (((*StatusCode == NULL) && (tmp == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- json_decref(collectionJson);
- return NULL;
+ return tmp;
}
- json_object_set(collectionJson, "Members@odata.count", jcount);
- json_decref(jcount);
- for(i = 0; i < count; i++)
- {
- json_array_append(members, payloads[i]->json);
- cleanupPayload(payloads[i]);
+
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ }
+
+ valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
+
+ /*
+ if ((*StatusCode == NULL && valid[validCount] == NULL) ||
+ (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ return valid[validCount];
}
- json_object_set(collectionJson, "Members", members);
- json_decref(members);
+ */
+
+ if (valid[validCount] != NULL) {
+ validCount++;
+ } else {
+ cleanupPayload (tmp);
+ }
+ }
+
+ if (validCount == 0) {
+ free (valid);
+ return NULL;
+ }
- ret = createRedfishPayload(collectionJson, service);
+ if (validCount == 1) {
+ ret = valid[0];
+ free (valid);
+ return ret;
+ } else {
+ ret = createCollection (payload->service, validCount, valid);
+ free (valid);
return ret;
+ }
}
-static json_t* json_object_get_by_index(json_t* json, size_t index)
+static redfishPayload *
+createCollection (
+ redfishService *service,
+ size_t count,
+ redfishPayload **payloads
+ )
{
- void* iter;
- size_t i;
+ redfishPayload *ret;
+ json_t *collectionJson = json_object ();
+ json_t *jcount = json_integer ((json_int_t)count);
+ json_t *members = json_array ();
+ size_t i;
- iter = json_object_iter(json);
- for(i = 0; i < index; i++)
- {
- iter = json_object_iter_next(json, iter);
- if(iter == NULL) break;
- }
- if(iter == NULL)
- {
- return NULL;
+ if (!collectionJson) {
+ return NULL;
+ }
+
+ if (!members) {
+ json_decref (collectionJson);
+ return NULL;
+ }
+
+ json_object_set (collectionJson, "Members@odata.count", jcount);
+ json_decref (jcount);
+ for (i = 0; i < count; i++) {
+ json_array_append (members, payloads[i]->json);
+ cleanupPayload (payloads[i]);
+ }
+
+ json_object_set (collectionJson, "Members", members);
+ json_decref (members);
+
+ ret = createRedfishPayload (collectionJson, service);
+ return ret;
+}
+
+static json_t *
+json_object_get_by_index (
+ json_t *json,
+ size_t index
+ )
+{
+ void *iter;
+ size_t i;
+
+ iter = json_object_iter (json);
+ for (i = 0; i < index; i++) {
+ iter = json_object_iter_next (json, iter);
+ if (iter == NULL) {
+ break;
}
- return json_object_iter_value(iter);
+ }
+
+ if (iter == NULL) {
+ return NULL;
+ }
+
+ return json_object_iter_value (iter);
}
+
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
index 1fb4346c2b..cf5ab85165 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
@@ -16,177 +16,209 @@
**/
#include <redpath.h>
-static char* getVersion(const char* path, char** end);
-static void parseNode(const char* path, redPathNode* node, redPathNode** end);
+static char *
+getVersion (
+ const char *path,
+ char **end
+ );
+
+static void
+parseNode (
+ const char *path,
+ redPathNode *node,
+ redPathNode **end
+ );
+
+static char *
+getStringTill (
+ const char *string,
+ const char *terminator,
+ char **retEnd
+ );
+
+redPathNode *
+parseRedPath (
+ const char *path
+ )
+{
+ redPathNode *node;
+ redPathNode *endNode;
+ char *curPath;
+ char *end;
+
+ if (!path || (strlen (path) == 0)) {
+ return NULL;
+ }
+
+ node = (redPathNode *)calloc (1, sizeof (redPathNode));
+ if (!node) {
+ return NULL;
+ }
+
+ if (path[0] == '/') {
+ node->isRoot = true;
+ if (path[1] == 'v') {
+ node->version = getVersion (path+1, &curPath);
+ if (curPath == NULL) {
+ return node;
+ }
-static char* getStringTill(const char* string, const char* terminator, char** retEnd);
+ if (curPath[0] == '/') {
+ curPath++;
+ }
-redPathNode* parseRedPath(const char* path)
-{
- redPathNode* node;
- redPathNode* endNode;
- char* curPath;
- char* end;
-
- if(!path || strlen(path) == 0)
- {
- return NULL;
+ node->next = parseRedPath (curPath);
+ } else {
+ node->next = parseRedPath (path+1);
}
- node = (redPathNode*)calloc(1, sizeof(redPathNode));
- if(!node)
- {
- return NULL;
- }
- if(path[0] == '/')
- {
- node->isRoot = true;
- if(path[1] == 'v')
- {
- node->version = getVersion(path+1, &curPath);
- if(curPath == NULL)
- {
- return node;
- }
- if(curPath[0] == '/')
- {
- curPath++;
- }
- node->next = parseRedPath(curPath);
- }
- else
- {
- node->next = parseRedPath(path+1);
- }
- return node;
- }
- node->isRoot = false;
- curPath = getStringTill(path, "/", &end);
- endNode = node;
- parseNode(curPath, node, &endNode);
- free(curPath);
- if(end != NULL)
- {
- endNode->next = parseRedPath(end+1);
- }
return node;
+ }
+
+ node->isRoot = false;
+ curPath = getStringTill (path, "/", &end);
+ endNode = node;
+ parseNode (curPath, node, &endNode);
+ free (curPath);
+ if (end != NULL) {
+ endNode->next = parseRedPath (end+1);
+ }
+
+ return node;
}
-void cleanupRedPath(redPathNode* node)
+void
+cleanupRedPath (
+ redPathNode *node
+ )
{
- if(!node)
- {
- return;
- }
- cleanupRedPath(node->next);
- node->next = NULL;
- if(node->version)
- {
- free(node->version);
- }
- if(node->nodeName)
- {
- free(node->nodeName);
- }
- if(node->op)
- {
- free(node->op);
- }
- if(node->propName)
- {
- free(node->propName);
- }
- if(node->value)
- {
- free(node->value);
- }
- free(node);
+ if (!node) {
+ return;
+ }
+
+ cleanupRedPath (node->next);
+ node->next = NULL;
+ if (node->version) {
+ free (node->version);
+ }
+
+ if (node->nodeName) {
+ free (node->nodeName);
+ }
+
+ if (node->op) {
+ free (node->op);
+ }
+
+ if (node->propName) {
+ free (node->propName);
+ }
+
+ if (node->value) {
+ free (node->value);
+ }
+
+ free (node);
}
-static char* getVersion(const char* path, char** end)
+static char *
+getVersion (
+ const char *path,
+ char **end
+ )
{
- return getStringTill(path, "/", end);
+ return getStringTill (path, "/", end);
}
-static void parseNode(const char* path, redPathNode* node, redPathNode** end)
+static void
+parseNode (
+ const char *path,
+ redPathNode *node,
+ redPathNode **end
+ )
{
- char* indexStart;
- char* index;
- char* indexEnd;
- char* nodeName = getStringTill(path, "[", &indexStart);
- size_t tmpIndex;
- char* opChars;
-
- node->nodeName = nodeName;
- if(indexStart == NULL)
- {
- *end = node;
- return;
- }
- node->next = (redPathNode*)calloc(1, sizeof(redPathNode));
- if(!node->next)
- {
- return;
- }
- //Skip past [
- indexStart++;
- *end = node->next;
- index = getStringTill(indexStart, "]", NULL);
- tmpIndex = (size_t)strtoull(index, &indexEnd, 0);
- if(indexEnd != index)
- {
- free(index);
- node->next->index = tmpIndex;
- node->next->isIndex = true;
- return;
- }
- opChars = strpbrk(index, "<>=~");
- if(opChars == NULL)
- {
- //TODO handle last() and position()
- node->next->op = strdup("exists");
- node->next->propName = index;
- return;
- }
- node->next->propName = (char*)malloc((opChars - index)+1);
- memcpy(node->next->propName, index, (opChars - index));
- node->next->propName[(opChars - index)] = 0;
-
- tmpIndex = 1;
- while(1)
- {
- if(opChars[tmpIndex] == '=' || opChars[tmpIndex] == '<' || opChars[tmpIndex] == '>' || opChars[tmpIndex] == '~')
- {
- tmpIndex++;
- continue;
- }
- break;
- }
-
- node->next->op = (char*)malloc(tmpIndex+1);
- memcpy(node->next->op, opChars, tmpIndex);
- node->next->op[tmpIndex] = 0;
-
- node->next->value = strdup(opChars+tmpIndex);
- free(index);
+ char *indexStart;
+ char *index;
+ char *indexEnd;
+ char *nodeName = getStringTill (path, "[", &indexStart);
+ size_t tmpIndex;
+ char *opChars;
+
+ node->nodeName = nodeName;
+ if (indexStart == NULL) {
+ *end = node;
+ return;
+ }
+
+ node->next = (redPathNode *)calloc (1, sizeof (redPathNode));
+ if (!node->next) {
+ return;
+ }
+
+ // Skip past [
+ indexStart++;
+ *end = node->next;
+ index = getStringTill (indexStart, "]", NULL);
+ tmpIndex = (size_t)strtoull (index, &indexEnd, 0);
+ if (indexEnd != index) {
+ free (index);
+ node->next->index = tmpIndex;
+ node->next->isIndex = true;
+ return;
+ }
+
+ opChars = strpbrk (index, "<>=~");
+ if (opChars == NULL) {
+ // TODO handle last() and position()
+ node->next->op = strdup ("exists");
+ node->next->propName = index;
+ return;
+ }
+
+ node->next->propName = (char *)malloc ((opChars - index)+1);
+ memcpy (node->next->propName, index, (opChars - index));
+ node->next->propName[(opChars - index)] = 0;
+
+ tmpIndex = 1;
+ while (1) {
+ if ((opChars[tmpIndex] == '=') || (opChars[tmpIndex] == '<') || (opChars[tmpIndex] == '>') || (opChars[tmpIndex] == '~')) {
+ tmpIndex++;
+ continue;
+ }
+
+ break;
+ }
+
+ node->next->op = (char *)malloc (tmpIndex+1);
+ memcpy (node->next->op, opChars, tmpIndex);
+ node->next->op[tmpIndex] = 0;
+
+ node->next->value = strdup (opChars+tmpIndex);
+ free (index);
}
-static char* getStringTill(const char* string, const char* terminator, char** retEnd)
+static char *
+getStringTill (
+ const char *string,
+ const char *terminator,
+ char **retEnd
+ )
{
- char* ret;
- char* end;
- end = strstr((char*)string, terminator);
- if(retEnd)
- {
- *retEnd = end;
- }
- if(end == NULL)
- {
- //No terminator
- return strdup(string);
- }
- ret = (char*)malloc((end-string)+1);
- memcpy(ret, string, (end-string));
- ret[(end-string)] = 0;
- return ret;
+ char *ret;
+ char *end;
+
+ end = strstr ((char *)string, terminator);
+ if (retEnd) {
+ *retEnd = end;
+ }
+
+ if (end == NULL) {
+ // No terminator
+ return strdup (string);
+ }
+
+ ret = (char *)malloc ((end-string)+1);
+ memcpy (ret, string, (end-string));
+ ret[(end-string)] = 0;
+ return ret;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c
index edfd4fc6f9..afa172b531 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c
@@ -19,22 +19,70 @@
#include <redfishPayload.h>
#include <redpath.h>
-static int initRest(redfishService* service, void * restProtocol);
-static redfishService* createServiceEnumeratorNoAuth(const char* host, const char* rootUri, bool enumerate, unsigned int flags, void * restProtocol);
-static redfishService* createServiceEnumeratorBasicAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol);
-static redfishService* createServiceEnumeratorSessionAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol);
-static char* makeUrlForService(redfishService* service, const char* uri);
-static json_t* getVersions(redfishService* service, const char* rootUri);
-static void addStringToJsonObject(json_t* object, const char* key, const char* value);
-
-CHAR16*
-C8ToC16 (CHAR8 *AsciiStr)
+static int
+initRest (
+ redfishService *service,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorNoAuth (
+ const char *host,
+ const char *rootUri,
+ bool enumerate,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorBasicAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorSessionAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static char *
+makeUrlForService (
+ redfishService *service,
+ const char *uri
+ );
+
+static json_t *
+getVersions (
+ redfishService *service,
+ const char *rootUri
+ );
+
+static void
+addStringToJsonObject (
+ json_t *object,
+ const char *key,
+ const char *value
+ );
+
+CHAR16 *
+C8ToC16 (
+ CHAR8 *AsciiStr
+ )
{
- CHAR16 *Str;
+ CHAR16 *Str;
UINTN BufLen;
BufLen = (AsciiStrLen (AsciiStr) + 1) * 2;
- Str = AllocatePool (BufLen);
+ Str = AllocatePool (BufLen);
ASSERT (Str != NULL);
AsciiStrToUnicodeStrS (AsciiStr, Str, AsciiStrLen (AsciiStr) + 1);
@@ -44,11 +92,11 @@ C8ToC16 (CHAR8 *AsciiStr)
VOID
RestConfigFreeHttpRequestData (
- IN EFI_HTTP_REQUEST_DATA *RequestData
+ IN EFI_HTTP_REQUEST_DATA *RequestData
)
{
if (RequestData == NULL) {
- return ;
+ return;
}
if (RequestData->Url != NULL) {
@@ -60,12 +108,12 @@ RestConfigFreeHttpRequestData (
VOID
RestConfigFreeHttpMessage (
- IN EFI_HTTP_MESSAGE *Message,
- IN BOOLEAN IsRequest
+ IN EFI_HTTP_MESSAGE *Message,
+ IN BOOLEAN IsRequest
)
{
if (Message == NULL) {
- return ;
+ return;
}
if (IsRequest) {
@@ -82,6 +130,7 @@ RestConfigFreeHttpMessage (
FreePool (Message->Headers);
Message->Headers = NULL;
}
+
if (Message->Body != NULL) {
FreePool (Message->Body);
Message->Body = NULL;
@@ -96,17 +145,16 @@ RestConfigFreeHttpMessage (
@return Buffer points to ASCII string, or NULL if error happens.
**/
-
CHAR8 *
UnicodeStrDupToAsciiStr (
- CONST CHAR16 *String
+ CONST CHAR16 *String
)
{
- CHAR8 *AsciiStr;
- UINTN BufLen;
- EFI_STATUS Status;
+ CHAR8 *AsciiStr;
+ UINTN BufLen;
+ EFI_STATUS Status;
- BufLen = StrLen (String) + 1;
+ BufLen = StrLen (String) + 1;
AsciiStr = AllocatePool (BufLen);
if (AsciiStr == NULL) {
return NULL;
@@ -119,6 +167,7 @@ UnicodeStrDupToAsciiStr (
return AsciiStr;
}
+
/**
This function encodes the content.
@@ -134,31 +183,33 @@ UnicodeStrDupToAsciiStr (
**/
EFI_STATUS
EncodeRequestContent (
- IN CHAR8 *ContentEncodedValue,
- IN CHAR8 *OriginalContent,
- OUT VOID **EncodedContent,
- OUT UINTN *EncodedContentLength
-)
+ IN CHAR8 *ContentEncodedValue,
+ IN CHAR8 *OriginalContent,
+ OUT VOID **EncodedContent,
+ OUT UINTN *EncodedContentLength
+ )
{
- EFI_STATUS Status;
- VOID *EncodedPointer;
- UINTN EncodedLength;
+ EFI_STATUS Status;
+ VOID *EncodedPointer;
+ UINTN EncodedLength;
- if (OriginalContent == NULL || EncodedContent == NULL || EncodedContentLength == NULL) {
+ if ((OriginalContent == NULL) || (EncodedContent == NULL) || (EncodedContentLength == NULL)) {
return EFI_INVALID_PARAMETER;
}
- Status = RedfishContentEncode (
+
+ Status = RedfishContentEncode (
ContentEncodedValue,
OriginalContent,
AsciiStrLen (OriginalContent),
&EncodedPointer,
&EncodedLength
- );
+ );
if (Status == EFI_SUCCESS) {
- *EncodedContent = EncodedPointer;
+ *EncodedContent = EncodedPointer;
*EncodedContentLength = EncodedLength;
return EFI_SUCCESS;
}
+
return Status;
}
@@ -180,30 +231,32 @@ EncodeRequestContent (
**/
EFI_STATUS
DecodeResponseContent (
- IN CHAR8 *ContentEncodedValue,
- IN OUT VOID **ContentPointer,
- IN OUT UINTN *ContentLength
-)
+ IN CHAR8 *ContentEncodedValue,
+ IN OUT VOID **ContentPointer,
+ IN OUT UINTN *ContentLength
+ )
{
- EFI_STATUS Status;
- VOID *DecodedPointer;
- UINTN DecodedLength;
+ EFI_STATUS Status;
+ VOID *DecodedPointer;
+ UINTN DecodedLength;
if (ContentEncodedValue == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Status = RedfishContentDecode (
- ContentEncodedValue,
- *ContentPointer,
- *ContentLength,
- &DecodedPointer,
- &DecodedLength
- );
+ ContentEncodedValue,
+ *ContentPointer,
+ *ContentLength,
+ &DecodedPointer,
+ &DecodedLength
+ );
if (Status == EFI_SUCCESS) {
FreePool (*ContentPointer);
*ContentPointer = DecodedPointer;
- *ContentLength = DecodedLength;
+ *ContentLength = DecodedLength;
}
+
return Status;
}
@@ -226,15 +279,15 @@ DecodeResponseContent (
**/
EFI_STATUS
RedfishBuildUrl (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN CHAR16 *RelativePath OPTIONAL,
- OUT CHAR16 **HttpUrl
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN CHAR16 *RelativePath OPTIONAL,
+ OUT CHAR16 **HttpUrl
)
{
- CHAR16 *Url;
- CHAR16 *UrlHead;
- UINTN UrlLength;
- UINTN PathLen;
+ CHAR16 *Url;
+ CHAR16 *UrlHead;
+ UINTN UrlLength;
+ UINTN PathLen;
if ((RedfishConfigServiceInfo == NULL) || (HttpUrl == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -248,8 +301,9 @@ RedfishBuildUrl (
} else {
PathLen = StrLen (RelativePath);
}
- UrlLength = StrLen (HTTPS_FLAG) + StrLen (REDFISH_FIRST_URL) + 1 + StrLen(RedfishConfigServiceInfo->RedfishServiceLocation) + PathLen;
- Url = AllocateZeroPool (UrlLength * sizeof (CHAR16));
+
+ UrlLength = StrLen (HTTPS_FLAG) + StrLen (REDFISH_FIRST_URL) + 1 + StrLen (RedfishConfigServiceInfo->RedfishServiceLocation) + PathLen;
+ Url = AllocateZeroPool (UrlLength * sizeof (CHAR16));
if (Url == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -272,30 +326,38 @@ RedfishBuildUrl (
//
// Copy abs_path
//
- if (RelativePath != NULL && PathLen != 0 ) {
+ if ((RelativePath != NULL) && (PathLen != 0)) {
StrnCpyS (Url, UrlLength, RelativePath, PathLen);
}
+
*HttpUrl = UrlHead;
return EFI_SUCCESS;
}
-redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, const char* rootUri, enumeratorAuthentication* auth, unsigned int flags)
+redfishService *
+createServiceEnumerator (
+ REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ const char *rootUri,
+ enumeratorAuthentication *auth,
+ unsigned int flags
+ )
{
- EFI_STATUS Status;
- CHAR16 *HttpUrl;
- CHAR8 *AsciiHost;
- EFI_REST_EX_PROTOCOL *RestEx;
- redfishService *ret;
+ EFI_STATUS Status;
+ CHAR16 *HttpUrl;
+ CHAR8 *AsciiHost;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ redfishService *ret;
- HttpUrl = NULL;
+ HttpUrl = NULL;
AsciiHost = NULL;
- RestEx = NULL;
- ret = NULL;
+ RestEx = NULL;
+ ret = NULL;
if (RedfishConfigServiceInfo->RedfishServiceRestExHandle == NULL) {
goto ON_EXIT;
}
- Status = RedfishBuildUrl(RedfishConfigServiceInfo, NULL, &HttpUrl);
+
+ Status = RedfishBuildUrl (RedfishConfigServiceInfo, NULL, &HttpUrl);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
@@ -308,19 +370,20 @@ redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *Redf
}
Status = gBS->HandleProtocol (
- RedfishConfigServiceInfo->RedfishServiceRestExHandle,
- &gEfiRestExProtocolGuid,
- (VOID **)&RestEx
- );
+ RedfishConfigServiceInfo->RedfishServiceRestExHandle,
+ &gEfiRestExProtocolGuid,
+ (VOID **)&RestEx
+ );
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
- if(auth == NULL) {
- ret = createServiceEnumeratorNoAuth(AsciiHost, rootUri, true, flags, RestEx);
- } else if(auth->authType == REDFISH_AUTH_BASIC) {
- ret = createServiceEnumeratorBasicAuth(AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
- } else if(auth->authType == REDFISH_AUTH_SESSION) {
- ret = createServiceEnumeratorSessionAuth(AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
+
+ if (auth == NULL) {
+ ret = createServiceEnumeratorNoAuth (AsciiHost, rootUri, true, flags, RestEx);
+ } else if (auth->authType == REDFISH_AUTH_BASIC) {
+ ret = createServiceEnumeratorBasicAuth (AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
+ } else if (auth->authType == REDFISH_AUTH_SESSION) {
+ ret = createServiceEnumeratorSessionAuth (AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
} else {
goto ON_EXIT;
}
@@ -338,31 +401,34 @@ ON_EXIT:
return ret;
}
-json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+getUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- EFI_HTTP_HEADER *ContentEncodedHeader;
-
- if(service == NULL || uri == NULL || StatusCode == NULL)
- {
- return NULL;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ EFI_HTTP_HEADER *ContentEncodedHeader;
+
+ if ((service == NULL) || (uri == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: getUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: getUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -373,8 +439,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA
goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -403,7 +468,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA
}
RequestData->Method = HttpMethodGet;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -445,7 +510,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA
**StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
//
// Check if data is encoded.
//
@@ -461,6 +526,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA
goto ON_EXIT;
}
}
+
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
} else {
//
@@ -491,33 +557,37 @@ ON_EXIT:
return ret;
}
-json_t* patchUriFromService(redfishService* service, const char* uri, const char* content, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+patchUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- CHAR8 ContentLengthStr[80];
- CHAR8 *EncodedContent;
- UINTN EncodedContentLen;
-
- if(service == NULL || uri == NULL || content == NULL || StatusCode == NULL)
- {
- return NULL;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ CHAR8 ContentLengthStr[80];
+ CHAR8 *EncodedContent;
+ UINTN EncodedContentLen;
+
+ if ((service == NULL) || (uri == NULL) || (content == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: patchUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: patchUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -528,8 +598,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -548,11 +617,11 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");
ASSERT_EFI_ERROR (Status);
- AsciiSPrint(
+ AsciiSPrint (
ContentLengthStr,
sizeof (ContentLengthStr),
"%lu",
- (UINT64) strlen(content)
+ (UINT64)strlen (content)
);
Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);
ASSERT_EFI_ERROR (Status);
@@ -569,7 +638,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
}
RequestData->Method = HttpMethodPatch;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -580,18 +649,18 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
goto ON_EXIT;
}
- EncodedContent = (CHAR8 *)content;
- EncodedContentLen = strlen(content);
+ EncodedContent = (CHAR8 *)content;
+ EncodedContentLen = strlen (content);
//
// We currently only support gzip Content-Encoding.
//
Status = EncodeRequestContent ((CHAR8 *)HTTP_CONTENT_ENCODING_GZIP, (CHAR8 *)content, (VOID **)&EncodedContent, &EncodedContentLen);
if (Status == EFI_INVALID_PARAMETER) {
- DEBUG((DEBUG_ERROR, "%a: Error to encode content.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a: Error to encode content.\n", __FUNCTION__));
ret = NULL;
goto ON_EXIT;
} else if (Status == EFI_UNSUPPORTED) {
- DEBUG((DEBUG_INFO, "No content coding for %a! Use raw data instead.\n", HTTP_CONTENT_ENCODING_GZIP));
+ DEBUG ((DEBUG_INFO, "No content coding for %a! Use raw data instead.\n", HTTP_CONTENT_ENCODING_GZIP));
Status = HttpIoSetHeader (HttpIoHeader, "Content-Encoding", HTTP_CONTENT_ENCODING_IDENTITY);
ASSERT_EFI_ERROR (Status);
} else {
@@ -603,7 +672,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
RequestMsg->HeaderCount = HttpIoHeader->HeaderCount;
RequestMsg->Headers = HttpIoHeader->Headers;
RequestMsg->BodyLength = EncodedContentLen;
- RequestMsg->Body = (VOID*) EncodedContent;
+ RequestMsg->Body = (VOID *)EncodedContent;
ZeroMem (&ResponseMsg, sizeof (ResponseMsg));
@@ -636,8 +705,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char
FreePool (EncodedContent);
}
-
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
} else {
//
@@ -668,38 +736,43 @@ ON_EXIT:
return ret;
}
-json_t* postUriFromService(redfishService* service, const char* uri, const char* content, size_t contentLength, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+postUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ size_t contentLength,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url = NULL;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- CHAR8 ContentLengthStr[80];
- EFI_HTTP_HEADER *HttpHeader = NULL;
+ char *url = NULL;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ CHAR8 ContentLengthStr[80];
+ EFI_HTTP_HEADER *HttpHeader = NULL;
ret = NULL;
- if(service == NULL || uri == NULL || content == NULL || StatusCode == NULL)
- {
- return NULL;
+ if ((service == NULL) || (uri == NULL) || (content == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: postUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: postUriFromService(): %a\n", url));
- if(contentLength == 0)
- {
- contentLength = strlen(content);
+ if (contentLength == 0) {
+ contentLength = strlen (content);
}
//
@@ -710,8 +783,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -719,13 +791,14 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
ASSERT_EFI_ERROR (Status);
}
- if(contentType == NULL) {
+ if (contentType == NULL) {
Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/json");
ASSERT_EFI_ERROR (Status);
} else {
- Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 *) contentType);
+ Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 *)contentType);
ASSERT_EFI_ERROR (Status);
}
+
Status = HttpIoSetHeader (HttpIoHeader, "Host", service->HostHeaderValue);
ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "Accept", "application/json");
@@ -734,11 +807,11 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");
ASSERT_EFI_ERROR (Status);
- AsciiSPrint(
+ AsciiSPrint (
ContentLengthStr,
sizeof (ContentLengthStr),
"%lu",
- (UINT64) contentLength
+ (UINT64)contentLength
);
Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);
ASSERT_EFI_ERROR (Status);
@@ -754,7 +827,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
}
RequestData->Method = HttpMethodPost;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -768,7 +841,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
RequestMsg->HeaderCount = HttpIoHeader->HeaderCount;
RequestMsg->Headers = HttpIoHeader->Headers;
RequestMsg->BodyLength = contentLength;
- RequestMsg->Body = (VOID*) content;
+ RequestMsg->Body = (VOID *)content;
ZeroMem (&ResponseMsg, sizeof (ResponseMsg));
@@ -795,21 +868,22 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char*
**StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
}
//
// Step 6: Parsing the HttpHeader to retrive the X-Auth-Token if the HTTP StatusCode is correct.
//
- if (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK ||
- ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT) {
+ if ((ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK) ||
+ (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT))
+ {
HttpHeader = HttpFindHeader (ResponseMsg.HeaderCount, ResponseMsg.Headers, "X-Auth-Token");
if (HttpHeader != NULL) {
- if(service->sessionToken)
- {
- free(service->sessionToken);
+ if (service->sessionToken) {
+ free (service->sessionToken);
}
+
service->sessionToken = AllocateCopyPool (AsciiStrSize (HttpHeader->FieldValue), HttpHeader->FieldValue);
}
@@ -849,32 +923,35 @@ ON_EXIT:
return ret;
}
-json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+deleteUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
ret = NULL;
- if(service == NULL || uri == NULL || StatusCode == NULL)
- {
- return NULL;
+ if ((service == NULL) || (uri == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: deleteUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: deleteUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -885,14 +962,14 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_
goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
Status = HttpIoSetHeader (HttpIoHeader, "Authorization", service->basicAuthStr);
ASSERT_EFI_ERROR (Status);
}
+
Status = HttpIoSetHeader (HttpIoHeader, "Host", service->HostHeaderValue);
ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "User-Agent", "libredfish");
@@ -912,7 +989,7 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_
}
RequestData->Method = HttpMethodDelete;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -954,7 +1031,7 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_
**StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
}
@@ -980,169 +1057,191 @@ ON_EXIT:
return ret;
}
-redfishPayload* getRedfishServiceRoot(redfishService* service, const char* version, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getRedfishServiceRoot (
+ redfishService *service,
+ const char *version,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value;
- json_t* versionNode;
- const char* verUrl;
+ json_t *value;
+ json_t *versionNode;
+ const char *verUrl;
- if(version == NULL)
- {
- versionNode = json_object_get(service->versions, "v1");
- }
- else
- {
- versionNode = json_object_get(service->versions, version);
- }
- if(versionNode == NULL)
- {
- return NULL;
- }
- verUrl = json_string_value(versionNode);
- if(verUrl == NULL)
- {
- return NULL;
- }
- value = getUriFromService(service, verUrl, StatusCode);
- if(value == NULL)
- {
- if((service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) == 0)
- {
- json_decref(versionNode);
- }
- return NULL;
+ if (version == NULL) {
+ versionNode = json_object_get (service->versions, "v1");
+ } else {
+ versionNode = json_object_get (service->versions, version);
+ }
+
+ if (versionNode == NULL) {
+ return NULL;
+ }
+
+ verUrl = json_string_value (versionNode);
+ if (verUrl == NULL) {
+ return NULL;
+ }
+
+ value = getUriFromService (service, verUrl, StatusCode);
+ if (value == NULL) {
+ if ((service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) == 0) {
+ json_decref (versionNode);
}
- return createRedfishPayload(value, service);
+
+ return NULL;
+ }
+
+ return createRedfishPayload (value, service);
}
-redfishPayload* getPayloadByPath(redfishService* service, const char* path, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByPath (
+ redfishService *service,
+ const char *path,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redPathNode* redpath;
- redfishPayload* root;
- redfishPayload* ret;
+ redPathNode *redpath;
+ redfishPayload *root;
+ redfishPayload *ret;
- if(!service || !path || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!service || !path || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- redpath = parseRedPath(path);
- if(!redpath)
- {
- return NULL;
- }
- if(!redpath->isRoot)
- {
- cleanupRedPath(redpath);
- return NULL;
- }
- root = getRedfishServiceRoot(service, redpath->version, StatusCode);
- if (*StatusCode == NULL || **StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT) {
- cleanupRedPath(redpath);
- return root;
- }
+ redpath = parseRedPath (path);
+ if (!redpath) {
+ return NULL;
+ }
- if(redpath->next == NULL)
- {
- cleanupRedPath(redpath);
- return root;
- }
+ if (!redpath->isRoot) {
+ cleanupRedPath (redpath);
+ return NULL;
+ }
- FreePool (*StatusCode);
- *StatusCode = NULL;
+ root = getRedfishServiceRoot (service, redpath->version, StatusCode);
+ if ((*StatusCode == NULL) || (**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ cleanupRedPath (redpath);
+ return root;
+ }
- ret = getPayloadForPath(root, redpath->next, StatusCode);
- if (*StatusCode == NULL && ret != NULL) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (root) directly.
- // So, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- ret = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
+ if (redpath->next == NULL) {
+ cleanupRedPath (redpath);
+ return root;
+ }
+
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+
+ ret = getPayloadForPath (root, redpath->next, StatusCode);
+ if ((*StatusCode == NULL) && (ret != NULL)) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (root) directly.
+ // So, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ ret = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
}
- cleanupPayload(root);
- cleanupRedPath(redpath);
- return ret;
+ }
+
+ cleanupPayload (root);
+ cleanupRedPath (redpath);
+ return ret;
}
-void cleanupServiceEnumerator(redfishService* service)
+void
+cleanupServiceEnumerator (
+ redfishService *service
+ )
{
- if(!service)
- {
- return;
+ if (!service) {
+ return;
}
- free(service->host);
- json_decref(service->versions);
- if(service->sessionToken != NULL)
- {
- ZeroMem (service->sessionToken, (UINTN)strlen(service->sessionToken));
- FreePool(service->sessionToken);
+
+ free (service->host);
+ json_decref (service->versions);
+ if (service->sessionToken != NULL) {
+ ZeroMem (service->sessionToken, (UINTN)strlen (service->sessionToken));
+ FreePool (service->sessionToken);
}
+
if (service->basicAuthStr != NULL) {
- ZeroMem (service->basicAuthStr, (UINTN)strlen(service->basicAuthStr));
- FreePool (service->basicAuthStr);
+ ZeroMem (service->basicAuthStr, (UINTN)strlen (service->basicAuthStr));
+ FreePool (service->basicAuthStr);
}
- free(service);
+
+ free (service);
}
-static int initRest(redfishService* service, void * restProtocol)
+static int
+initRest (
+ redfishService *service,
+ void *restProtocol
+ )
{
service->RestEx = restProtocol;
return 0;
}
-static redfishService* createServiceEnumeratorNoAuth(const char* host, const char* rootUri, bool enumerate, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorNoAuth (
+ const char *host,
+ const char *rootUri,
+ bool enumerate,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- char *HostStart;
-
- ret = (redfishService*)calloc(1, sizeof(redfishService));
- ZeroMem (ret, sizeof(redfishService));
- if(initRest(ret, restProtocol) != 0)
- {
- free(ret);
- return NULL;
- }
- ret->host = AllocateCopyPool(AsciiStrSize(host), host);
- ret->flags = flags;
- if(enumerate)
- {
- ret->versions = getVersions(ret, rootUri);
- }
- HostStart = strstr (ret->host, "//");
- if (HostStart != NULL && (*(HostStart + 2) != '\0')) {
- ret->HostHeaderValue = HostStart + 2;
- }
+ redfishService *ret;
+ char *HostStart;
+
+ ret = (redfishService *)calloc (1, sizeof (redfishService));
+ ZeroMem (ret, sizeof (redfishService));
+ if (initRest (ret, restProtocol) != 0) {
+ free (ret);
+ return NULL;
+ }
+
+ ret->host = AllocateCopyPool (AsciiStrSize (host), host);
+ ret->flags = flags;
+ if (enumerate) {
+ ret->versions = getVersions (ret, rootUri);
+ }
- return ret;
+ HostStart = strstr (ret->host, "//");
+ if ((HostStart != NULL) && (*(HostStart + 2) != '\0')) {
+ ret->HostHeaderValue = HostStart + 2;
+ }
+
+ return ret;
}
EFI_STATUS
createBasicAuthStr (
- IN redfishService* service,
- IN CONST CHAR8 *UserId,
- IN CONST CHAR8 *Password
+ IN redfishService *service,
+ IN CONST CHAR8 *UserId,
+ IN CONST CHAR8 *Password
)
{
- EFI_STATUS Status;
- CHAR8 *RawAuthValue;
- UINTN RawAuthBufSize;
- CHAR8 *EnAuthValue;
- UINTN EnAuthValueSize;
- CHAR8 *BasicWithEnAuthValue;
- UINTN BasicBufSize;
+ EFI_STATUS Status;
+ CHAR8 *RawAuthValue;
+ UINTN RawAuthBufSize;
+ CHAR8 *EnAuthValue;
+ UINTN EnAuthValueSize;
+ CHAR8 *BasicWithEnAuthValue;
+ UINTN BasicBufSize;
EnAuthValue = NULL;
EnAuthValueSize = 0;
RawAuthBufSize = AsciiStrLen (UserId) + AsciiStrLen (Password) + 2;
- RawAuthValue = AllocatePool (RawAuthBufSize);
+ RawAuthValue = AllocatePool (RawAuthBufSize);
if (RawAuthValue == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -1162,20 +1261,20 @@ createBasicAuthStr (
// Encoding RawAuthValue into Base64 format.
//
Status = Base64Encode (
- (CONST UINT8 *) RawAuthValue,
+ (CONST UINT8 *)RawAuthValue,
AsciiStrLen (RawAuthValue),
EnAuthValue,
&EnAuthValueSize
);
if (Status == EFI_BUFFER_TOO_SMALL) {
- EnAuthValue = (CHAR8 *) AllocateZeroPool (EnAuthValueSize);
+ EnAuthValue = (CHAR8 *)AllocateZeroPool (EnAuthValueSize);
if (EnAuthValue == NULL) {
Status = EFI_OUT_OF_RESOURCES;
return Status;
}
Status = Base64Encode (
- (CONST UINT8 *) RawAuthValue,
+ (CONST UINT8 *)RawAuthValue,
AsciiStrLen (RawAuthValue),
EnAuthValue,
&EnAuthValueSize
@@ -1186,7 +1285,7 @@ createBasicAuthStr (
goto Exit;
}
- BasicBufSize = AsciiStrLen ("Basic ") + AsciiStrLen(EnAuthValue) + 2;
+ BasicBufSize = AsciiStrLen ("Basic ") + AsciiStrLen (EnAuthValue) + 2;
BasicWithEnAuthValue = AllocatePool (BasicBufSize);
if (BasicWithEnAuthValue == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@@ -1220,177 +1319,205 @@ Exit:
return Status;
}
-static redfishService* createServiceEnumeratorBasicAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorBasicAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- EFI_STATUS Status;
+ redfishService *ret;
+ EFI_STATUS Status;
- ret = createServiceEnumeratorNoAuth(host, rootUri, false, flags, restProtocol);
+ ret = createServiceEnumeratorNoAuth (host, rootUri, false, flags, restProtocol);
- // add basic auth str
- Status = createBasicAuthStr (ret, username, password);
- if (EFI_ERROR(Status)) {
- cleanupServiceEnumerator (ret);
- return NULL;
- }
+ // add basic auth str
+ Status = createBasicAuthStr (ret, username, password);
+ if (EFI_ERROR (Status)) {
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- ret->versions = getVersions(ret, rootUri);
- return ret;
+ ret->versions = getVersions (ret, rootUri);
+ return ret;
}
-static redfishService* createServiceEnumeratorSessionAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorSessionAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- redfishPayload* payload;
- redfishPayload* links;
- json_t* sessionPayload;
- json_t* session;
- json_t* odataId;
- const char* uri;
- json_t* post;
- char* content;
- EFI_HTTP_STATUS_CODE *StatusCode;
-
- content = NULL;
- StatusCode = NULL;
-
- ret = createServiceEnumeratorNoAuth(host, rootUri, true, flags, restProtocol);
- if(ret == NULL)
- {
- return NULL;
- }
- payload = getRedfishServiceRoot(ret, NULL, &StatusCode);
- if(StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)
- {
- if (StatusCode != NULL) {
- FreePool (StatusCode);
- }
-
- if (payload != NULL) {
- cleanupPayload(payload);
- }
- cleanupServiceEnumerator(ret);
- return NULL;
- }
+ redfishService *ret;
+ redfishPayload *payload;
+ redfishPayload *links;
+ json_t *sessionPayload;
+ json_t *session;
+ json_t *odataId;
+ const char *uri;
+ json_t *post;
+ char *content;
+ EFI_HTTP_STATUS_CODE *StatusCode;
+
+ content = NULL;
+ StatusCode = NULL;
+
+ ret = createServiceEnumeratorNoAuth (host, rootUri, true, flags, restProtocol);
+ if (ret == NULL) {
+ return NULL;
+ }
+ payload = getRedfishServiceRoot (ret, NULL, &StatusCode);
+ if ((StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
if (StatusCode != NULL) {
FreePool (StatusCode);
- StatusCode = NULL;
}
- links = getPayloadByNodeName(payload, "Links", &StatusCode);
- cleanupPayload(payload);
- if(links == NULL)
- {
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- session = json_object_get(links->json, "Sessions");
- if(session == NULL)
- {
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- odataId = json_object_get(session, "@odata.id");
- if(odataId == NULL)
- {
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- uri = json_string_value(odataId);
- post = json_object();
- addStringToJsonObject(post, "UserName", username);
- addStringToJsonObject(post, "Password", password);
- content = json_dumps(post, 0);
- json_decref(post);
- sessionPayload = postUriFromService(ret, uri, content, 0, NULL, &StatusCode);
-
- if (content != NULL) {
- ZeroMem (content, (UINTN)strlen(content));
- free(content);
+ if (payload != NULL) {
+ cleanupPayload (payload);
}
- if(sessionPayload == NULL || StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)
- {
- //Failed to create session!
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
+
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
+ StatusCode = NULL;
+ }
+
+ links = getPayloadByNodeName (payload, "Links", &StatusCode);
+ cleanupPayload (payload);
+ if (links == NULL) {
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
+ session = json_object_get (links->json, "Sessions");
+ if (session == NULL) {
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- if (StatusCode != NULL) {
- FreePool (StatusCode);
- }
+ odataId = json_object_get (session, "@odata.id");
+ if (odataId == NULL) {
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
+
+ uri = json_string_value (odataId);
+ post = json_object ();
+ addStringToJsonObject (post, "UserName", username);
+ addStringToJsonObject (post, "Password", password);
+ content = json_dumps (post, 0);
+ json_decref (post);
+ sessionPayload = postUriFromService (ret, uri, content, 0, NULL, &StatusCode);
+
+ if (content != NULL) {
+ ZeroMem (content, (UINTN)strlen (content));
+ free (content);
+ }
+
+ if ((sessionPayload == NULL) || (StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ // Failed to create session!
- if (sessionPayload != NULL) {
- json_decref(sessionPayload);
- }
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
- return NULL;
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
}
- json_decref(sessionPayload);
- cleanupPayload(links);
- FreePool (StatusCode);
- return ret;
+
+ if (sessionPayload != NULL) {
+ json_decref (sessionPayload);
+ }
+
+ return NULL;
+ }
+
+ json_decref (sessionPayload);
+ cleanupPayload (links);
+ FreePool (StatusCode);
+ return ret;
}
-static char* makeUrlForService(redfishService* service, const char* uri)
+static char *
+makeUrlForService (
+ redfishService *service,
+ const char *uri
+ )
{
- char* url;
- if(service->host == NULL)
- {
- return NULL;
- }
- url = (char*)malloc(strlen(service->host)+strlen(uri)+1);
- strcpy(url, service->host);
- strcat(url, uri);
- return url;
+ char *url;
+
+ if (service->host == NULL) {
+ return NULL;
+ }
+
+ url = (char *)malloc (strlen (service->host)+strlen (uri)+1);
+ strcpy (url, service->host);
+ strcat (url, uri);
+ return url;
}
-static json_t* getVersions(redfishService* service, const char* rootUri)
+static json_t *
+getVersions (
+ redfishService *service,
+ const char *rootUri
+ )
{
- json_t* ret = NULL;
- EFI_HTTP_STATUS_CODE* StatusCode = NULL;
-
- if(service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC)
- {
- service->versions = json_object();
- if(service->versions == NULL)
- {
- return NULL;
- }
- addStringToJsonObject(service->versions, "v1", "/redfish/v1");
- return service->versions;
- }
- if(rootUri != NULL)
- {
- ret = getUriFromService(service, rootUri, &StatusCode);
- }
- else
- {
- ret = getUriFromService(service, "/redfish", &StatusCode);
- }
+ json_t *ret = NULL;
+ EFI_HTTP_STATUS_CODE *StatusCode = NULL;
- if (ret == NULL || StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT) {
- if (ret != NULL) {
- json_decref(ret);
- }
- ret = NULL;
+ if (service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) {
+ service->versions = json_object ();
+ if (service->versions == NULL) {
+ return NULL;
}
- if (StatusCode != NULL) {
- FreePool (StatusCode);
+ addStringToJsonObject (service->versions, "v1", "/redfish/v1");
+ return service->versions;
+ }
+
+ if (rootUri != NULL) {
+ ret = getUriFromService (service, rootUri, &StatusCode);
+ } else {
+ ret = getUriFromService (service, "/redfish", &StatusCode);
+ }
+
+ if ((ret == NULL) || (StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ if (ret != NULL) {
+ json_decref (ret);
}
- return ret;
+ ret = NULL;
+ }
+
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
+ }
+
+ return ret;
}
-static void addStringToJsonObject(json_t* object, const char* key, const char* value)
+static void
+addStringToJsonObject (
+ json_t *object,
+ const char *key,
+ const char *value
+ )
{
- json_t* jValue = json_string(value);
+ json_t *jValue = json_string (value);
- json_object_set(object, key, jValue);
+ json_object_set (object, key, jValue);
- json_decref(jValue);
+ json_decref (jValue);
}