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>
This commit is contained in:
Michael Kubacki 2021-12-05 14:54:11 -08:00 committed by mergify[bot]
parent 5220bd211d
commit 39de741e2d
56 changed files with 6067 additions and 4616 deletions

View File

@ -45,7 +45,7 @@ typedef struct {
///< iSerialNumber.bDescriptorType field of the USB
///< descriptor, and is converted from Unicode to ASCII
///< and is NULL terminated.
UINT8 MacAddress [6]; ///< The MAC address of the PCI/PCIe network device.
UINT8 MacAddress[6]; ///< The MAC address of the PCI/PCIe network device.
} USB_INTERFACE_DEVICE_DESCRIPTOR_V2;
//
@ -57,7 +57,7 @@ typedef struct {
UINT16 DeviceId; ///< The Device ID of the PCI/PCIe device.
UINT16 SubsystemVendorId; ///< The Subsystem Vendor ID of the PCI/PCIe device.
UINT16 SubsystemId; ///< The Subsystem ID of the PCI/PCIe device.
UINT8 MacAddress [6]; ///< The MAC address of the PCI/PCIe network device.
UINT8 MacAddress[6]; ///< The MAC address of the PCI/PCIe network device.
UINT16 SegmemtGroupNumber; ///< The Segment Group Number of the PCI/PCIe.
UINT8 BusNumber; ///< The Bus Number of the PCI/PCIe device.
UINT8 DeviceFunctionNumber; ///< The Device/Function Number of the PCI/PCIe.
@ -95,7 +95,7 @@ typedef struct {
// the protocol-specific data for the "Redfish Over IP" protocol
//
typedef struct {
EFI_GUID ServiceUuid; //same as Redfish Service UUID in Redfish Service Root resource
EFI_GUID ServiceUuid; // same as Redfish Service UUID in Redfish Service Root resource
//
// Unknown=00h,
@ -166,4 +166,3 @@ typedef struct {
#pragma pack()
#endif

View File

@ -7,12 +7,13 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef JSON_LIB_H_
#define JSON_LIB_H_
typedef VOID* EDKII_JSON_VALUE;
typedef VOID* EDKII_JSON_ARRAY;
typedef VOID* EDKII_JSON_OBJECT;
typedef VOID *EDKII_JSON_VALUE;
typedef VOID *EDKII_JSON_ARRAY;
typedef VOID *EDKII_JSON_OBJECT;
///
/// Map to json_int_t in jansson.h
@ -69,8 +70,8 @@ typedef struct {
INTN Line;
INTN Column;
INTN Position;
CHAR8 Source [EDKII_JSON_ERROR_SOURCE_LENGTH];
CHAR8 Text [EDKII_JSON_ERROR_TEXT_LENGTH];
CHAR8 Source[EDKII_JSON_ERROR_SOURCE_LENGTH];
CHAR8 Text[EDKII_JSON_ERROR_TEXT_LENGTH];
} EDKII_JSON_ERROR;
///
@ -499,7 +500,7 @@ JsonValueGetAsciiString (
@retval Return the associated Unicode string in JSON value or NULL.
**/
CHAR16*
CHAR16 *
EFIAPI
JsonValueGetUnicodeString (
IN EDKII_JSON_VALUE Json
@ -549,7 +550,7 @@ JsonValueGetBoolean (
@retval Return the associated Ascii string in JSON value or NULL on errors.
**/
CONST CHAR8*
CONST CHAR8 *
EFIAPI
JsonValueGetString (
IN EDKII_JSON_VALUE Json
@ -583,7 +584,7 @@ JsonObjectSize (
JsonObj is not an JSON object, key count is zero or on other errors.
**/
CHAR8**
CHAR8 **
JsonObjectGetKeys (
IN EDKII_JSON_OBJECT JsonObj,
OUT UINTN *KeyCount
@ -766,7 +767,7 @@ JsonDumpString (
EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
IN CONST CHAR8* String,
IN CONST CHAR8 *String,
IN UINT64 Flags,
IN EDKII_JSON_ERROR *Error
);
@ -835,6 +836,7 @@ EFIAPI
JsonIncreaseReference (
IN EDKII_JSON_VALUE JsonValue
);
/**
Returns an opaque iterator which can be used to iterate over all key-value pairs
in object, or NULL if object is empty
@ -883,7 +885,7 @@ CHAR8 *
EFIAPI
JsonObjectIteratorKey (
IN VOID *Iterator
);
);
/**
Returns the pointer of iterator by key.
@ -895,7 +897,7 @@ VOID *
EFIAPI
JsonObjectKeyToIterator (
IN CHAR8 *Key
);
);
/**
Returns the json type of this json value
@ -905,7 +907,8 @@ JsonObjectKeyToIterator (
**/
EDKII_JSON_TYPE
EFIAPI
JsonGetType(
JsonGetType (
IN EDKII_JSON_VALUE JsonValue
);
#endif

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CONTENT_CODING_LIB_H_
#define REDFISH_CONTENT_CODING_LIB_H_
@ -75,4 +76,5 @@ RedfishContentDecode (
OUT VOID **DecodedContentPointer,
OUT UINTN *DecodedLength
);
#endif

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CREDENTIAL_LIB_H_
#define REDFISH_CREDENTIAL_LIB_H_
@ -20,7 +21,7 @@ VOID
EFIAPI
LibCredentialExitBootServicesNotify (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This
);
);
/**
Notification of End of DXe.
@ -31,7 +32,7 @@ VOID
EFIAPI
LibCredentialEndOfDxeNotify (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This
);
);
/**
Retrieve platform's Redfish authentication information.
@ -64,7 +65,7 @@ LibCredentialGetAuthInfo (
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId,
OUT CHAR8 **Password
);
);
/**
Notify the Redfish service provide to stop provide configuration service to this platform.
@ -87,5 +88,6 @@ EFIAPI
LibStopRedfishService (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
);
);
#endif

View File

@ -27,21 +27,21 @@
// We dont support double on edk2
#define HUGE_VAL 0
#if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_RISCV64)
#if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64)
//
// With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
// SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
// 64-bit. Since using 'long long' works fine on GCC too, just do that.
//
#define SIXTY_FOUR_BIT
#elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
#elif defined (MDE_CPU_IA32) || defined (MDE_CPU_ARM) || defined (MDE_CPU_EBC)
#define THIRTY_TWO_BIT
#endif
//
// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
//
#if !defined(__CC_ARM) // if va_list is not already defined
#if !defined (__CC_ARM) // if va_list is not already defined
#define va_list VA_LIST
#define va_arg VA_ARG
#define va_start VA_START
@ -80,7 +80,9 @@ typedef INT32 int32_t;
typedef UINT32 uint32_t;
typedef UINT16 uint16_t;
typedef UINT8 uint8_t;
typedef enum {false, true} bool;
typedef enum {
false, true
} bool;
//
// File operations are not required for EFI building,
@ -148,90 +150,386 @@ extern FILE *stderr;
//
// Function prototypes of CRT Library routines
//
void *malloc (size_t);
void *realloc (void *, size_t);
void *calloc (size_t Num, size_t Size);
void free (void *);
void *memset (void *, int, size_t);
int memcmp (const void *, const void *, size_t);
int isdigit (int);
int isspace (int);
int tolower (int);
int isupper (int);
int isxdigit (int);
int isalnum (int);
void *memcpy (void *, const void *, size_t);
void *memset (void *, int, size_t);
void *memchr (const void *, int, size_t);
int memcmp (const void *, const void *, size_t);
void *memmove (void *, const void *, size_t);
int strcmp (const char *, const char *);
int strncmp (const char *, const char *, size_t);
char *strcpy (char *, const char *);
size_t strlen (const char *);
char *strcat (char *, const char *);
char *strchr (const char *, int);
int strcasecmp (const char *, const char *);
int strncasecmp (const char *, const char *, size_t);
char *strncpy (char *, size_t, const char *, size_t);
int strncmp (const char *, const char *, size_t);
char *strrchr (const char *, int);
unsigned long strtoul (const char *, char **, int);
char * strstr (const char *s1 , const char *s2);
long strtol (const char *, char **, int);
char *strerror (int);
size_t strspn (const char *, const char *);
char * strdup (const char *str);
char * strpbrk (const char *s1, const char *s2);
unsigned long long strtoull(const char * nptr, char ** endptr, int base);
long long strtoll (const char * nptr, char ** endptr, int base);
long strtol (const char * nptr, char ** endptr, int base);
double strtod (const char * __restrict nptr, char ** __restrict endptr);
size_t strcspn (const char *, const char *);
int printf (const char *, ...);
int sscanf (const char *, const char *, ...);
FILE *fopen (const char *, const char *);
size_t fread (void *, size_t, size_t, FILE *);
size_t fwrite (const void *, size_t, size_t, FILE *);
int fclose (FILE *);
int fprintf (FILE *, const char *, ...);
int fgetc (FILE * _File);
uid_t getuid (void);
uid_t geteuid (void);
gid_t getgid (void);
gid_t getegid (void);
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
char *getenv (const char *);
#if defined(__GNUC__) && (__GNUC__ >= 2)
void abort (void) __attribute__((__noreturn__));
void *
malloc (
size_t
);
void *
realloc (
void *,
size_t
);
void *
calloc (
size_t Num,
size_t Size
);
void
free (
void *
);
void *
memset (
void *,
int,
size_t
);
int
memcmp (
const void *,
const void *,
size_t
);
int
isdigit (
int
);
int
isspace (
int
);
int
tolower (
int
);
int
isupper (
int
);
int
isxdigit (
int
);
int
isalnum (
int
);
void *
memcpy (
void *,
const void *,
size_t
);
void *
memset (
void *,
int,
size_t
);
void *
memchr (
const void *,
int,
size_t
);
int
memcmp (
const void *,
const void *,
size_t
);
void *
memmove (
void *,
const void *,
size_t
);
int
strcmp (
const char *,
const char *
);
int
strncmp (
const char *,
const char *,
size_t
);
char *
strcpy (
char *,
const char *
);
size_t
strlen (
const char *
);
char *
strcat (
char *,
const char *
);
char *
strchr (
const char *,
int
);
int
strcasecmp (
const char *,
const char *
);
int
strncasecmp (
const char *,
const char *,
size_t
);
char *
strncpy (
char *,
size_t,
const char *,
size_t
);
int
strncmp (
const char *,
const char *,
size_t
);
char *
strrchr (
const char *,
int
);
unsigned long
strtoul (
const char *,
char **,
int
);
char *
strstr (
const char *s1,
const char *s2
);
long
strtol (
const char *,
char **,
int
);
char *
strerror (
int
);
size_t
strspn (
const char *,
const char *
);
char *
strdup (
const char *str
);
char *
strpbrk (
const char *s1,
const char *s2
);
unsigned long long
strtoull (
const char *nptr,
char **endptr,
int base
);
long long
strtoll (
const char *nptr,
char **endptr,
int base
);
long
strtol (
const char *nptr,
char **endptr,
int base
);
double
strtod (
const char *__restrict nptr,
char **__restrict endptr
);
size_t
strcspn (
const char *,
const char *
);
int
printf (
const char *,
...
);
int
sscanf (
const char *,
const char *,
...
);
FILE *
fopen (
const char *,
const char *
);
size_t
fread (
void *,
size_t,
size_t,
FILE *
);
size_t
fwrite (
const void *,
size_t,
size_t,
FILE *
);
int
fclose (
FILE *
);
int
fprintf (
FILE *,
const char *,
...
);
int
fgetc (
FILE *_File
);
uid_t
getuid (
void
);
uid_t
geteuid (
void
);
gid_t
getgid (
void
);
gid_t
getegid (
void
);
void
qsort (
void *,
size_t,
size_t,
int (*)(const void *, const void *)
);
char *
getenv (
const char *
);
#if defined (__GNUC__) && (__GNUC__ >= 2)
void
abort (
void
) __attribute__ ((__noreturn__));
#else
void abort (void);
void
abort (
void
);
#endif
int toupper (int);
int Digit2Val (int);
time_t time (time_t *);
int
toupper (
int
);
int
Digit2Val (
int
);
time_t
time (
time_t *
);
//
// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
//
#define strcmp AsciiStrCmp
#define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
#define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))
#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
#define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,(strlen(strSource)+1),strSource)
#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,(UINTN)count,strSource,(UINTN)count)
#define strncpys(strDest, DestLen, strSource,count) AsciiStrnCpyS(strDest,DestLen,strSource,(UINTN)count)
#define strcat(strDest,strSource) AsciiStrCatS(strDest,(strlen(strSource)+strlen(strDest)+1),strSource)
#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
#define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2)
#define strstr(s1,s2) AsciiStrStr(s1,s2)
#define snprintf(buf,len,...) RedfishAsciiSPrint(buf,len,__VA_ARGS__)
#define vsnprintf(buf,len,format,marker) RedfishAsciiVSPrint((buf),(len),(format),(marker))
#define strcpy(strDest, strSource) AsciiStrCpyS(strDest,(strlen(strSource)+1),strSource)
#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,(UINTN)count,strSource,(UINTN)count)
#define strncpys(strDest, DestLen, strSource, count) AsciiStrnCpyS(strDest,DestLen,strSource,(UINTN)count)
#define strcat(strDest, strSource) AsciiStrCatS(strDest,(strlen(strSource)+strlen(strDest)+1),strSource)
#define strchr(str, ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
#define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)
#define strstr(s1, s2) AsciiStrStr(s1,s2)
#define snprintf(buf, len, ...) RedfishAsciiSPrint(buf,len,__VA_ARGS__)
#define vsnprintf(buf, len, format, marker) RedfishAsciiVSPrint((buf),(len),(format),(marker))
#define assert(expression) ASSERT(expression)
#define offsetof(type,member) OFFSET_OF(type,member)
#define offsetof(type, member) OFFSET_OF(type,member)
#define EOF (-1)

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_HOST_INTERFACE_LIB_H_
#define REDFISH_HOST_INTERFACE_LIB_H_
@ -29,7 +30,8 @@ EFI_STATUS
RedfishPlatformHostInterfaceDeviceDescriptor (
IN UINT8 *DeviceType,
OUT REDFISH_INTERFACE_DATA **DeviceDescriptor
);
);
/**
Get platform Redfish host interface protocol data.
Caller should pass NULL in ProtocolRecord to retrive the first protocol record.
@ -48,5 +50,6 @@ EFI_STATUS
RedfishPlatformHostInterfaceProtocolData (
IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
IN UINT8 IndexOfProtocolData
);
);
#endif

View File

@ -37,6 +37,6 @@ RestExLibCreateChild (
IN EFI_REST_EX_CONFIG_TYPE ConfigType,
IN EFI_REST_EX_SERVICE_TYPE ServiceType,
OUT EFI_HANDLE *ChildInstanceHandle
);
);
#endif

View File

@ -47,7 +47,7 @@ typedef struct {
**/
typedef
EFI_STATUS
(EFIAPI *EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_INIT) (
(EFIAPI *EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_INIT)(
IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This,
IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishServiceinfo
);
@ -63,7 +63,7 @@ EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_STOP) (
(EFIAPI *EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_STOP)(
IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This
);
@ -72,7 +72,6 @@ struct _EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL {
EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_STOP Stop;
};
extern EFI_GUID gdkIIRedfishConfigHandlerProtocolGuid;
#endif

View File

@ -34,7 +34,6 @@ typedef enum {
ServiceStopTypeMax
} EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE;
/**
Retrieve platform's Redfish authentication information.
@ -61,7 +60,7 @@ typedef enum {
**/
typedef
EFI_STATUS
(EFIAPI *EDKII_REDFISH_CREDENTIAL_PROTOCOL_GET_AUTH_INFO) (
(EFIAPI *EDKII_REDFISH_CREDENTIAL_PROTOCOL_GET_AUTH_INFO)(
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId,
@ -86,7 +85,7 @@ EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *EDKII_REDFISH_CREDENTIAL_PROTOCOL_STOP_SERVICE) (
(EFIAPI *EDKII_REDFISH_CREDENTIAL_PROTOCOL_STOP_SERVICE)(
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
);

View File

@ -36,7 +36,6 @@ GetUTF8SizeForUCS2 (
TempChar = *Utf8Buffer;
if ((TempChar & 0xF0) == 0xF0) {
//
// This format is not for UCS2.
//
@ -46,11 +45,9 @@ GetUTF8SizeForUCS2 (
Utf8Size = 1;
if ((TempChar & 0x80) == 0x80) {
if ((TempChar & 0xC0) == 0xC0) {
Utf8Size ++;
Utf8Size++;
if ((TempChar & 0xE0) == 0xE0) {
Utf8Size ++;
Utf8Size++;
}
}
}
@ -83,7 +80,7 @@ GetUCS2CharByFormat (
UINT8 Index;
CHAR8 Ucs2CharFormat[UNICODE_FORMAT_CHAR_SIZE]; /// two Hexadecimal digits Ascii string, like "3F"
for (Index = 0; Index < 4; Index ++) {
for (Index = 0; Index < 4; Index++) {
if ((*(Utf8Buffer + 2 + Index) & 0x80) != 0x00) {
return EFI_INVALID_PARAMETER;
}
@ -95,19 +92,19 @@ GetUCS2CharByFormat (
// Get the First Number, Offset is 2
//
CopyMem (Ucs2CharFormat, Utf8Buffer + 2, UNICODE_FORMAT_CHAR_LEN);
Num1 = (UINT8) AsciiStrHexToUintn (Ucs2CharFormat);
Num1 = (UINT8)AsciiStrHexToUintn (Ucs2CharFormat);
//
// Get the Second Number, Offset is 4
//
CopyMem (Ucs2CharFormat, Utf8Buffer + 4, UNICODE_FORMAT_CHAR_LEN);
Num2 = (UINT8) AsciiStrHexToUintn (Ucs2CharFormat);
Num2 = (UINT8)AsciiStrHexToUintn (Ucs2CharFormat);
//
// Ucs2Char is Little-Endian
//
*((CHAR8 *) Ucs2Char) = Num2;
*(((CHAR8 *) Ucs2Char) + 1) = Num1;
*((CHAR8 *)Ucs2Char) = Num2;
*(((CHAR8 *)Ucs2Char) + 1) = Num1;
return EFI_SUCCESS;
}
@ -131,25 +128,22 @@ UCS2CharToUTF8 (
ASSERT (Utf8Buffer != NULL);
Ucs2Number = (UINT16) Ucs2Char;
Ucs2Number = (UINT16)Ucs2Char;
if (Ucs2Number <= 0x007F) {
//
// UTF8 format: 0xxxxxxx
//
*Utf8Buffer = Ucs2Char & 0x7F;
return 1;
} else if (Ucs2Number >= 0x0080 && Ucs2Number <= 0x07FF) {
} else if ((Ucs2Number >= 0x0080) && (Ucs2Number <= 0x07FF)) {
//
// UTF8 format: 110xxxxx 10xxxxxx
//
*(Utf8Buffer + 1) = (Ucs2Char & 0x3F) | 0x80;
*Utf8Buffer = ((Ucs2Char >> 6) & 0x1F) | 0xC0;
return 2;
} else { /// Ucs2Number >= 0x0800 && Ucs2Number <= 0xFFFF
} else {
/// Ucs2Number >= 0x0800 && Ucs2Number <= 0xFFFF
//
// UTF8 format: 1110xxxx 10xxxxxx 10xxxxxx
@ -186,11 +180,10 @@ UTF8ToUCS2Char (
ASSERT (Utf8Buffer != NULL && Ucs2Char != NULL);
ZeroMem (Ucs2Char, sizeof (CHAR16));
Ucs2Buffer = (CHAR8 *) Ucs2Char;
Ucs2Buffer = (CHAR8 *)Ucs2Char;
Utf8Size = GetUTF8SizeForUCS2 (Utf8Buffer);
switch (Utf8Size) {
case 1:
//
@ -283,15 +276,14 @@ UCS2StrToUTF8 (
CHAR8 Utf8Buffer[UTF8_BUFFER_FOR_UCS2_MAX_SIZE];
UINT8 Utf8BufferSize;
if (Ucs2Str == NULL || Utf8StrAddr == NULL) {
if ((Ucs2Str == NULL) || (Utf8StrAddr == NULL)) {
return EFI_INVALID_PARAMETER;
}
Ucs2StrLength = StrLen (Ucs2Str);
Utf8StrLength = 0;
for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex ++) {
for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex++) {
ZeroMem (Utf8Buffer, sizeof (Utf8Buffer));
Utf8BufferSize = UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], Utf8Buffer);
Utf8StrLength += Utf8BufferSize;
@ -303,8 +295,7 @@ UCS2StrToUTF8 (
}
Utf8StrIndex = 0;
for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex ++) {
for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex++) {
ZeroMem (Utf8Buffer, sizeof (Utf8Buffer));
Utf8BufferSize = UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], Utf8Buffer);
@ -345,7 +336,7 @@ UTF8StrToUCS2 (
UINT8 Utf8BufferSize;
CHAR16 *Ucs2StrTemp;
if (Utf8Str == NULL || Ucs2StrAddr == NULL) {
if ((Utf8Str == NULL) || (Ucs2StrAddr == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -354,7 +345,7 @@ UTF8StrToUCS2 (
//
Utf8StrLength = 0;
while (*(Utf8Str + Utf8StrLength) != '\0') {
Utf8StrLength ++;
Utf8StrLength++;
}
//
@ -368,46 +359,39 @@ UTF8StrToUCS2 (
Utf8StrIndex = 0;
Ucs2StrIndex = 0;
while (Utf8Str[Utf8StrIndex] != '\0') {
if (CompareMem (Utf8Str + Utf8StrIndex, "\\u", 2) == 0 &&
Utf8StrLength - Utf8StrIndex >= UNICODE_FORMAT_LEN) {
if ((CompareMem (Utf8Str + Utf8StrIndex, "\\u", 2) == 0) &&
(Utf8StrLength - Utf8StrIndex >= UNICODE_FORMAT_LEN))
{
Status = GetUCS2CharByFormat (Utf8Str + Utf8StrIndex, Ucs2StrTemp + Ucs2StrIndex);
if (!EFI_ERROR (Status)) {
Utf8StrIndex += UNICODE_FORMAT_LEN;
Ucs2StrIndex ++;
Ucs2StrIndex++;
} else {
StrCpyS (Ucs2StrTemp + Ucs2StrIndex, 3, L"\\u");
Ucs2StrIndex += 2;
Utf8StrIndex += 2;
}
} else {
Utf8BufferSize = GetUTF8SizeForUCS2 (Utf8Str + Utf8StrIndex);
if (Utf8BufferSize == 0 || Utf8StrLength - Utf8StrIndex < Utf8BufferSize) {
if ((Utf8BufferSize == 0) || (Utf8StrLength - Utf8StrIndex < Utf8BufferSize)) {
FreePool (Ucs2StrTemp);
return EFI_INVALID_PARAMETER;
}
Status = UTF8ToUCS2Char (Utf8Str + Utf8StrIndex, Ucs2StrTemp + Ucs2StrIndex);
if (EFI_ERROR (Status)) {
FreePool (Ucs2StrTemp);
return EFI_INVALID_PARAMETER;
}
Ucs2StrIndex ++;
Ucs2StrIndex++;
Utf8StrIndex += Utf8BufferSize;
}
}
*Ucs2StrAddr = AllocateZeroPool ((Ucs2StrIndex + 1) * sizeof (CHAR16));
if (*Ucs2StrAddr == NULL) {
FreePool (Ucs2StrTemp);
return EFI_OUT_OF_RESOURCES;
}
@ -418,4 +402,3 @@ UTF8StrToUCS2 (
return EFI_SUCCESS;
}

View File

@ -38,7 +38,7 @@ RestExLibCreateChild (
IN EFI_REST_EX_CONFIG_TYPE ConfigType,
IN EFI_REST_EX_SERVICE_TYPE ServiceType,
OUT EFI_HANDLE *ChildInstanceHandle
)
)
{
EFI_STATUS Status;
UINTN NoBuffer;
@ -48,12 +48,13 @@ RestExLibCreateChild (
EFI_REST_EX_SERVICE_INFO *RestExServiceInfo;
UINT8 LenOfConfig;
if (Image == NULL ||
AccessMode >= EfiRestExServiceModeMax ||
ConfigType >= EfiRestExConfigTypeMax ||
ServiceType >= EfiRestExServiceTypeMax ||
ChildInstanceHandle == NULL
) {
if ((Image == NULL) ||
(AccessMode >= EfiRestExServiceModeMax) ||
(ConfigType >= EfiRestExConfigTypeMax) ||
(ServiceType >= EfiRestExServiceTypeMax) ||
(ChildInstanceHandle == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
@ -70,13 +71,15 @@ RestExLibCreateChild (
&NoBuffer,
&Handle
);
if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
return Status;
}
Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof(EFI_HANDLE) * NoBuffer);
Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof (EFI_HANDLE) * NoBuffer);
if (Handle == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiRestExServiceBindingProtocolGuid,
@ -123,6 +126,7 @@ RestExLibCreateChild (
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
//
// Check REST EX property.
//
@ -138,13 +142,16 @@ RestExLibCreateChild (
default:
goto ON_ERROR;
}
if (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode ||
RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType ||
RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType ||
((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig))) {
if ((RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||
(RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType) ||
(RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType) ||
((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig)))
{
goto ON_ERROR;
}
}
//
// This is proper REST EX instance.
//
@ -159,8 +166,9 @@ ON_ERROR:;
&gEfiRestExServiceBindingProtocolGuid,
ChildHandle
);
NoBuffer --;
};
NoBuffer--;
}
FreePool (Handle);
return EFI_NOT_FOUND;
}

View File

@ -36,7 +36,7 @@ JsonValueInitArray (
VOID
)
{
return (EDKII_JSON_VALUE)json_array();
return (EDKII_JSON_VALUE)json_array ();
}
/**
@ -58,7 +58,7 @@ JsonValueInitObject (
VOID
)
{
return (EDKII_JSON_VALUE)json_object();
return (EDKII_JSON_VALUE)json_object ();
}
/**
@ -201,7 +201,7 @@ JsonValueInitTrue (
VOID
)
{
return (EDKII_JSON_VALUE)json_true();
return (EDKII_JSON_VALUE)json_true ();
}
/**
@ -219,7 +219,7 @@ JsonValueInitFalse (
VOID
)
{
return (EDKII_JSON_VALUE)json_false();
return (EDKII_JSON_VALUE)json_false ();
}
/**
@ -237,7 +237,7 @@ JsonValueInitNull (
VOID
)
{
return (EDKII_JSON_VALUE)json_null();
return (EDKII_JSON_VALUE)json_null ();
}
/**
@ -266,7 +266,7 @@ JsonValueFree (
IN EDKII_JSON_VALUE Json
)
{
json_decref((json_t *)Json);
json_decref ((json_t *)Json);
}
/**
@ -292,7 +292,7 @@ JsonValueClone (
IN EDKII_JSON_VALUE Json
)
{
return (EDKII_JSON_VALUE)json_deep_copy ((json_t *) Json);
return (EDKII_JSON_VALUE)json_deep_copy ((json_t *)Json);
}
/**
@ -310,7 +310,7 @@ JsonValueIsArray (
IN EDKII_JSON_VALUE Json
)
{
return json_is_array ((json_t *) Json);
return json_is_array ((json_t *)Json);
}
/**
@ -328,7 +328,7 @@ JsonValueIsObject (
IN EDKII_JSON_VALUE Json
)
{
return json_is_object ((json_t *) Json);
return json_is_object ((json_t *)Json);
}
/**
@ -347,7 +347,7 @@ JsonValueIsString (
IN EDKII_JSON_VALUE Json
)
{
return json_is_string ((json_t *) Json);
return json_is_string ((json_t *)Json);
}
/**
@ -365,7 +365,7 @@ JsonValueIsInteger (
IN EDKII_JSON_VALUE Json
)
{
return json_is_integer ((json_t *) Json);
return json_is_integer ((json_t *)Json);
}
/**
@ -383,7 +383,7 @@ JsonValueIsNumber (
IN EDKII_JSON_VALUE Json
)
{
return json_is_number ((json_t *) Json);
return json_is_number ((json_t *)Json);
}
/**
@ -401,7 +401,7 @@ JsonValueIsBoolean (
IN EDKII_JSON_VALUE Json
)
{
return json_is_boolean ((json_t *) Json);
return json_is_boolean ((json_t *)Json);
}
/**
@ -422,6 +422,7 @@ JsonValueIsTrue (
if (json_is_true ((json_t *)Json)) {
return TRUE;
}
return FALSE;
}
@ -443,8 +444,10 @@ JsonValueIsFalse (
if (json_is_false ((json_t *)Json)) {
return TRUE;
}
return FALSE;
}
/**
The function is used to return if the provided JSON value contains a JSON NULL.
@ -460,7 +463,7 @@ JsonValueIsNull (
IN EDKII_JSON_VALUE Json
)
{
return json_is_null ((json_t *) Json);
return json_is_null ((json_t *)Json);
}
/**
@ -479,7 +482,7 @@ JsonValueGetArray (
IN EDKII_JSON_VALUE Json
)
{
if (Json == NULL || !JsonValueIsArray (Json)) {
if ((Json == NULL) || !JsonValueIsArray (Json)) {
return NULL;
}
@ -502,7 +505,7 @@ JsonValueGetObject (
IN EDKII_JSON_VALUE Json
)
{
if (Json == NULL || !JsonValueIsObject (Json)) {
if ((Json == NULL) || !JsonValueIsObject (Json)) {
return NULL;
}
@ -528,7 +531,7 @@ JsonValueGetAsciiString (
CONST CHAR8 *AsciiStr;
UINTN Index;
AsciiStr = json_string_value ((json_t *) Json);
AsciiStr = json_string_value ((json_t *)Json);
if (AsciiStr == NULL) {
return NULL;
}
@ -556,7 +559,7 @@ JsonValueGetAsciiString (
@retval Return the associated Unicode string in JSON value or NULL.
**/
CHAR16*
CHAR16 *
EFIAPI
JsonValueGetUnicodeString (
IN EDKII_JSON_VALUE Json
@ -566,12 +569,12 @@ JsonValueGetUnicodeString (
CONST CHAR8 *Utf8Str;
CHAR16 *Ucs2Str;
Utf8Str = json_string_value ((json_t *) Json);
Utf8Str = json_string_value ((json_t *)Json);
if (Utf8Str == NULL) {
return NULL;
}
Status = UTF8StrToUCS2 ((CHAR8*)Utf8Str, &Ucs2Str);
Status = UTF8StrToUCS2 ((CHAR8 *)Utf8Str, &Ucs2Str);
if (EFI_ERROR (Status)) {
return NULL;
}
@ -597,11 +600,11 @@ JsonValueGetInteger (
)
{
ASSERT (Json != NULL && JsonValueIsInteger (Json));
if (Json == NULL || !JsonValueIsInteger (Json)) {
if ((Json == NULL) || !JsonValueIsInteger (Json)) {
return 0;
}
return json_integer_value ((json_t *) Json);
return json_integer_value ((json_t *)Json);
}
/**
@ -622,11 +625,11 @@ JsonValueGetBoolean (
)
{
ASSERT (Json != NULL && JsonValueIsBoolean (Json));
if (Json == NULL || !JsonValueIsBoolean (Json)) {
if ((Json == NULL) || !JsonValueIsBoolean (Json)) {
return FALSE;
}
return json_is_true ((json_t *) Json);
return json_is_true ((json_t *)Json);
}
/**
@ -639,7 +642,7 @@ JsonValueGetBoolean (
@retval Return the associated Ascii string in JSON value or NULL on errors.
**/
CONST CHAR8*
CONST CHAR8 *
EFIAPI
JsonValueGetString (
IN EDKII_JSON_VALUE Json
@ -663,7 +666,7 @@ JsonObjectSize (
IN EDKII_JSON_OBJECT JsonObject
)
{
return json_object_size ((json_t *) JsonObject);
return json_object_size ((json_t *)JsonObject);
}
/**
@ -679,24 +682,23 @@ JsonObjectSize (
JsonObj is not an JSON object, key count is zero or on other errors.
**/
CHAR8**
CHAR8 **
JsonObjectGetKeys (
IN EDKII_JSON_OBJECT JsonObj,
OUT UINTN *KeyCount
)
{
UINTN Index;
CONST CHAR8 **KeyArray;
CONST CHAR8 *Key;
EDKII_JSON_VALUE Value;
if (JsonObj == NULL || KeyCount == NULL) {
if ((JsonObj == NULL) || (KeyCount == NULL)) {
return NULL;
}
Index = 0;
json_object_foreach(JsonObj, Key, Value) {
json_object_foreach (JsonObj, Key, Value) {
Index++;
}
if (Index == 0) {
@ -705,7 +707,7 @@ JsonObjectGetKeys (
}
*KeyCount = Index;
KeyArray = (CONST CHAR8 **) AllocateZeroPool (*KeyCount * sizeof (CHAR8 *));
KeyArray = (CONST CHAR8 **)AllocateZeroPool (*KeyCount * sizeof (CHAR8 *));
if (KeyArray == NULL) {
return NULL;
}
@ -713,7 +715,7 @@ JsonObjectGetKeys (
Key = NULL;
Value = NULL;
Index = 0;
json_object_foreach((json_t *) JsonObj, Key, Value) {
json_object_foreach ((json_t *)JsonObj, Key, Value) {
KeyArray[Index] = Key;
Index++;
}
@ -773,7 +775,7 @@ JsonObjectSetValue (
IN EDKII_JSON_VALUE Json
)
{
if (json_object_set ((json_t *) JsonObj, Key, (json_t *) Json) != 0) {
if (json_object_set ((json_t *)JsonObj, Key, (json_t *)Json) != 0) {
return EFI_ABORTED;
} else {
return EFI_SUCCESS;
@ -795,7 +797,7 @@ JsonArrayCount (
IN EDKII_JSON_ARRAY JsonArray
)
{
return json_array_size ((json_t *) JsonArray);
return json_array_size ((json_t *)JsonArray);
}
/**
@ -821,7 +823,7 @@ JsonArrayGetValue (
IN UINTN Index
)
{
return (EDKII_JSON_VALUE)json_array_get ((json_t *) JsonArray, Index);
return (EDKII_JSON_VALUE)json_array_get ((json_t *)JsonArray, Index);
}
/**
@ -844,7 +846,7 @@ JsonArrayAppendValue (
IN EDKII_JSON_VALUE Json
)
{
if (json_array_append ((json_t *) JsonArray, (json_t *) Json) != 0) {
if (json_array_append ((json_t *)JsonArray, (json_t *)Json) != 0) {
return EFI_ABORTED;
} else {
return EFI_SUCCESS;
@ -872,7 +874,7 @@ JsonArrayRemoveValue (
IN UINTN Index
)
{
if (json_array_remove ((json_t *) JsonArray, Index) != 0) {
if (json_array_remove ((json_t *)JsonArray, Index) != 0) {
return EFI_ABORTED;
} else {
return EFI_SUCCESS;
@ -911,7 +913,8 @@ JsonDumpString (
if (JsonValue == NULL) {
return NULL;
}
return json_dumps((json_t *)JsonValue, Flags);
return json_dumps ((json_t *)JsonValue, Flags);
}
/**
@ -934,12 +937,12 @@ JsonDumpString (
EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
IN CONST CHAR8* String,
IN CONST CHAR8 *String,
IN UINT64 Flags,
IN EDKII_JSON_ERROR *Error
)
{
return (EDKII_JSON_VALUE) json_loads ((const char *)String, Flags, (json_error_t *)Error);
return (EDKII_JSON_VALUE)json_loads ((const char *)String, Flags, (json_error_t *)Error);
}
/**
@ -970,7 +973,7 @@ JsonLoadBuffer (
IN OUT EDKII_JSON_ERROR *Error
)
{
return json_loadb(Buffer, BufferLen, Flags, (json_error_t *)Error);
return json_loadb (Buffer, BufferLen, Flags, (json_error_t *)Error);
}
/**
@ -1044,7 +1047,7 @@ JsonObjectIteratorValue (
IN VOID *Iterator
)
{
return json_object_iter_value(Iterator);
return json_object_iter_value (Iterator);
}
/**
@ -1062,7 +1065,7 @@ JsonObjectIteratorNext (
IN VOID *Iterator
)
{
return json_object_iter_next(JsonValue, Iterator);
return json_object_iter_next (JsonValue, Iterator);
}
/**
@ -1075,9 +1078,9 @@ CHAR8 *
EFIAPI
JsonObjectIteratorKey (
IN VOID *Iterator
)
)
{
return (CHAR8 *)json_object_iter_key(Iterator);
return (CHAR8 *)json_object_iter_key (Iterator);
}
/**
@ -1090,9 +1093,9 @@ VOID *
EFIAPI
JsonObjectKeyToIterator (
IN CHAR8 *Key
)
)
{
return json_object_key_to_iter(Key);
return json_object_key_to_iter (Key);
}
/**

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@
**/
#include <Uefi.h>
#include <Protocol/EdkIIRedfishCredential.h>
/**
Notification of Exit Boot Service.
@ -17,7 +18,7 @@ VOID
EFIAPI
LibCredentialExitBootServicesNotify (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This
)
)
{
return;
}
@ -31,7 +32,7 @@ VOID
EFIAPI
LibCredentialEndOfDxeNotify (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This
)
)
{
return;
}
@ -67,7 +68,7 @@ LibCredentialGetAuthInfo (
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId,
OUT CHAR8 **Password
)
)
{
return EFI_UNSUPPORTED;
}
@ -98,4 +99,3 @@ LibStopRedfishService (
{
return EFI_UNSUPPORTED;
}

View File

@ -25,10 +25,11 @@ EFI_STATUS
RedfishPlatformHostInterfaceDeviceDescriptor (
IN UINT8 *DeviceType,
OUT REDFISH_INTERFACE_DATA **DeviceDescriptor
)
)
{
return EFI_NOT_FOUND;
}
/**
Get platform Redfish host interface protocol data.
Caller should pass NULL in ProtocolRecord to retrive the first protocol record.
@ -46,7 +47,7 @@ EFI_STATUS
RedfishPlatformHostInterfaceProtocolData (
IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
IN UINT8 IndexOfProtocolData
)
)
{
return EFI_NOT_FOUND;
}

View File

@ -7,6 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CRT_STDARG_H_
#define REDFISH_CRT_STDARG_H_

View File

@ -7,6 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CRT_STDIO_H_
#define REDFISH_CRT_STDIO_H_

View File

@ -7,6 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CRT_SYS_TIME_H_
#define REDFISH_CRT_SYS_TIME_H_

View File

@ -7,6 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CRT_SYS_TYPES_H_
#define REDFISH_CRT_SYS_TYPES_H_

View File

@ -7,6 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef REDFISH_CRT_TIME_H_
#define REDFISH_CRT_TIME_H_

View File

@ -80,8 +80,8 @@
///
/// Library class public defines
///
typedef VOID* REDFISH_SERVICE;
typedef VOID* REDFISH_PAYLOAD;
typedef VOID *REDFISH_SERVICE;
typedef VOID *REDFISH_PAYLOAD;
///
/// Library class public structures/unions
@ -97,8 +97,8 @@ typedef struct {
/// Odata type-name mapping structure.
///
typedef struct {
CONST CHAR8 OdataTypeName [ODATA_TYPE_NAME_MAX_SIZE];
CONST CHAR8 OdataType [ODATA_TYPE_MAX_SIZE];
CONST CHAR8 OdataTypeName[ODATA_TYPE_NAME_MAX_SIZE];
CONST CHAR8 OdataType[ODATA_TYPE_MAX_SIZE];
} REDFISH_ODATA_TYPE_MAPPING;
/**
@ -471,6 +471,7 @@ VOID
RedfishDumpPayload (
IN REDFISH_PAYLOAD Payload
);
/**
Dump text in JSON value.
@ -481,6 +482,7 @@ VOID
RedfishDumpJson (
IN EDKII_JSON_VALUE JsonValue
);
/**
This function will cleanup the HTTP header and Redfish payload resources.
@ -528,7 +530,8 @@ RedfishIsValidOdataType (
BOOLEAN
RedfishIsPayloadCollection (
IN REDFISH_PAYLOAD Payload
);
);
/**
Get collection size.
@ -539,10 +542,11 @@ RedfishIsPayloadCollection (
@return EFI_INVALID_PARAMETER The payload is not a collection.
**/
EFI_STATUS
RedfishGetCollectionSize(
RedfishGetCollectionSize (
IN REDFISH_PAYLOAD Payload,
IN UINTN *CollectionSize
);
);
/**
Get Redfish payload of collection member
@ -556,7 +560,7 @@ REDFISH_PAYLOAD
RedfishGetPayloadByIndex (
IN REDFISH_PAYLOAD Payload,
IN UINTN Index
);
);
/**
Check and return Redfish resource of the given Redpath.
@ -572,7 +576,7 @@ RedfishCheckIfRedpathExist (
IN REDFISH_SERVICE RedfishService,
IN CHAR8 *Redpath,
IN REDFISH_RESPONSE *Response OPTIONAL
);
);
/**
This function returns the string of Redfish service version.
@ -584,7 +588,7 @@ RedfishCheckIfRedpathExist (
**/
EFI_STATUS
RedfishGetServiceVersion(
RedfishGetServiceVersion (
IN REDFISH_SERVICE RedfishService,
OUT CHAR8 **ServiceVersionStr
);
@ -608,4 +612,5 @@ RedfishBuildRedpathUseId (
IN CHAR8 *Id,
OUT CHAR8 **Redpath
);
#endif

View File

@ -15,7 +15,7 @@
#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";
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;
@ -24,7 +24,10 @@ 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;
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(
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,7 +176,11 @@ 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;
long long Result = 0;
@ -162,71 +190,86 @@ strtoll(const char * nptr, char ** endptr, int base)
pEnd = nptr;
if((base < 0) || (base == 1) || (base > 36)) {
if(endptr != NULL) {
if ((base < 0) || (base == 1) || (base > 36)) {
if (endptr != NULL) {
*endptr = NULL;
}
return 0;
}
// Skip leading spaces.
while(isspace(*nptr)) ++nptr;
// Process Subject sequence: optional sign followed by digits.
if(*nptr == '+') {
Negative = FALSE;
// Skip leading spaces.
while (isspace (*nptr)) {
++nptr;
}
else if(*nptr == '-') {
// Process Subject sequence: optional sign followed by digits.
if (*nptr == '+') {
Negative = FALSE;
++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 */
}
}
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) {
if ( Result <= Previous) {
// Detect Overflow
if (Negative) {
Result = LLONG_MIN;
}
else {
} else {
Result = LLONG_MAX;
}
Negative = FALSE;
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,7 +328,11 @@ 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;
long Result = 0;
@ -295,71 +342,86 @@ strtol(const char * nptr, char ** endptr, int base)
pEnd = nptr;
if((base < 0) || (base == 1) || (base > 36)) {
if(endptr != NULL) {
if ((base < 0) || (base == 1) || (base > 36)) {
if (endptr != NULL) {
*endptr = NULL;
}
return 0;
}
// Skip leading spaces.
while(isspace(*nptr)) ++nptr;
// Process Subject sequence: optional sign followed by digits.
if(*nptr == '+') {
Negative = FALSE;
// Skip leading spaces.
while (isspace (*nptr)) {
++nptr;
}
else if(*nptr == '-') {
// Process Subject sequence: optional sign followed by digits.
if (*nptr == '+') {
Negative = FALSE;
++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 */
}
}
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) {
if ( Result <= Previous) {
// Detect Overflow
if (Negative) {
Result = LONG_MIN;
}
else {
} else {
Result = LONG_MAX;
}
Negative = FALSE;
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,7 +436,11 @@ 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;
@ -383,57 +449,72 @@ strtoull(const char * nptr, char ** endptr, int base)
pEnd = nptr;
if((base < 0) || (base == 1) || (base > 36)) {
if(endptr != NULL) {
if ((base < 0) || (base == 1) || (base > 36)) {
if (endptr != NULL) {
*endptr = NULL;
}
return 0;
}
// Skip leading spaces.
while(isspace(*nptr)) ++nptr;
// Process Subject sequence: optional + sign followed by digits.
if(*nptr == '+') {
// Skip leading spaces.
while (isspace (*nptr)) {
++nptr;
}
if(*nptr == '0') { /* Might be Octal or Hex */
if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
if((base == 0) || (base == 16)) {
// Process Subject sequence: optional + sign followed by digits.
if (*nptr == '+') {
++nptr;
}
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 */
}
}
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
if ( Result < Previous) {
// If we overflowed
Result = ULLONG_MAX;
errno = ERANGE;
break;
}
pEnd = ++nptr;
}
// Save pointer to final sequence
if(endptr != NULL) {
if (endptr != NULL) {
*endptr = (char *)pEnd;
}
return Result;
}
@ -462,16 +543,19 @@ 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);
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)])
@ -479,7 +563,11 @@ static UINT8 BitMask[] = {
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;
@ -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 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,7 +638,10 @@ 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;
@ -552,12 +649,13 @@ calloc(size_t Num, size_t Size)
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;
}
@ -610,7 +708,10 @@ UINTN CumulativeDays[2][14] = {
/**
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){
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.
@ -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;
}
@ -773,7 +921,7 @@ CheckFormatingString (
CHAR8 *
ReplaceUnicodeToAsciiStrFormat (
IN CONST CHAR8 *FormatString
)
)
{
UINTN FormatStrSize;
UINTN FormatStrIndex;
@ -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
TempFormatBuffer = AllocatePool (FormatStrSize); // Allocate memory for the
// new string.
if (TempFormatBuffer== NULL) {
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),
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;
}
@ -888,6 +1047,7 @@ RedfishAsciiVSPrint (
if (TempFormatBuffer == NULL) {
return 0;
}
LenStrProduced = AsciiVSPrint (StartOfBuffer, BufferSize, (CONST CHAR8 *)TempFormatBuffer, Marker);
FreePool (TempFormatBuffer);
return LenStrProduced;
@ -922,8 +1082,7 @@ RedfishAsciiSPrint (
VA_LIST Marker;
UINTN LenStrProduced;
VA_START(Marker, FormatString);
VA_START (Marker, FormatString);
LenStrProduced = RedfishAsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
return LenStrProduced;
}

View File

@ -69,7 +69,8 @@ ON_EXIT:
if (UserId != NULL) {
FreePool (UserId);
}
if (Password!= NULL) {
if (Password != NULL) {
FreePool (Password);
}
@ -94,6 +95,7 @@ RedfishCleanupService (
cleanupServiceEnumerator (RedfishService);
}
/**
Create REDFISH_PAYLOAD instance in local with JSON represented resource value and
the Redfish Service.
@ -138,7 +140,7 @@ RedfishCleanupPayload (
return;
}
cleanupPayload ((redfishPayload *) Payload);
cleanupPayload ((redfishPayload *)Payload);
}
/**
@ -162,7 +164,7 @@ RedfishJsonInPayload (
return NULL;
}
return ((redfishPayload*)Payload)->json;
return ((redfishPayload *)Payload)->json;
}
/**
@ -193,7 +195,7 @@ RedfishBuildPathWithSystemUuid (
)
{
UINTN BufSize;
CHAR8* RetRedPath;
CHAR8 *RetRedPath;
EFI_GUID SystemUuid;
EFI_STATUS Status;
@ -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.
@ -257,19 +263,19 @@ RedfishGetByService (
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.
@ -317,20 +325,20 @@ RedfishGetByUri (
{
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);
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.
@ -379,13 +390,13 @@ RedfishGetByPayload (
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.
@ -454,13 +467,13 @@ RedfishPatchToUri (
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 (
JsonValue = (EDKII_JSON_VALUE)patchUriFromService (
RedfishService,
Uri,
Content,
@ -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.
@ -535,13 +550,13 @@ RedfishPatchToPayload (
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 (
RedResponse->Payload = (REDFISH_PAYLOAD)patchPayload (
Target,
Payload,
&(RedResponse->StatusCode)
@ -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.
@ -601,13 +618,13 @@ RedfishPostToPayload (
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 (
RedResponse->Payload = (REDFISH_PAYLOAD)postPayload (
Target,
Payload,
&(RedResponse->StatusCode)
@ -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.
@ -673,13 +692,13 @@ RedfishDeleteByUri (
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 (
JsonValue = (EDKII_JSON_VALUE)deleteUriFromService (
RedfishService,
Uri,
&(RedResponse->StatusCode)
@ -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.
@ -736,26 +757,29 @@ RedfishDumpJsonStringFractions (
StringFractionSize = 200;
if (String == NULL) {
return ;
return;
}
DEBUG((DEBUG_INFO, "JSON text:\n"));
DEBUG ((DEBUG_INFO, "JSON text:\n"));
NextFraction = String;
StrLen = AsciiStrLen (String);
if (StrLen == 0) {
return;
}
for (Count = 0; Count < (StrLen / StringFractionSize); Count++) {
BackupChar = *(NextFraction + StringFractionSize);
*(NextFraction + StringFractionSize) = 0;
DEBUG((DEBUG_INFO, "%a", NextFraction));
DEBUG ((DEBUG_INFO, "%a", NextFraction));
*(NextFraction + StringFractionSize) = BackupChar;
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.
@ -773,9 +797,11 @@ RedfishDumpJson (
if (String == NULL) {
return;
}
RedfishDumpJsonStringFractions (String);
FreePool(String);
FreePool (String);
}
/**
Extract the JSON text content from REDFISH_PAYLOAD and dump to debug console.
@ -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.
@ -865,7 +893,7 @@ RedfishIsValidOdataType (
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
@ -899,10 +930,11 @@ RedfishIsValidOdataType (
BOOLEAN
RedfishIsPayloadCollection (
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(
RedfishGetCollectionSize (
IN REDFISH_PAYLOAD Payload,
IN UINTN *CollectionSize
)
{
if (Payload == NULL || CollectionSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (!RedfishIsPayloadCollection(Payload)) {
if ((Payload == NULL) || (CollectionSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
*CollectionSize = (UINTN)getCollectionSize(Payload);
if (!RedfishIsPayloadCollection (Payload)) {
return EFI_INVALID_PARAMETER;
}
*CollectionSize = (UINTN)getCollectionSize (Payload);
return EFI_SUCCESS;
}
/**
Get Redfish payload of collection member
@ -941,18 +975,21 @@ REDFISH_PAYLOAD
RedfishGetPayloadByIndex (
IN REDFISH_PAYLOAD Payload,
IN UINTN Index
)
)
{
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.
@ -975,12 +1012,14 @@ RedfishCheckIfRedpathExist (
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,
@ -989,5 +1028,6 @@ RedfishCheckIfRedpathExist (
} else {
CopyMem ((VOID *)Response, (VOID *)&TempResponse, sizeof (REDFISH_RESPONSE));
}
return EFI_SUCCESS;
}

View File

@ -31,17 +31,20 @@ RedfishGetServiceVersion (
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;
}
@ -71,10 +74,9 @@ RedfishCreateLibredfishService (
IN CHAR8 *Password
)
{
UINTN Flags;
enumeratorAuthentication Auth;
redfishService* Redfish;
redfishService *Redfish;
Redfish = NULL;
@ -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;
}
/**
@ -137,7 +140,7 @@ RedfishGetAuthInfo (
{
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.
@ -183,7 +187,7 @@ RedfishBuildRedpathUseId (
{
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;
}

View File

@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef LIBREDFISH_REDFISH_H_
#define LIBREDFISH_REDFISH_H_

View File

@ -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

View File

@ -38,22 +38,22 @@
#include <jansson.h>
typedef struct {
char* host;
json_t* versions;
char *host;
json_t *versions;
unsigned int flags;
char* sessionToken;
char* basicAuthStr;
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;
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
@ -78,24 +78,74 @@ typedef struct {
unsigned int authType;
union {
struct {
char* username;
char* password;
char *username;
char *password;
} userPass;
struct {
char* token;
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

View File

@ -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
{
typedef struct _redPathNode {
bool isRoot;
bool isIndex;
char* version;
char* nodeName;
char *version;
char *nodeName;
size_t index;
char* op;
char* propName;
char* value;
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

View File

@ -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 char* getStringTill(const char* string, const char* terminator, char** retEnd);
static void
parseNode (
const char *path,
redPathNode *node,
redPathNode **end
);
redPathNode* parseRedPath(const char* path)
static char *
getStringTill (
const char *string,
const char *terminator,
char **retEnd
);
redPathNode *
parseRedPath (
const char *path
)
{
redPathNode* node;
redPathNode* endNode;
char* curPath;
char* end;
redPathNode *node;
redPathNode *endNode;
char *curPath;
char *end;
if(!path || strlen(path) == 0)
{
if (!path || (strlen (path) == 0)) {
return NULL;
}
node = (redPathNode*)calloc(1, sizeof(redPathNode));
if(!node)
{
node = (redPathNode *)calloc (1, sizeof (redPathNode));
if (!node) {
return NULL;
}
if(path[0] == '/')
{
if (path[0] == '/') {
node->isRoot = true;
if(path[1] == 'v')
{
node->version = getVersion(path+1, &curPath);
if(curPath == NULL)
{
if (path[1] == 'v') {
node->version = getVersion (path+1, &curPath);
if (curPath == NULL) {
return node;
}
if(curPath[0] == '/')
{
if (curPath[0] == '/') {
curPath++;
}
node->next = parseRedPath(curPath);
}
else
{
node->next = parseRedPath(path+1);
node->next = parseRedPath (curPath);
} else {
node->next = parseRedPath (path+1);
}
return node;
}
node->isRoot = false;
curPath = getStringTill(path, "/", &end);
curPath = getStringTill (path, "/", &end);
endNode = node;
parseNode(curPath, node, &endNode);
free(curPath);
if(end != NULL)
{
endNode->next = parseRedPath(end+1);
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)
{
if (!node) {
return;
}
cleanupRedPath(node->next);
cleanupRedPath (node->next);
node->next = NULL;
if(node->version)
{
free(node->version);
if (node->version) {
free (node->version);
}
if(node->nodeName)
{
free(node->nodeName);
if (node->nodeName) {
free (node->nodeName);
}
if(node->op)
{
free(node->op);
if (node->op) {
free (node->op);
}
if(node->propName)
{
free(node->propName);
if (node->propName) {
free (node->propName);
}
if(node->value)
{
free(node->value);
if (node->value) {
free (node->value);
}
free(node);
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);
char *indexStart;
char *index;
char *indexEnd;
char *nodeName = getStringTill (path, "[", &indexStart);
size_t tmpIndex;
char* opChars;
char *opChars;
node->nodeName = nodeName;
if(indexStart == NULL)
{
if (indexStart == NULL) {
*end = node;
return;
}
node->next = (redPathNode*)calloc(1, sizeof(redPathNode));
if(!node->next)
{
node->next = (redPathNode *)calloc (1, sizeof (redPathNode));
if (!node->next) {
return;
}
//Skip past [
// Skip past [
indexStart++;
*end = node->next;
index = getStringTill(indexStart, "]", NULL);
tmpIndex = (size_t)strtoull(index, &indexEnd, 0);
if(indexEnd != index)
{
free(index);
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");
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 = (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] == '~')
{
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 = (char *)malloc (tmpIndex+1);
memcpy (node->next->op, opChars, tmpIndex);
node->next->op[tmpIndex] = 0;
node->next->value = strdup(opChars+tmpIndex);
free(index);
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)
{
char *ret;
char *end;
end = strstr ((char *)string, terminator);
if (retEnd) {
*retEnd = end;
}
if(end == NULL)
{
//No terminator
return strdup(string);
if (end == NULL) {
// No terminator
return strdup (string);
}
ret = (char*)malloc((end-string)+1);
memcpy(ret, string, (end-string));
ret = (char *)malloc ((end-string)+1);
memcpy (ret, string, (end-string));
ret[(end-string)] = 0;
return ret;
}

View File

@ -33,7 +33,7 @@ RedfishConfigOnEndOfDxe (
EFI_STATUS Status;
Status = gCredential->StopService (gCredential, ServiceStopTypeSecureBootDisabled);
if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on EndOfDxe: %r", Status));
}
@ -61,7 +61,7 @@ RedfishConfigOnExitBootService (
EFI_STATUS Status;
Status = gCredential->StopService (gCredential, ServiceStopTypeExitBootService);
if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on ExitBootService: %r", Status));
}
}
@ -114,15 +114,17 @@ RedfishConfigCommonInit (
)
{
EFI_STATUS Status;
//
// Locate Redfish Credential Protocol to get credential for
// accessing to Redfish service.
//
Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **) &gCredential);
Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&gCredential);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
return Status;
}
//
// Create EndOfDxe Event.
//
@ -138,6 +140,7 @@ RedfishConfigCommonInit (
DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCTION__));
return Status;
}
//
// Create Exit Boot Service event.
//
@ -155,8 +158,10 @@ RedfishConfigCommonInit (
DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", __FUNCTION__));
return Status;
}
return EFI_SUCCESS;
}
/**
This is the common code to stop EDK2 Redfish feature driver.
@ -167,7 +172,7 @@ RedfishConfigCommonInit (
EFI_STATUS
RedfishConfigCommonStop (
VOID
)
)
{
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer;
@ -182,7 +187,7 @@ RedfishConfigCommonStop (
&NumberOfHandles,
&HandleBuffer
);
if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
return Status;
}
@ -191,18 +196,20 @@ RedfishConfigCommonStop (
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEdkIIRedfishConfigHandlerProtocolGuid,
(VOID**) &ConfigHandler
(VOID **)&ConfigHandler
);
ASSERT_EFI_ERROR (Status);
Status = ConfigHandler->Stop (ConfigHandler);
if (EFI_ERROR (Status) && Status != EFI_UNSUPPORTED) {
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
break;
}
}
return Status;
}
/**
Callback function executed when a Redfish Config Handler Protocol is installed
by EDK2 Redfish Feature Drivers.
@ -233,29 +240,30 @@ RedfishConfigHandlerInitialization (
for (Index = 0; Index < NumberOfHandles; Index++) {
Status = gBS->HandleProtocol (
HandleBuffer [Index],
HandleBuffer[Index],
&gEfiCallerIdGuid,
(VOID **) &Id
(VOID **)&Id
);
if (!EFI_ERROR (Status)) {
continue;
}
Status = gBS->HandleProtocol (
HandleBuffer [Index],
HandleBuffer[Index],
&gEdkIIRedfishConfigHandlerProtocolGuid,
(VOID**) &ConfigHandler
(VOID **)&ConfigHandler
);
ASSERT_EFI_ERROR (Status);
Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
}
//
// Install caller ID to indicate Redfish Configure Handler is initialized.
//
Status = gBS->InstallProtocolInterface (
&HandleBuffer [Index],
&HandleBuffer[Index],
&gEfiCallerIdGuid,
EFI_NATIVE_INTERFACE,
(VOID *)&gRedfishConfigData.CallerId

View File

@ -86,7 +86,7 @@ RedfishConfigCommonInit (
EFI_STATUS
RedfishConfigCommonStop (
VOID
);
);
/**
Callback function executed when a Redfish Config Handler Protocol is installed

View File

@ -48,7 +48,7 @@ EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding = {
VOID
RedfishConfigStopRedfishDiscovery (
VOID
)
)
{
if (gRedfishDiscoverActivated) {
//
@ -57,6 +57,7 @@ RedfishConfigStopRedfishDiscovery (
if (gEfiRedfishDiscoverProtocolEvent != NULL) {
gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
}
//
// Stop Redfish service discovery.
//
@ -161,10 +162,10 @@ RedfishConfigDriverBindingSupported (
//
// Test if REST EX protocol is ready.
//
Status = gBS->OpenProtocol(
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiRestExProtocolGuid,
(VOID**) &RestEx,
(VOID **)&RestEx,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -172,6 +173,7 @@ RedfishConfigDriverBindingSupported (
if (EFI_ERROR (Status)) {
Status = EFI_UNSUPPORTED;
}
NetLibDestroyServiceChild (
ControllerHandle,
This->ImageHandle,
@ -278,6 +280,7 @@ RedfishConfigDriverBindingStop (
if (ControllerHandle == gEfiRedfishDiscoverControllerHandle) {
RedfishConfigStopRedfishDiscovery ();
}
gBS->CloseProtocol (
ControllerHandle,
&gEfiRedfishDiscoverProtocolGuid,
@ -294,6 +297,7 @@ RedfishConfigDriverBindingStop (
gBS->CloseEvent (gRedfishConfigData.Event);
gRedfishConfigData.Event = NULL;
}
return EFI_SUCCESS;
}
@ -368,7 +372,7 @@ RedfishDiscoverProtocolInstalled (
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
DEBUG((DEBUG_INFO, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __FUNCTION__));
DEBUG ((DEBUG_INFO, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __FUNCTION__));
BufferSize = sizeof (EFI_HANDLE);
Status = gBS->LocateHandle (
@ -379,15 +383,16 @@ RedfishDiscoverProtocolInstalled (
&HandleBuffer
);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER_PROTOCOL installed.\n", __FUNCTION__));
DEBUG ((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER_PROTOCOL installed.\n", __FUNCTION__));
}
gRedfishDiscoverActivated = TRUE;
if (gEfiRedfishDiscoverProtocol == NULL) {
gEfiRedfishDiscoverControllerHandle = HandleBuffer;
//
// First time to open EFI_REDFISH_DISCOVER_PROTOCOL.
//
Status = gBS->OpenProtocol(
Status = gBS->OpenProtocol (
gEfiRedfishDiscoverControllerHandle,
&gEfiRedfishDiscoverProtocolGuid,
(VOID **)&gEfiRedfishDiscoverProtocol,
@ -398,30 +403,32 @@ RedfishDiscoverProtocolInstalled (
if (EFI_ERROR (Status)) {
gEfiRedfishDiscoverProtocol = NULL;
gRedfishDiscoverActivated = FALSE;
DEBUG((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __FUNCTION__));
DEBUG ((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __FUNCTION__));
return;
}
}
//
// Check the new found network interface.
//
if (gNetworkInterfaceInstances != NULL) {
FreePool (gNetworkInterfaceInstances);
}
Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList(
Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList (
gEfiRedfishDiscoverProtocol,
gRedfishConfigData.Image,
&gNumberOfNetworkInterfaces,
&gNetworkInterfaceInstances
);
if (EFI_ERROR (Status) || gNumberOfNetworkInterfaces == 0) {
DEBUG((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __FUNCTION__));
if (EFI_ERROR (Status) || (gNumberOfNetworkInterfaces == 0)) {
DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __FUNCTION__));
return;
}
gRedfishDiscoveredToken = AllocateZeroPool (gNumberOfNetworkInterfaces * sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
if (gRedfishDiscoveredToken == NULL) {
DEBUG((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __FUNCTION__));
DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __FUNCTION__));
return;
}
@ -430,7 +437,7 @@ RedfishDiscoverProtocolInstalled (
//
// Loop to discover Redfish service on each network interface.
//
for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < gNumberOfNetworkInterfaces; NetworkInterfaceIndex ++) {
for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < gNumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
//
// Initial this Redfish Discovered Token
//
@ -442,9 +449,10 @@ RedfishDiscoverProtocolInstalled (
&ThisRedfishDiscoveredToken->Event
);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __FUNCTION__));
DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __FUNCTION__));
goto ErrorReturn;
}
ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound = 0;
ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances = NULL;
@ -452,25 +460,27 @@ RedfishDiscoverProtocolInstalled (
// Acquire for Redfish service which is reported by
// Redfish Host Interface.
//
Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService(
Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
gEfiRedfishDiscoverProtocol,
gRedfishConfigData.Image,
ThisNetworkInterface,
EFI_REDFISH_DISCOVER_HOST_INTERFACE,
ThisRedfishDiscoveredToken
);
ThisNetworkInterface ++;
ThisRedfishDiscoveredToken ++;
ThisNetworkInterface++;
ThisRedfishDiscoveredToken++;
}
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "%a: Acquire Redfish service fail.\n", __FUNCTION__));
DEBUG ((DEBUG_ERROR, "%a: Acquire Redfish service fail.\n", __FUNCTION__));
goto ErrorReturn;
}
return;
ErrorReturn:
if (gRedfishDiscoveredToken != NULL) {
FreePool(gRedfishDiscoveredToken);
FreePool (gRedfishDiscoveredToken);
}
}
@ -496,15 +506,18 @@ RedfishConfigHandlerDriverUnload (
RedfishConfigStopRedfishDiscovery ();
if (gRedfishDiscoveredToken != NULL) {
ThisRedfishDiscoveredToken = gRedfishDiscoveredToken;
for (NumberOfNetworkInterfacesIndex = 0; NumberOfNetworkInterfacesIndex < gNumberOfNetworkInterfaces; NumberOfNetworkInterfacesIndex ++) {
for (NumberOfNetworkInterfacesIndex = 0; NumberOfNetworkInterfacesIndex < gNumberOfNetworkInterfaces; NumberOfNetworkInterfacesIndex++) {
if (ThisRedfishDiscoveredToken->Event != NULL) {
gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
}
FreePool (ThisRedfishDiscoveredToken);
ThisRedfishDiscoveredToken ++;
ThisRedfishDiscoveredToken++;
}
gRedfishDiscoveredToken = NULL;
}
return EFI_SUCCESS;
}
@ -546,6 +559,7 @@ RedfishConfigHandlerDriverEntryPoint (
DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__));
return Status;
}
Status = gBS->RegisterProtocolNotify (
&gEfiRedfishDiscoverProtocolGuid,
gEfiRedfishDiscoverProtocolEvent,
@ -582,6 +596,6 @@ RedfishConfigHandlerDriverEntryPoint (
DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI Binding Protocol of EFI Redfish Config driver.", __FUNCTION__));
return Status;
}
return Status;
}

View File

@ -156,4 +156,5 @@ RedfishConfigDriverBindingStop (
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
#endif

View File

@ -85,11 +85,11 @@ RedfishCredentialGetAuthInfo (
OUT CHAR8 **Password
)
{
if (This == NULL || AuthMethod == NULL || UserId == NULL || Password == NULL) {
if ((This == NULL) || (AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
return EFI_INVALID_PARAMETER;
}
return LibCredentialGetAuthInfo (This, AuthMethod, UserId,Password);
return LibCredentialGetAuthInfo (This, AuthMethod, UserId, Password);
}
/**

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef EDKII_REDFISH_CREDENTIAL_DXE_H_
#define EDKII_REDFISH_CREDENTIAL_DXE_H_
@ -72,4 +73,5 @@ RedfishCredentialStopService (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
);
#endif

View File

@ -13,6 +13,7 @@
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@ -93,7 +94,6 @@ RedfishDiscoverComponentNameGetControllerName (
OUT CHAR16 **ControllerName
);
///
/// Component Name Protocol instance
///
@ -109,8 +109,8 @@ EFI_COMPONENT_NAME_PROTOCOL gRedfishDiscoverComponentName = {
///
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME2_PROTOCOL gRedfishDiscoverComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) RedfishDiscoverComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) RedfishDiscoverComponentNameGetControllerName,
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)RedfishDiscoverComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)RedfishDiscoverComponentNameGetControllerName,
"en"
};

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@
#define EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL TPL_NOTIFY
//
//GUID definitions
// GUID definitions
//
#define EFI_REDFISH_DISCOVER_TCP4_INSTANCE_GUID \
@ -135,7 +135,7 @@ EFI_STATUS
(EFIAPI *EFI_REDFISH_DISCOVER_GET_SUBNET_INFO)(
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
);
);
//
// The require network protocol matrix.

View File

@ -52,17 +52,17 @@ RedfishGetHostInterfaceProtocolData (
//
// Check Interface Type, should be Network Host Interface = 40h
//
mType42Record = (SMBIOS_TABLE_TYPE42 *) Record;
mType42Record = (SMBIOS_TABLE_TYPE42 *)Record;
if (mType42Record->InterfaceType == MCHostInterfaceTypeNetworkHostInterface) {
ASSERT (Record->Length >= 9);
Offset = 5;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
//
// Get interface specific data length.
//
SpecificDataLen = *RecordTmp;
Offset += 1;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
//
// Check Device Type, only PCI/PCIe Network Interface v2 is supported now.
@ -71,23 +71,23 @@ RedfishGetHostInterfaceProtocolData (
ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
*DeviceDescriptor = (REDFISH_INTERFACE_DATA *)RecordTmp;
Offset = Offset + SpecificDataLen;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
//
// Check Protocol count. if > 1, only use the first protocol.
//
ASSERT (*RecordTmp == 1);
Offset += 1;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
//
// Check protocol identifier.
//
if (*RecordTmp == MCHostInterfaceProtocolTypeRedfishOverIP) {
Offset += 1;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
ProtocolLength = *RecordTmp;
Offset += 1;
RecordTmp = (UINT8 *) Record + Offset;
RecordTmp = (UINT8 *)Record + Offset;
//
// This SMBIOS record is invalid, if the length of protocol specific data for
@ -104,12 +104,14 @@ RedfishGetHostInterfaceProtocolData (
if (Offset > mType42Record->Hdr.Length) {
return EFI_SECURITY_VIOLATION;
}
*ProtocolData = (REDFISH_OVER_IP_PROTOCOL_DATA *)RecordTmp;
return EFI_SUCCESS;
}
}
}
}
Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
}

View File

@ -57,20 +57,25 @@ RedfishCreateSmbiosTable42 (
DEBUG ((DEBUG_ERROR, "%a: No Redfish host interface descriptor is provided on this platform.", __FUNCTION__));
return EFI_NOT_FOUND;
}
DEBUG((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTION__, Status));
DEBUG ((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTION__, Status));
return Status;
}
if (DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 &&
DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2
) {
if ((DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) &&
(DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2)
)
{
DEBUG ((DEBUG_ERROR, "%a: Only support either protocol type 04h or 05h as Redfish host interface.", __FUNCTION__));
return EFI_UNSUPPORTED;
}
if (DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
DeviceDataLength = DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.Length;
} else {
DeviceDataLength = DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.Length;
}
//
// Loop to get platform Redfish host interface protocol type data.
//
@ -86,17 +91,21 @@ RedfishCreateSmbiosTable42 (
if (Status == EFI_NOT_FOUND) {
break;
}
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Fail to get Redfish host interafce protocol type data.", __FUNCTION__));
if (ProtocolRecords != NULL) {
FreePool (ProtocolRecords);
}
if (ProtocolRecord != NULL) {
FreePool (ProtocolRecord);
}
return Status;
}
ProtocolDataSize = sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - sizeof(ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen;
ProtocolDataSize = sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - sizeof (ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen;
NewProtocolsDataLength += ProtocolDataSize;
if (ProtocolRecords == NULL) {
ProtocolRecords = AllocateZeroPool (NewProtocolsDataLength);
@ -104,29 +113,34 @@ RedfishCreateSmbiosTable42 (
FreePool (ProtocolRecord);
return EFI_OUT_OF_RESOURCES;
}
CopyMem ((VOID *)ProtocolRecords, (VOID *)ProtocolRecord, ProtocolDataSize);
NewProtocolRecords = ProtocolRecords;
} else {
NewProtocolRecords = ReallocatePool(CurrentProtocolsDataLength, NewProtocolsDataLength, (VOID *)ProtocolRecords);
NewProtocolRecords = ReallocatePool (CurrentProtocolsDataLength, NewProtocolsDataLength, (VOID *)ProtocolRecords);
if (NewProtocolRecords == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish host interface protocol data."));
FreePool (ProtocolRecords);
FreePool (ProtocolRecord);
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
(VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLength),
(VOID *)ProtocolRecord,
ProtocolDataSize
);
}
FreePool (ProtocolRecord);
CurrentProtocolsDataLength = NewProtocolsDataLength;
ProtocolCount ++;
};
ProtocolCount++;
}
if (ProtocolCount == 0) {
goto ON_EXIT;
}
//
// Construct SMBIOS Type 42h for Redfish host inteface.
//
@ -140,7 +154,7 @@ RedfishCreateSmbiosTable42 (
// 06h+n number of protocols defined for the host interface (typically 1)
// 07h+n Include a Protocol Record for each protocol supported.
//
Type42Record = (SMBIOS_TABLE_TYPE42 *) AllocateZeroPool (
Type42Record = (SMBIOS_TABLE_TYPE42 *)AllocateZeroPool (
sizeof (SMBIOS_TABLE_TYPE42) - 4
+ DeviceDataLength
+ 1 /// For Protocol Record Count
@ -189,7 +203,7 @@ RedfishCreateSmbiosTable42 (
//
// 5. Add Redfish interface data record to SMBIOS table 42
//
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
@ -199,24 +213,28 @@ RedfishCreateSmbiosTable42 (
Smbios,
NULL,
&MemArrayMappedAddrSmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*) Type42Record
(EFI_SMBIOS_TABLE_HEADER *)Type42Record
);
DEBUG ((DEBUG_INFO, "RedfishPlatformDxe: Smbios->Add() - %r\n", Status));
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
Status = EFI_SUCCESS;
ON_EXIT:
if (DeviceDescriptor != NULL) {
FreePool (DeviceDescriptor);
}
if (NewProtocolRecords != NULL) {
FreePool (NewProtocolRecords);
}
if (Type42Record != NULL) {
FreePool (Type42Record);
}
return Status;
}

View File

@ -18,6 +18,7 @@
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@ -113,8 +114,8 @@ EFI_COMPONENT_NAME_PROTOCOL gRedfishRestExComponentName = {
///
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME2_PROTOCOL gRedfishRestExComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) RedfishRestExComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) RedfishRestExComponentNameGetControllerName,
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)RedfishRestExComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)RedfishRestExComponentNameGetControllerName,
"en"
};

View File

@ -47,14 +47,14 @@ RestExDestroyChildEntryInHandleBuffer (
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
if (Entry == NULL || Context == NULL) {
if ((Entry == NULL) || (Context == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = NET_LIST_USER_STRUCT_S (Entry, RESTEX_INSTANCE, Link, RESTEX_INSTANCE_SIGNATURE);
ServiceBinding = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
NumberOfChildren = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
ChildHandleBuffer = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
ServiceBinding = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ServiceBinding;
NumberOfChildren = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->NumberOfChildren;
ChildHandleBuffer = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ChildHandleBuffer;
if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {
return EFI_SUCCESS;
@ -354,7 +354,6 @@ RedfishRestExDriverBindingSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
//
// Test for the HttpServiceBinding Protocol.
//
@ -366,7 +365,6 @@ RedfishRestExDriverBindingSupported (
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
}
/**
@ -420,7 +418,7 @@ RedfishRestExDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiCallerIdGuid,
(VOID **) &Id,
(VOID **)&Id,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -538,7 +536,7 @@ RedfishRestExDriverBindingStop (
Status = gBS->OpenProtocol (
NicHandle,
&gEfiRestExServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
(VOID **)&ServiceBinding,
This->DriverBindingHandle,
NicHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -565,7 +563,7 @@ RedfishRestExDriverBindingStop (
);
}
if (NumberOfChildren == 0 && IsListEmpty (&RestExSb->RestExChildrenList)) {
if ((NumberOfChildren == 0) && IsListEmpty (&RestExSb->RestExChildrenList)) {
gBS->UninstallProtocolInterface (
NicHandle,
&gEfiRestExServiceBindingProtocolGuid,
@ -627,6 +625,7 @@ RedfishRestExServiceBindingCreateChild (
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (Instance != NULL);
//
@ -650,7 +649,7 @@ RedfishRestExServiceBindingCreateChild (
Status = gBS->OpenProtocol (
RestExSb->HttpChildHandle,
&gEfiHttpProtocolGuid,
(VOID **) &Http,
(VOID **)&Http,
gRedfishRestExDriverBinding.DriverBindingHandle,
Instance->ChildHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@ -672,7 +671,7 @@ RedfishRestExServiceBindingCreateChild (
Status = gBS->OpenProtocol (
Instance->HttpIo.Handle,
&gEfiHttpProtocolGuid,
(VOID **) &Http,
(VOID **)&Http,
gRedfishRestExDriverBinding.DriverBindingHandle,
Instance->ChildHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@ -758,7 +757,7 @@ RedfishRestExServiceBindingDestroyChild (
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiRestExProtocolGuid,
(VOID **) &RestEx,
(VOID **)&RestEx,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -800,7 +799,6 @@ RedfishRestExServiceBindingDestroyChild (
ChildHandle
);
gBS->RestoreTPL (OldTpl);
//
@ -828,4 +826,3 @@ RedfishRestExServiceBindingDestroyChild (
RestExDestroyInstance (Instance);
return EFI_SUCCESS;
}

View File

@ -66,7 +66,6 @@ typedef struct _RESTEX_INSTANCE RESTEX_INSTANCE;
#define RESTEX_INSTANCE_FROM_THIS(a) \
CR (a, RESTEX_INSTANCE, RestEx, RESTEX_INSTANCE_SIGNATURE)
#define RESTEX_STATE_UNCONFIGED 0
#define RESTEX_STATE_CONFIGED 1
@ -359,6 +358,7 @@ RedfishRestExEventService (
IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
IN EFI_REST_EX_TOKEN *RestExToken
);
/**
Create a new TLS session becuase the previous on is closed.
status.
@ -372,8 +372,7 @@ RedfishRestExEventService (
EFI_STATUS
ResetHttpTslSession (
IN RESTEX_INSTANCE *Instance
);
);
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@ -419,7 +418,6 @@ RestExCreateInstance (
OUT RESTEX_INSTANCE **Instance
);
/**
Release all the resource used the RestEx service binding instance.
@ -647,4 +645,5 @@ RedfishRestExServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@ -23,7 +23,7 @@
EFI_STATUS
ResetHttpTslSession (
IN RESTEX_INSTANCE *Instance
)
)
{
EFI_STATUS Status;
@ -34,12 +34,15 @@ ResetHttpTslSession (
DEBUG ((DEBUG_ERROR, "%a: Error to reset HTTP instance.\n", __FUNCTION__));
return Status;
}
Status = Instance->HttpIo.Http->Configure(Instance->HttpIo.Http, &((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData);
Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, &((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Error to re-initiate HTTP instance.\n", __FUNCTION__));
}
return Status;
}
/**
This function check
@ -62,9 +65,9 @@ RedfishCheckHttpReceiveStatus (
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
if (!EFI_ERROR (HttpIoReceiveStatus)){
if (!EFI_ERROR (HttpIoReceiveStatus)) {
ReturnStatus = EFI_SUCCESS;
} else if (EFI_ERROR (HttpIoReceiveStatus) && HttpIoReceiveStatus != EFI_CONNECTION_FIN) {
} else if (EFI_ERROR (HttpIoReceiveStatus) && (HttpIoReceiveStatus != EFI_CONNECTION_FIN)) {
if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY) == 0) {
DEBUG ((DEBUG_ERROR, "%a: TCP error, reset HTTP session.\n", __FUNCTION__));
Instance->Flags |= RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY;
@ -85,19 +88,22 @@ RedfishCheckHttpReceiveStatus (
DEBUG ((DEBUG_ERROR, "%a: REST_EX Send and receive fail even with a new TLS session.\n", __FUNCTION__));
ReturnStatus = EFI_DEVICE_ERROR;
}
Instance->Flags |= RESTEX_INSTANCE_FLAGS_TLS_RETRY;
Status = ResetHttpTslSession (Instance);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Reset HTTP instance fail.\n", __FUNCTION__));
ReturnStatus = EFI_DEVICE_ERROR;
}
return EFI_NOT_READY;
}
}
//
// Clean TLS new session retry and error try flags.
//
Instance->Flags &= ~ (RESTEX_INSTANCE_FLAGS_TLS_RETRY | RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY);
Instance->Flags &= ~(RESTEX_INSTANCE_FLAGS_TLS_RETRY | RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY);
return ReturnStatus;
}
@ -132,7 +138,7 @@ RedfishHttpAddExpectation (
{
EFI_HTTP_HEADER *NewHeaders;
if (This == NULL || RequestMessage == NULL) {
if ((This == NULL) || (RequestMessage == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -142,16 +148,17 @@ RedfishHttpAddExpectation (
}
if ((RequestMessage->Data.Request->Method != HttpMethodPut) && (RequestMessage->Data.Request->Method != HttpMethodPost) &&
(RequestMessage->Data.Request->Method != HttpMethodPatch)) {
(RequestMessage->Data.Request->Method != HttpMethodPatch))
{
return EFI_SUCCESS;
}
*ItsWrite = TRUE;
NewHeaders = AllocateZeroPool((RequestMessage->HeaderCount + 1) * sizeof(EFI_HTTP_HEADER));
CopyMem ((VOID*)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + 1) * sizeof (EFI_HTTP_HEADER));
CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
HttpSetFieldNameAndValue (NewHeaders + RequestMessage->HeaderCount, HTTP_HEADER_EXPECT, HTTP_EXPECT_100_CONTINUE);
RequestMessage->HeaderCount ++;
RequestMessage->HeaderCount++;
RequestMessage->Headers = NewHeaders;
return EFI_SUCCESS;
}

View File

@ -320,6 +320,7 @@ RedfishRestExEventService (
IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
IN EFI_REST_EX_TOKEN *RestExToken
);
/**
Create a new TLS session becuase the previous on is closed.
status.
@ -333,8 +334,7 @@ RedfishRestExEventService (
EFI_STATUS
ResetHttpTslSession (
IN RESTEX_INSTANCE *Instance
);
);
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@ -380,7 +380,6 @@ RestExCreateInstance (
OUT RESTEX_INSTANCE **Instance
);
/**
Release all the resource used the RestEx service binding instance.
@ -608,4 +607,5 @@ RedfishRestExServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@ -75,7 +75,7 @@ RedfishRestExSendReceive (
//
// Validate the parameters
//
if ((This == NULL) || (RequestMessage == NULL) || ResponseMessage == NULL) {
if ((This == NULL) || (RequestMessage == NULL) || (ResponseMessage == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -101,17 +101,19 @@ RedfishRestExSendReceive (
if (EFI_ERROR (Status)) {
return Status;
}
if (ItsWrite == TRUE) {
if (RequestMessage->BodyLength > HTTP_IO_MAX_SEND_PAYLOAD) {
//
// Send chunked transfer.
//
SendChunkProcess ++;
SendChunkProcess++;
CopyMem ((VOID *)&ChunkTransferRequestMessage, (VOID *)RequestMessage, sizeof (EFI_HTTP_MESSAGE));
} else {
SendNonChunkProcess ++;
SendNonChunkProcess++;
}
}
ReSendRequest:;
//
// Send out the request to REST service.
@ -127,7 +129,7 @@ ReSendRequest:;
// following request message body using chunk transfer.
//
do {
Status = HttpIoSendChunkedTransfer(
Status = HttpIoSendChunkedTransfer (
&(Instance->HttpIo),
&SendChunkProcess,
&ChunkTransferRequestMessage
@ -141,20 +143,20 @@ ReSendRequest:;
// This is the non-chunk transfer, send request header first and then
// handle the following request message body using chunk transfer.
//
Status = HttpIoSendRequest(
Status = HttpIoSendRequest (
&(Instance->HttpIo),
(SendNonChunkProcess == HttpIoSendNonChunkContent)? NULL: RequestMessage->Data.Request,
(SendNonChunkProcess == HttpIoSendNonChunkContent)? 0: RequestMessage->HeaderCount,
(SendNonChunkProcess == HttpIoSendNonChunkContent)? NULL: RequestMessage->Headers,
(SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent)? 0: RequestMessage->BodyLength,
(SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent)? NULL: RequestMessage->Body
(SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Data.Request,
(SendNonChunkProcess == HttpIoSendNonChunkContent) ? 0 : RequestMessage->HeaderCount,
(SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Headers,
(SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? 0 : RequestMessage->BodyLength,
(SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? NULL : RequestMessage->Body
);
}
} else {
//
// This is read from URI.
//
Status = HttpIoSendRequest(
Status = HttpIoSendRequest (
&(Instance->HttpIo),
RequestMessage->Data.Request,
RequestMessage->HeaderCount,
@ -163,6 +165,7 @@ ReSendRequest:;
RequestMessage->Body
);
}
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
@ -173,20 +176,20 @@ ReSendRequest:;
// Clean the previous buffers and all of them will be allocated later according to the actual situation.
//
if (ResponseMessage->Data.Response != NULL) {
FreePool(ResponseMessage->Data.Response);
FreePool (ResponseMessage->Data.Response);
ResponseMessage->Data.Response = NULL;
}
ResponseMessage->BodyLength = 0;
if (ResponseMessage->Body != NULL) {
FreePool(ResponseMessage->Body);
FreePool (ResponseMessage->Body);
ResponseMessage->Body = NULL;
}
//
// Use zero BodyLength to only receive the response headers.
//
ResponseData = AllocateZeroPool (sizeof(HTTP_IO_RESPONSE_DATA));
ResponseData = AllocateZeroPool (sizeof (HTTP_IO_RESPONSE_DATA));
if (ResponseData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
@ -206,13 +209,14 @@ ReSendRequest:;
} else if (Status == EFI_DEVICE_ERROR) {
goto ON_EXIT;
}
//
// Restore the headers if it ever changed in RedfishHttpAddExpectation().
//
if (RequestMessage->Headers != PreservedRequestHeaders) {
FreePool (RequestMessage->Headers);
RequestMessage->Headers = PreservedRequestHeaders; // Restore headers before we adding "Expect".
RequestMessage->HeaderCount --; // Minus one header count for "Expect".
RequestMessage->HeaderCount--; // Minus one header count for "Expect".
}
DEBUG ((DEBUG_INFO, "HTTP Response StatusCode - %d:", ResponseData->Response.StatusCode));
@ -221,7 +225,7 @@ ReSendRequest:;
if (SendChunkProcess == HttpIoSendChunkHeaderZeroContent) {
DEBUG ((DEBUG_INFO, "This is chunk transfer, start to send all chunks.", ResponseData->Response.StatusCode));
SendChunkProcess ++;
SendChunkProcess++;
goto ReSendRequest;
}
} else if (ResponseData->Response.StatusCode == HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE) {
@ -229,7 +233,7 @@ ReSendRequest:;
Status = EFI_BAD_BUFFER_SIZE;
goto ON_EXIT;
} else if (ResponseData->Response.StatusCode == HTTP_STATUS_405_METHOD_NOT_ALLOWED){
} else if (ResponseData->Response.StatusCode == HTTP_STATUS_405_METHOD_NOT_ALLOWED) {
DEBUG ((DEBUG_ERROR, "HTTP_STATUS_405_METHOD_NOT_ALLOWED\n"));
Status = EFI_ACCESS_DENIED;
@ -238,7 +242,7 @@ ReSendRequest:;
DEBUG ((DEBUG_INFO, "HTTP_STATUS_400_BAD_REQUEST\n"));
if (SendChunkProcess == HttpIoSendChunkHeaderZeroContent) {
DEBUG ((DEBUG_INFO, "Bad request may caused by zero length chunk. Try to send all chunks...\n"));
SendChunkProcess ++;
SendChunkProcess++;
goto ReSendRequest;
}
} else if (ResponseData->Response.StatusCode == HTTP_STATUS_100_CONTINUE) {
@ -248,22 +252,25 @@ ReSendRequest:;
// We get HTTP_STATUS_100_CONTINUE to send the body using chunk transfer.
//
DEBUG ((DEBUG_INFO, "HTTP_STATUS_100_CONTINUE for chunk transfer...\n"));
SendChunkProcess ++;
SendChunkProcess++;
goto ReSendRequest;
}
if (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) {
DEBUG ((DEBUG_INFO, "HTTP_STATUS_100_CONTINUE for non chunk transfer...\n"));
SendNonChunkProcess ++;
SendNonChunkProcess++;
goto ReSendRequest;
}
//
// It's the REST protocol's responsibility to handle the interim HTTP response (e.g. 100 Continue Informational),
// and return the final response content to the caller.
//
if (ResponseData->Headers != NULL && ResponseData->HeaderCount != 0) {
if ((ResponseData->Headers != NULL) && (ResponseData->HeaderCount != 0)) {
FreePool (ResponseData->Headers);
}
ZeroMem (ResponseData, sizeof(HTTP_IO_RESPONSE_DATA));
ZeroMem (ResponseData, sizeof (HTTP_IO_RESPONSE_DATA));
Status = HttpIoRecvResponse (
&(Instance->HttpIo),
TRUE,
@ -296,7 +303,7 @@ ReSendRequest:;
//
if (ResponseMessage->HeaderCount > 0) {
Status = HttpIoGetContentLength (ResponseMessage->HeaderCount, ResponseMessage->Headers, &ResponseMessage->BodyLength);
if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
goto ON_EXIT;
}
@ -315,13 +322,15 @@ ReSendRequest:;
&ChunkListLink,
&ResponseMessage->BodyLength
);
if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
goto ON_EXIT;
}
if (Status == EFI_SUCCESS &&
ChunkListLink != NULL &&
!IsListEmpty(ChunkListLink) &&
ResponseMessage->BodyLength != 0) {
if ((Status == EFI_SUCCESS) &&
(ChunkListLink != NULL) &&
!IsListEmpty (ChunkListLink) &&
(ResponseMessage->BodyLength != 0))
{
IsGetChunkedTransfer = TRUE;
//
// Copy data to Message body.
@ -332,27 +341,31 @@ ReSendRequest:;
Status = EFI_OUT_OF_RESOURCES;
CopyChunkData = FALSE;
}
Index = 0;
while (!IsListEmpty(ChunkListLink)) {
while (!IsListEmpty (ChunkListLink)) {
ThisChunk = (HTTP_IO_CHUNKS *)GetFirstNode (ChunkListLink);
if (CopyChunkData) {
CopyMem(((UINT8 *)ResponseMessage->Body + Index), (UINT8 *)ThisChunk->Data, ThisChunk->Length);
CopyMem (((UINT8 *)ResponseMessage->Body + Index), (UINT8 *)ThisChunk->Data, ThisChunk->Length);
Index += ThisChunk->Length;
}
RemoveEntryList (&ThisChunk->NextChunk);
FreePool ((VOID *)ThisChunk->Data);
FreePool ((VOID *)ThisChunk);
};
}
FreePool ((VOID *)ChunkListLink);
}
}
Status = EFI_SUCCESS;
}
//
// Ready to return the Body from REST service if have any.
//
if (ResponseMessage->BodyLength > 0 && !IsGetChunkedTransfer) {
if ((ResponseMessage->BodyLength > 0) && !IsGetChunkedTransfer) {
ResponseData->HeaderCount = 0;
ResponseData->Headers = NULL;
@ -368,7 +381,7 @@ ReSendRequest:;
TotalReceivedSize = 0;
while (TotalReceivedSize < ResponseMessage->BodyLength) {
ResponseData->BodyLength = ResponseMessage->BodyLength - TotalReceivedSize;
ResponseData->Body = (CHAR8 *) ResponseMessage->Body + TotalReceivedSize;
ResponseData->Body = (CHAR8 *)ResponseMessage->Body + TotalReceivedSize;
Status = HttpIoRecvResponse (
&(Instance->HttpIo),
FALSE,
@ -380,8 +393,10 @@ ReSendRequest:;
TotalReceivedSize += ResponseData->BodyLength;
}
DEBUG ((DEBUG_INFO, "Total of lengh of Response :%d\n", TotalReceivedSize));
}
DEBUG ((DEBUG_INFO, "RedfishRestExSendReceive()- EFI_STATUS: %r\n", Status));
ON_EXIT:
@ -401,6 +416,7 @@ ON_EXIT:
ResponseMessage->Body = NULL;
}
}
return Status;
}
@ -480,7 +496,7 @@ RedfishRestExGetService (
ServiceInfo = NULL;
if (This == NULL || RestExServiceInfo == NULL) {
if ((This == NULL) || (RestExServiceInfo == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -601,9 +617,10 @@ RedfishRestExConfigure (
if (Instance->ConfigData != NULL) {
if (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node != NULL) {
FreePool(((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node);
FreePool (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node);
}
FreePool(Instance->ConfigData);
FreePool (Instance->ConfigData);
Instance->ConfigData = NULL;
}
@ -614,6 +631,7 @@ RedfishRestExConfigure (
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
Instance->HttpIo.Timeout = ((EFI_REST_EX_HTTP_CONFIG_DATA *)RestExConfigData)->SendReceiveTimeout;
Instance->ConfigData = AllocateZeroPool (sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
@ -621,6 +639,7 @@ RedfishRestExConfigure (
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
CopyMem (Instance->ConfigData, RestExConfigData, sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
if (HttpConfigData->LocalAddressIsIPv6 == TRUE) {
((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv6Node = AllocateZeroPool (sizeof (EFI_HTTPv6_ACCESS_POINT));
@ -628,6 +647,7 @@ RedfishRestExConfigure (
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
CopyMem (
((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv6Node,
HttpConfigData->AccessPoint.IPv6Node,
@ -639,12 +659,14 @@ RedfishRestExConfigure (
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
CopyMem (
((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node,
HttpConfigData->AccessPoint.IPv4Node,
sizeof (EFI_HTTPv4_ACCESS_POINT)
);
}
Instance->State = RESTEX_STATE_CONFIGED;
}
@ -732,4 +754,3 @@ RedfishRestExEventService (
{
return EFI_UNSUPPORTED;
}

View File

@ -39,7 +39,7 @@ RestJsonStructureRegister (
IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE ToStructure,
IN EFI_REST_JSON_STRUCTURE_TO_JSON ToJson,
IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure
)
)
{
UINTN NumberOfNS;
UINTN Index;
@ -48,12 +48,13 @@ RestJsonStructureRegister (
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId;
EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp;
if (This == NULL ||
ToStructure == NULL ||
ToJson == NULL ||
DestroyStructure == NULL ||
JsonStructureSupported == NULL
) {
if ((This == NULL) ||
(ToStructure == NULL) ||
(ToJson == NULL) ||
(DestroyStructure == NULL) ||
(JsonStructureSupported == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
@ -67,15 +68,16 @@ RestJsonStructureRegister (
break;
} else {
ThisList = ThisList->ForwardLink;
NumberOfNS ++;
NumberOfNS++;
}
}
};
Instance =
(REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
InitializeListHead (&Instance->NextRestJsonStructureInstance);
Instance->NumberOfNameSpaceToConvert = NumberOfNS;
Instance->SupportedRsrcIndentifier = (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1);
@ -84,11 +86,12 @@ RestJsonStructureRegister (
//
CloneSupportedInterpId = Instance->SupportedRsrcIndentifier;
ThisSupportedInterp = JsonStructureSupported;
for (Index = 0; Index < NumberOfNS; Index ++) {
for (Index = 0; Index < NumberOfNS; Index++) {
CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;
CloneSupportedInterpId ++;
CloneSupportedInterpId++;
}
Instance->JsonToStructure = ToStructure;
Instance->StructureToJson = ToJson;
Instance->DestroyStructure = DestroyStructure;
@ -122,11 +125,12 @@ InterpreterInstanceToStruct (
EFI_STATUS Status;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
if (This == NULL ||
InterpreterInstance == NULL ||
ResourceRaw == NULL ||
RestJSonHeader == NULL
) {
if ((This == NULL) ||
(InterpreterInstance == NULL) ||
(ResourceRaw == NULL) ||
(RestJSonHeader == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
@ -147,14 +151,17 @@ InterpreterInstanceToStruct (
// Check if the namesapce and version is supported by this interpreter.
//
ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
if (AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.ResourceTypeName,
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
) == 0)
{
if ((RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) &&
(RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) &&
(RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)
) {
)
{
//
// Don't check version of this resource type identifier.
//
@ -171,13 +178,17 @@ InterpreterInstanceToStruct (
//
if ((AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.MajorVersion,
ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MajorVersion
) == 0) &&
(AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.MinorVersion,
ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MinorVersion
) == 0) &&
(AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.ErrataVersion,
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
) == 0))
{
Status = InterpreterInstance->JsonToStructure (
This,
RsrcTypeIdentifier,
@ -188,11 +199,14 @@ InterpreterInstanceToStruct (
}
}
}
ThisSupportedRsrcTypeId ++;
ThisSupportedRsrcTypeId++;
}
}
return Status;
}
/**
This function converts JSON C structure to JSON property.
@ -211,27 +225,30 @@ InterpreterEfiStructToInstance (
IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,
OUT CHAR8 **ResourceRaw
)
)
{
UINTN Index;
EFI_STATUS Status;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier;
if (This == NULL ||
InterpreterInstance == NULL ||
RestJSonHeader == NULL ||
ResourceRaw == NULL
) {
if ((This == NULL) ||
(InterpreterInstance == NULL) ||
(RestJSonHeader == NULL) ||
(ResourceRaw == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
RsrcTypeIdentifier = &RestJSonHeader->JsonRsrcIdentifier;
if (RsrcTypeIdentifier == NULL ||
RsrcTypeIdentifier->NameSpace.ResourceTypeName == NULL ||
RsrcTypeIdentifier->NameSpace.MajorVersion == NULL ||
RsrcTypeIdentifier->NameSpace.MinorVersion == NULL ||
RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL
) {
if ((RsrcTypeIdentifier == NULL) ||
(RsrcTypeIdentifier->NameSpace.ResourceTypeName == NULL) ||
(RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) ||
(RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) ||
(RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
@ -240,22 +257,28 @@ InterpreterEfiStructToInstance (
//
Status = EFI_UNSUPPORTED;
ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
if (AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.ResourceTypeName,
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
) == 0)
{
//
// Check version.
//
if ((AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.MajorVersion,
ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MajorVersion
) == 0) &&
(AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.MinorVersion,
ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MinorVersion
) == 0) &&
(AsciiStrCmp (
RsrcTypeIdentifier->NameSpace.ErrataVersion,
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
) == 0))
{
Status = InterpreterInstance->StructureToJson (
This,
RestJSonHeader,
@ -264,8 +287,10 @@ InterpreterEfiStructToInstance (
break;
}
}
ThisSupportedRsrcTypeId ++;
ThisSupportedRsrcTypeId++;
}
return Status;
}
@ -291,10 +316,11 @@ InterpreterInstanceDestoryJsonStruct (
EFI_STATUS Status;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
if (This == NULL ||
InterpreterInstance == NULL ||
RestJSonHeader == NULL
) {
if ((This == NULL) ||
(InterpreterInstance == NULL) ||
(RestJSonHeader == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
@ -303,14 +329,17 @@ InterpreterInstanceDestoryJsonStruct (
// Check if the namesapce and version is supported by this interpreter.
//
ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
if (AsciiStrCmp (
RestJSonHeader->JsonRsrcIdentifier.NameSpace.ResourceTypeName,
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0) {
ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
) == 0)
{
if ((RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion == NULL) &&
(RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion == NULL) &&
(RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion == NULL)
) {
)
{
//
// Don't check version of this resource type identifier.
//
@ -325,13 +354,17 @@ InterpreterInstanceDestoryJsonStruct (
//
if ((AsciiStrCmp (
RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion,
ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MajorVersion
) == 0) &&
(AsciiStrCmp (
RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion,
ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
ThisSupportedRsrcTypeId->NameSpace.MinorVersion
) == 0) &&
(AsciiStrCmp (
RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion,
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
) == 0))
{
Status = InterpreterInstance->DestroyStructure (
This,
RestJSonHeader
@ -340,8 +373,10 @@ InterpreterInstanceDestoryJsonStruct (
}
}
}
ThisSupportedRsrcTypeId ++;
ThisSupportedRsrcTypeId++;
}
return Status;
}
@ -364,21 +399,23 @@ RestJsonStructureToStruct (
IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,
IN CHAR8 *ResourceJsonText,
OUT EFI_REST_JSON_STRUCTURE_HEADER **JsonStructure
)
)
{
EFI_STATUS Status;
REST_JSON_STRUCTURE_INSTANCE *Instance;
if (This == NULL ||
ResourceJsonText == NULL ||
JsonStructure == NULL
) {
if ((This == NULL) ||
(ResourceJsonText == NULL) ||
(JsonStructure == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
if (IsListEmpty (&mRestJsonStructureList)) {
return EFI_UNSUPPORTED;
}
Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
@ -392,12 +429,15 @@ RestJsonStructureToStruct (
if (!EFI_ERROR (Status)) {
break;
}
if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
Status = EFI_UNSUPPORTED;
break;
}
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
};
}
return Status;
}
@ -417,18 +457,19 @@ EFIAPI
RestJsonStructureDestroyStruct (
IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader
)
)
{
EFI_STATUS Status;
REST_JSON_STRUCTURE_INSTANCE *Instance;
if (This == NULL || RestJSonHeader == NULL) {
if ((This == NULL) || (RestJSonHeader == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (IsListEmpty (&mRestJsonStructureList)) {
return EFI_UNSUPPORTED;
}
Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
@ -440,12 +481,15 @@ RestJsonStructureDestroyStruct (
if (!EFI_ERROR (Status)) {
break;
}
if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
Status = EFI_UNSUPPORTED;
break;
}
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
};
}
return Status;
}
@ -466,18 +510,19 @@ RestJsonStructureToJson (
IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,
OUT CHAR8 **ResourceRaw
)
)
{
EFI_STATUS Status;
REST_JSON_STRUCTURE_INSTANCE *Instance;
if (This == NULL || RestJSonHeader == NULL || ResourceRaw == NULL) {
if ((This == NULL) || (RestJSonHeader == NULL) || (ResourceRaw == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (IsListEmpty (&mRestJsonStructureList)) {
return EFI_UNSUPPORTED;
}
Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
@ -490,12 +535,15 @@ RestJsonStructureToJson (
if (!EFI_ERROR (Status)) {
break;
}
if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
Status = EFI_UNSUPPORTED;
break;
}
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
};
}
return Status;
}
@ -569,15 +617,17 @@ RestJsonStructureUnload (
if (IsListEmpty (&mRestJsonStructureList)) {
return Status;
}
//
// Free memory of REST_JSON_STRUCTURE_INSTANCE instance.
//
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
do {
NextInstance = NULL;
if (!IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
if (!IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
NextInstance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
}
FreePool ((VOID *)Instance);
Instance = NextInstance;
} while (Instance != NULL);