diff options
Diffstat (limited to 'RedfishPkg')
56 files changed, 5937 insertions, 4486 deletions
diff --git a/RedfishPkg/Include/IndustryStandard/RedfishHostInterface.h b/RedfishPkg/Include/IndustryStandard/RedfishHostInterface.h index 3eec7a0b0e..49b3ceee39 100644 --- a/RedfishPkg/Include/IndustryStandard/RedfishHostInterface.h +++ b/RedfishPkg/Include/IndustryStandard/RedfishHostInterface.h @@ -12,72 +12,72 @@ #include <IndustryStandard/SmBios.h>
-#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB 0x02 // We don't support this type of interface.
+#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB 0x02 // We don't support this type of interface.
// Use REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 instead.
-#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE 0x03 // We don't support this type of interface.
+#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE 0x03 // We don't support this type of interface.
// Use REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2 instead.
-#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 0x04
-#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2 0x05
+#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 0x04
+#define REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2 0x05
-#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_UNKNOWN 0x00
-#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_STATIC 0x01
-#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_DHCP 0x02
-#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_AUTO_CONFIGURE 0x03
-#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_HOST_SELECTED 0x04
+#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_UNKNOWN 0x00
+#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_STATIC 0x01
+#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_DHCP 0x02
+#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_AUTO_CONFIGURE 0x03
+#define REDFISH_HOST_INTERFACE_HOST_IP_ASSIGNMENT_TYPE_HOST_SELECTED 0x04
-#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN 0x00
-#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4 0x01
-#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6 0x02
+#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN 0x00
+#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4 0x01
+#define REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6 0x02
#pragma pack(1)
///
/// Structure definitions of Host Interface device type 04h (USB Network Interface V2)
///
typedef struct {
- UINT8 Length; ///< Length of the structure, including Device Type
+ UINT8 Length; ///< Length of the structure, including Device Type
///< and Length fields.
- UINT16 IdVendor; ///< The Vendor ID of the device, as read from the
+ UINT16 IdVendor; ///< The Vendor ID of the device, as read from the
///< idVendor field of the USB descriptor.
- UINT16 IdProduct; ///< The Product ID of the device, as read from the
+ UINT16 IdProduct; ///< The Product ID of the device, as read from the
///< idProduct field of the USB descriptor.
- UINT8 SecialNumberStr; ///< The string number for the Serial Number of the
+ UINT8 SecialNumberStr; ///< The string number for the Serial Number of the
///< device. The string data is read from the
///< 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;
//
// Structure definitions of Host Interface device type 05h (PCI/PCIE V2)
//
typedef struct {
- UINT8 Length; ///< Length of the structure, including Device Type and Length fields.
- UINT16 VendorId; ///< The Vendor ID of the PCI/PCIe device.
- 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.
- 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.
+ UINT8 Length; ///< Length of the structure, including Device Type and Length fields.
+ UINT16 VendorId; ///< The Vendor ID of the PCI/PCIe device.
+ 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.
+ 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.
} PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2;
///
/// Structure definitions of Host Interface device type 80-FFh (OEM)
///
typedef struct {
- UINT32 VendorIana; ///< The IANA code for the vendor (MSB first).
- UINT8 OemDefinedData[1]; ///< OEM defined data.
+ UINT32 VendorIana; ///< The IANA code for the vendor (MSB first).
+ UINT8 OemDefinedData[1]; ///< OEM defined data.
} OEM_DEVICE_DESCRIPTOR;
///
/// Define union for the Host Interface Device Descriptor
///
typedef union {
- USB_INTERFACE_DEVICE_DESCRIPTOR_V2 UsbDeviceV2; ///< Device type USB V2 device discriptor.
- PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2 PciPcieDeviceV2; ///< Device type PCI/PCIe V2 device discriptor.
- OEM_DEVICE_DESCRIPTOR OemDevice; ///< OEM type device discriptor.
+ USB_INTERFACE_DEVICE_DESCRIPTOR_V2 UsbDeviceV2; ///< Device type USB V2 device discriptor.
+ PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2 PciPcieDeviceV2; ///< Device type PCI/PCIe V2 device discriptor.
+ OEM_DEVICE_DESCRIPTOR OemDevice; ///< OEM type device discriptor.
} DEVICE_DESCRITOR; /// Device descriptor data formated based on Device Type.
///
@@ -87,15 +87,15 @@ typedef union { /// specific Tape 42 table.
///
typedef struct {
- UINT8 DeviceType; ///< The Device Type of the interface.
- DEVICE_DESCRITOR DeviceDescriptor; ///< The Device descriptor.
+ UINT8 DeviceType; ///< The Device Type of the interface.
+ DEVICE_DESCRITOR DeviceDescriptor; ///< The Device descriptor.
} REDFISH_INTERFACE_DATA;
//
// 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,
@@ -105,7 +105,7 @@ typedef struct { // HostSelected=04h,
// other values reserved
//
- UINT8 HostIpAssignmentType;
+ UINT8 HostIpAssignmentType;
//
// Unknown=00h,
@@ -113,19 +113,19 @@ typedef struct { // Ipv6=02h,
// other values reserved
//
- UINT8 HostIpAddressFormat;
+ UINT8 HostIpAddressFormat;
//
// Used for Static and AutoConfigure.
// For IPV4, use the first 4 Bytes and zero fill the remaining bytes.
//
- UINT8 HostIpAddress[16];
+ UINT8 HostIpAddress[16];
//
// Used for Static and AutoConfigure.
// For IPV4, use the first 4 Bytes and zero fill the remaining bytes.
//
- UINT8 HostIpMask[16];
+ UINT8 HostIpMask[16];
//
// Unknown=00h,
@@ -135,7 +135,7 @@ typedef struct { // HostSelected=04h,
// other values reserved
//
- UINT8 RedfishServiceIpDiscoveryType;
+ UINT8 RedfishServiceIpDiscoveryType;
//
// Unknown=00h,
@@ -143,27 +143,26 @@ typedef struct { // Ipv6=02h,
// other values reserved
//
- UINT8 RedfishServiceIpAddressFormat;
+ UINT8 RedfishServiceIpAddressFormat;
//
// Used for Static and AutoConfigure.
// For IPV4, use the first 4 Bytes and zero fill the remaining bytes.
//
- UINT8 RedfishServiceIpAddress[16];
+ UINT8 RedfishServiceIpAddress[16];
//
// Used for Static and AutoConfigure.
// For IPV4, use the first 4 Bytes and zero fill the remaining bytes.
//
- UINT8 RedfishServiceIpMask[16];
+ UINT8 RedfishServiceIpMask[16];
- UINT16 RedfishServiceIpPort; // Used for Static and AutoConfigure.
- UINT32 RedfishServiceVlanId; // Used for Static and AutoConfigure.
- UINT8 RedfishServiceHostnameLength; // length of the following hostname string
- UINT8 RedfishServiceHostname[1]; // hostname of Redfish Service
+ UINT16 RedfishServiceIpPort; // Used for Static and AutoConfigure.
+ UINT32 RedfishServiceVlanId; // Used for Static and AutoConfigure.
+ UINT8 RedfishServiceHostnameLength; // length of the following hostname string
+ UINT8 RedfishServiceHostname[1]; // hostname of Redfish Service
} REDFISH_OVER_IP_PROTOCOL_DATA;
#pragma pack()
#endif
-
diff --git a/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h b/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h index c6989617df..5017043827 100644 --- a/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h +++ b/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h @@ -14,11 +14,11 @@ ///
/// L"\u0000"
///
-#define UNICODE_FORMAT_LEN 6
-#define UNICODE_FORMAT_CHAR_LEN 2
-#define UNICODE_FORMAT_CHAR_SIZE 3
+#define UNICODE_FORMAT_LEN 6
+#define UNICODE_FORMAT_CHAR_LEN 2
+#define UNICODE_FORMAT_CHAR_SIZE 3
-#define UTF8_BUFFER_FOR_UCS2_MAX_SIZE 3
+#define UTF8_BUFFER_FOR_UCS2_MAX_SIZE 3
/**
Convert a UCS2 string to a UTF8 encoded string.
@@ -34,8 +34,8 @@ **/
EFI_STATUS
UCS2StrToUTF8 (
- IN CHAR16 *Ucs2Str,
- OUT CHAR8 **Utf8StrAddr
+ IN CHAR16 *Ucs2Str,
+ OUT CHAR8 **Utf8StrAddr
);
/**
@@ -54,8 +54,8 @@ UCS2StrToUTF8 ( **/
EFI_STATUS
UTF8StrToUCS2 (
- IN CHAR8 *Utf8Str,
- OUT CHAR16 **Ucs2StrAddr
+ IN CHAR8 *Utf8Str,
+ OUT CHAR16 **Ucs2StrAddr
);
#endif
diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h index 83959dd52a..f98f4e779e 100644 --- a/RedfishPkg/Include/Library/JsonLib.h +++ b/RedfishPkg/Include/Library/JsonLib.h @@ -7,17 +7,18 @@ 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
///
-typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1
+typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1
// in jansson_Config.h
///
@@ -25,28 +26,28 @@ typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1 /// See below URI for the JSON encoding flags reference.
/// https://jansson.readthedocs.io/en/2.13/apiref.html#encoding
///
-#define EDKII_JSON_MAX_INDENT 0x1F
-#define EDKII_JSON_INDENT(n) ((n) & EDKII_JSON_MAX_INDENT)
-
-#define EDKII_JSON_COMPACT 0x20
-#define EDKII_JSON_ENSURE_ASCII 0x40
-#define EDKII_JSON_SORT_KEYS 0x80
-#define EDKII_JSON_PRESERVE_ORDER 0x100
-#define EDKII_JSON_ENCODE_ANY 0x200
-#define EDKII_JSON_ESCAPE_SLASH 0x400
-#define EDKII_JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
-#define EDKII_JSON_EMBED 0x10000
+#define EDKII_JSON_MAX_INDENT 0x1F
+#define EDKII_JSON_INDENT(n) ((n) & EDKII_JSON_MAX_INDENT)
+
+#define EDKII_JSON_COMPACT 0x20
+#define EDKII_JSON_ENSURE_ASCII 0x40
+#define EDKII_JSON_SORT_KEYS 0x80
+#define EDKII_JSON_PRESERVE_ORDER 0x100
+#define EDKII_JSON_ENCODE_ANY 0x200
+#define EDKII_JSON_ESCAPE_SLASH 0x400
+#define EDKII_JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
+#define EDKII_JSON_EMBED 0x10000
///
/// Map to the definitions in jansson.h
/// See below URI for the JSON decoding flags reference.
/// https://jansson.readthedocs.io/en/2.13/apiref.html?highlight=json_loadb#decoding
///
-#define EDKII_JSON_REJECT_DUPLICATES 0x1
-#define EDKII_JSON_DISABLE_EOF_CHECK 0x2
-#define EDKII_JSON_DECODE_ANY 0x4
-#define EDKII_JSON_DECODE_INT_AS_REAL 0x8
-#define EDKII_JSON_ALLOW_NUL 0x10
+#define EDKII_JSON_REJECT_DUPLICATES 0x1
+#define EDKII_JSON_DISABLE_EOF_CHECK 0x2
+#define EDKII_JSON_DECODE_ANY 0x4
+#define EDKII_JSON_DECODE_INT_AS_REAL 0x8
+#define EDKII_JSON_ALLOW_NUL 0x10
#define EDKII_JSON_ARRAY_FOREACH(Array, Index, Value) \
for(Index = 0; \
@@ -63,28 +64,28 @@ typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1 ///
/// Map to the json_error_t in jansson.h
///
-#define EDKII_JSON_ERROR_TEXT_LENGTH 160
-#define EDKII_JSON_ERROR_SOURCE_LENGTH 80
+#define EDKII_JSON_ERROR_TEXT_LENGTH 160
+#define EDKII_JSON_ERROR_SOURCE_LENGTH 80
typedef struct {
- INTN Line;
- INTN Column;
- INTN Position;
- CHAR8 Source [EDKII_JSON_ERROR_SOURCE_LENGTH];
- CHAR8 Text [EDKII_JSON_ERROR_TEXT_LENGTH];
+ INTN Line;
+ INTN Column;
+ INTN Position;
+ CHAR8 Source[EDKII_JSON_ERROR_SOURCE_LENGTH];
+ CHAR8 Text[EDKII_JSON_ERROR_TEXT_LENGTH];
} EDKII_JSON_ERROR;
///
/// Map to the json_type in jansson.h
///
typedef enum {
- EdkiiJsonTypeObject,
- EdkiiJsonTypeArray,
- EdkiiJsonTypeString,
- EdkiiJsonTypeInteger,
- EdkiiJsonTypeReal,
- EdkiiJsonTypeTrue,
- EdkiiJsonTypeFalse,
- EdkiiJsonTypeNull
+ EdkiiJsonTypeObject,
+ EdkiiJsonTypeArray,
+ EdkiiJsonTypeString,
+ EdkiiJsonTypeInteger,
+ EdkiiJsonTypeReal,
+ EdkiiJsonTypeTrue,
+ EdkiiJsonTypeFalse,
+ EdkiiJsonTypeNull
} EDKII_JSON_TYPE;
/**
@@ -147,7 +148,7 @@ JsonValueInitObject ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitAsciiString (
- IN CONST CHAR8 *String
+ IN CONST CHAR8 *String
);
/**
@@ -170,7 +171,7 @@ JsonValueInitAsciiString ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitUnicodeString (
- IN CHAR16 *String
+ IN CHAR16 *String
);
/**
@@ -190,7 +191,7 @@ JsonValueInitUnicodeString ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitInteger (
- IN INT64 Value
+ IN INT64 Value
);
/**
@@ -207,7 +208,7 @@ JsonValueInitInteger ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitBoolean (
- IN BOOLEAN Value
+ IN BOOLEAN Value
);
/**
@@ -278,7 +279,7 @@ JsonValueInitFalse ( VOID
EFIAPI
JsonValueFree (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -301,7 +302,7 @@ JsonValueFree ( EDKII_JSON_VALUE
EFIAPI
JsonValueClone (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -316,7 +317,7 @@ JsonValueClone ( BOOLEAN
EFIAPI
JsonValueIsArray (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -331,7 +332,7 @@ JsonValueIsArray ( BOOLEAN
EFIAPI
JsonValueIsObject (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -347,7 +348,7 @@ JsonValueIsObject ( BOOLEAN
EFIAPI
JsonValueIsString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -362,7 +363,7 @@ JsonValueIsString ( BOOLEAN
EFIAPI
JsonValueIsInteger (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -377,7 +378,7 @@ JsonValueIsInteger ( BOOLEAN
EFIAPI
JsonValueIsNumber (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -392,7 +393,7 @@ JsonValueIsNumber ( BOOLEAN
EFIAPI
JsonValueIsBoolean (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -407,7 +408,7 @@ JsonValueIsBoolean ( BOOLEAN
EFIAPI
JsonValueIsTrue (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -422,7 +423,7 @@ JsonValueIsTrue ( BOOLEAN
EFIAPI
JsonValueIsFalse (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -437,7 +438,7 @@ JsonValueIsFalse ( BOOLEAN
EFIAPI
JsonValueIsNull (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -453,7 +454,7 @@ JsonValueIsNull ( EDKII_JSON_ARRAY
EFIAPI
JsonValueGetArray (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -469,7 +470,7 @@ JsonValueGetArray ( EDKII_JSON_OBJECT
EFIAPI
JsonValueGetObject (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -485,7 +486,7 @@ JsonValueGetObject ( CONST CHAR8 *
EFIAPI
JsonValueGetAsciiString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -499,10 +500,10 @@ JsonValueGetAsciiString ( @retval Return the associated Unicode string in JSON value or NULL.
**/
-CHAR16*
+CHAR16 *
EFIAPI
JsonValueGetUnicodeString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -519,7 +520,7 @@ JsonValueGetUnicodeString ( INT64
EFIAPI
JsonValueGetInteger (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -536,7 +537,7 @@ JsonValueGetInteger ( BOOLEAN
EFIAPI
JsonValueGetBoolean (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -549,10 +550,10 @@ 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
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -567,7 +568,7 @@ JsonValueGetString ( UINTN
EFIAPI
JsonObjectSize (
- IN EDKII_JSON_OBJECT JsonObject
+ IN EDKII_JSON_OBJECT JsonObject
);
/**
@@ -583,10 +584,10 @@ 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
+ IN EDKII_JSON_OBJECT JsonObj,
+ OUT UINTN *KeyCount
);
/**
@@ -608,8 +609,8 @@ JsonObjectGetKeys ( EDKII_JSON_VALUE
EFIAPI
JsonObjectGetValue (
- IN CONST EDKII_JSON_OBJECT JsonObj,
- IN CONST CHAR8 *Key
+ IN CONST EDKII_JSON_OBJECT JsonObj,
+ IN CONST CHAR8 *Key
);
/**
@@ -633,9 +634,9 @@ JsonObjectGetValue ( EFI_STATUS
EFIAPI
JsonObjectSetValue (
- IN EDKII_JSON_OBJECT JsonObj,
- IN CONST CHAR8 *Key,
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_OBJECT JsonObj,
+ IN CONST CHAR8 *Key,
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -650,7 +651,7 @@ JsonObjectSetValue ( UINTN
EFIAPI
JsonArrayCount (
- IN EDKII_JSON_ARRAY JsonArray
+ IN EDKII_JSON_ARRAY JsonArray
);
/**
@@ -672,8 +673,8 @@ JsonArrayCount ( EDKII_JSON_VALUE
EFIAPI
JsonArrayGetValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN UINTN Index
+ IN EDKII_JSON_ARRAY JsonArray,
+ IN UINTN Index
);
/**
@@ -692,8 +693,8 @@ JsonArrayGetValue ( EFI_STATUS
EFIAPI
JsonArrayAppendValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_ARRAY JsonArray,
+ IN EDKII_JSON_VALUE Json
);
/**
@@ -713,8 +714,8 @@ JsonArrayAppendValue ( EFI_STATUS
EFIAPI
JsonArrayRemoveValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN UINTN Index
+ IN EDKII_JSON_ARRAY JsonArray,
+ IN UINTN Index
);
/**
@@ -742,8 +743,8 @@ JsonArrayRemoveValue ( CHAR8 *
EFIAPI
JsonDumpString (
- IN EDKII_JSON_VALUE JsonValue,
- IN UINTN Flags
+ IN EDKII_JSON_VALUE JsonValue,
+ IN UINTN Flags
);
/**
@@ -766,9 +767,9 @@ JsonDumpString ( EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
- IN CONST CHAR8* String,
- IN UINT64 Flags,
- IN EDKII_JSON_ERROR *Error
+ IN CONST CHAR8 *String,
+ IN UINT64 Flags,
+ IN EDKII_JSON_ERROR *Error
);
/**
@@ -793,7 +794,7 @@ JsonLoadString ( EDKII_JSON_VALUE
EFIAPI
JsonLoadBuffer (
- IN CONST CHAR8 *Buffer,
+ IN CONST CHAR8 *Buffer,
IN UINTN BufferLen,
IN UINTN Flags,
IN OUT EDKII_JSON_ERROR *Error
@@ -815,7 +816,7 @@ JsonLoadBuffer ( VOID
EFIAPI
JsonDecreaseReference (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
);
/**
@@ -833,8 +834,9 @@ JsonDecreaseReference ( EDKII_JSON_VALUE
EFIAPI
JsonIncreaseReference (
- IN EDKII_JSON_VALUE JsonValue
+ 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
@@ -844,7 +846,7 @@ JsonIncreaseReference ( VOID *
EFIAPI
JsonObjectIterator (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
);
/**
@@ -855,7 +857,7 @@ JsonObjectIterator ( EDKII_JSON_VALUE
EFIAPI
JsonObjectIteratorValue (
- IN VOID *Iterator
+ IN VOID *Iterator
);
/**
@@ -869,8 +871,8 @@ JsonObjectIteratorValue ( VOID *
EFIAPI
JsonObjectIteratorNext (
- IN EDKII_JSON_VALUE JsonValue,
- IN VOID *Iterator
+ IN EDKII_JSON_VALUE JsonValue,
+ IN VOID *Iterator
);
/**
@@ -882,8 +884,8 @@ JsonObjectIteratorNext ( CHAR8 *
EFIAPI
JsonObjectIteratorKey (
- IN VOID *Iterator
-);
+ IN VOID *Iterator
+ );
/**
Returns the pointer of iterator by key.
@@ -894,8 +896,8 @@ JsonObjectIteratorKey ( VOID *
EFIAPI
JsonObjectKeyToIterator (
- IN CHAR8 *Key
-);
+ IN CHAR8 *Key
+ );
/**
Returns the json type of this json value
@@ -905,7 +907,8 @@ JsonObjectKeyToIterator ( **/
EDKII_JSON_TYPE
EFIAPI
-JsonGetType(
- IN EDKII_JSON_VALUE JsonValue
+JsonGetType (
+ IN EDKII_JSON_VALUE JsonValue
);
+
#endif
diff --git a/RedfishPkg/Include/Library/RedfishContentCodingLib.h b/RedfishPkg/Include/Library/RedfishContentCodingLib.h index 71a8adcb26..137c39aa7d 100644 --- a/RedfishPkg/Include/Library/RedfishContentCodingLib.h +++ b/RedfishPkg/Include/Library/RedfishContentCodingLib.h @@ -6,6 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CONTENT_CODING_LIB_H_
#define REDFISH_CONTENT_CODING_LIB_H_
@@ -36,11 +37,11 @@ EFI_STATUS
RedfishContentEncode (
- IN CHAR8 *ContentEncodedValue,
- IN CHAR8 *OriginalContent,
- IN UINTN OriginalContentLength,
- OUT VOID **EncodedContentPointer,
- OUT UINTN *EncodedLength
+ IN CHAR8 *ContentEncodedValue,
+ IN CHAR8 *OriginalContent,
+ IN UINTN OriginalContentLength,
+ OUT VOID **EncodedContentPointer,
+ OUT UINTN *EncodedLength
);
/**
@@ -69,10 +70,11 @@ RedfishContentEncode ( **/
EFI_STATUS
RedfishContentDecode (
- IN CHAR8 *ContentEncodedValue,
- IN VOID *ContentPointer,
- IN UINTN ContentLength,
- OUT VOID **DecodedContentPointer,
- OUT UINTN *DecodedLength
+ IN CHAR8 *ContentEncodedValue,
+ IN VOID *ContentPointer,
+ IN UINTN ContentLength,
+ OUT VOID **DecodedContentPointer,
+ OUT UINTN *DecodedLength
);
+
#endif
diff --git a/RedfishPkg/Include/Library/RedfishCredentialLib.h b/RedfishPkg/Include/Library/RedfishCredentialLib.h index dac1b3303f..fafe786513 100644 --- a/RedfishPkg/Include/Library/RedfishCredentialLib.h +++ b/RedfishPkg/Include/Library/RedfishCredentialLib.h @@ -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.
@@ -85,7 +86,8 @@ LibCredentialGetAuthInfo ( EFI_STATUS
EFIAPI
LibStopRedfishService (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
-);
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
+ );
+
#endif
diff --git a/RedfishPkg/Include/Library/RedfishCrtLib.h b/RedfishPkg/Include/Library/RedfishCrtLib.h index 5e15768938..23c6acfca3 100644 --- a/RedfishPkg/Include/Library/RedfishCrtLib.h +++ b/RedfishPkg/Include/Library/RedfishCrtLib.h @@ -19,74 +19,76 @@ #define MAX_STRING_SIZE 0x10000000
// Minimum value for an object of type long long int.
-#define LLONG_MIN MIN_INT64
+#define LLONG_MIN MIN_INT64
// Maximum value for an object of type long long int.
-#define LLONG_MAX MAX_INT64
+#define LLONG_MAX MAX_INT64
// We dont support double on edk2
-#define HUGE_VAL 0
+#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
#define va_end VA_END
#else // __CC_ARM
-#define va_start(Marker, Parameter) __va_start(Marker, Parameter)
-#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
-#define va_end(Marker) ((void)0)
+#define va_start(Marker, Parameter) __va_start(Marker, Parameter)
+#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
+#define va_end(Marker) ((void)0)
#endif
//
// Definitions for global constants used by CRT library routines
//
-#define INT_MAX MAX_INT32 /* Maximum (signed) int value */
-#define LONG_MAX 0X7FFFFFFFL /* max value for a long */
-#define LONG_MIN (-LONG_MAX-1) /* min value for a long */
-#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
-#define CHAR_BIT 8 /* Number of bits in a char */
+#define INT_MAX MAX_INT32 /* Maximum (signed) int value */
+#define LONG_MAX 0X7FFFFFFFL /* max value for a long */
+#define LONG_MIN (-LONG_MAX-1) /* min value for a long */
+#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
+#define CHAR_BIT 8 /* Number of bits in a char */
// Maximum value for an object of type unsigned long long int.
#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL // 2^64 - 1
// Maximum value for an object of type unsigned char.
-#define UCHAR_MAX 255 // 2^8 - 1
+#define UCHAR_MAX 255 // 2^8 - 1
//
// Basic types mapping
//
-typedef UINTN size_t;
-typedef INTN ssize_t;
-typedef INT32 time_t;
-typedef UINT8 __uint8_t;
-typedef UINT8 sa_family_t;
-typedef UINT32 uid_t;
-typedef UINT32 gid_t;
-typedef INT32 int32_t;
-typedef UINT32 uint32_t;
-typedef UINT16 uint16_t;
-typedef UINT8 uint8_t;
-typedef enum {false, true} bool;
+typedef UINTN size_t;
+typedef INTN ssize_t;
+typedef INT32 time_t;
+typedef UINT8 __uint8_t;
+typedef UINT8 sa_family_t;
+typedef UINT32 uid_t;
+typedef UINT32 gid_t;
+typedef INT32 int32_t;
+typedef UINT32 uint32_t;
+typedef UINT16 uint16_t;
+typedef UINT8 uint8_t;
+typedef enum {
+ false, true
+} bool;
//
// File operations are not required for EFI building,
// so FILE is mapped to VOID * to pass build
//
-typedef VOID *FILE;
+typedef VOID *FILE;
/**
This is the Redfish version of CRT snprintf function, this function replaces "%s" to
@@ -133,110 +135,406 @@ RedfishAsciiSPrint ( UINTN
EFIAPI
RedfishAsciiVSPrint (
- OUT CHAR8 *StartOfBuffer,
- IN UINTN BufferSize,
- IN CONST CHAR8 *FormatString,
- IN VA_LIST Marker
+ OUT CHAR8 *StartOfBuffer,
+ IN UINTN BufferSize,
+ IN CONST CHAR8 *FormatString,
+ IN VA_LIST Marker
);
//
// Global variables
//
-extern int errno;
-extern FILE *stderr;
+extern int errno;
+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 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 assert(expression) ASSERT(expression)
-#define offsetof(type,member) OFFSET_OF(type,member)
-
-#define EOF (-1)
+#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 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 assert(expression) ASSERT(expression)
+#define offsetof(type, member) OFFSET_OF(type,member)
+
+#define EOF (-1)
extern int errno;
-#define ERANGE 34 /* 34 Result too large */
+#define ERANGE 34 /* 34 Result too large */
#endif
diff --git a/RedfishPkg/Include/Library/RedfishHostInterfaceLib.h b/RedfishPkg/Include/Library/RedfishHostInterfaceLib.h index ad134e8f9b..8d8389b964 100644 --- a/RedfishPkg/Include/Library/RedfishHostInterfaceLib.h +++ b/RedfishPkg/Include/Library/RedfishHostInterfaceLib.h @@ -6,6 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_HOST_INTERFACE_LIB_H_
#define REDFISH_HOST_INTERFACE_LIB_H_
@@ -27,9 +28,10 @@ **/
EFI_STATUS
RedfishPlatformHostInterfaceDeviceDescriptor (
- IN UINT8 *DeviceType,
+ 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.
@@ -46,7 +48,8 @@ RedfishPlatformHostInterfaceDeviceDescriptor ( **/
EFI_STATUS
RedfishPlatformHostInterfaceProtocolData (
- IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
- IN UINT8 IndexOfProtocolData
-);
+ IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
+ IN UINT8 IndexOfProtocolData
+ );
+
#endif
diff --git a/RedfishPkg/Include/Library/RestExLib.h b/RedfishPkg/Include/Library/RestExLib.h index 80233fb21c..bc4e4ca6ca 100644 --- a/RedfishPkg/Include/Library/RestExLib.h +++ b/RedfishPkg/Include/Library/RestExLib.h @@ -32,11 +32,11 @@ **/
EFI_STATUS
RestExLibCreateChild (
- IN EFI_HANDLE Image,
+ IN EFI_HANDLE Image,
IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode,
- IN EFI_REST_EX_CONFIG_TYPE ConfigType,
- IN EFI_REST_EX_SERVICE_TYPE ServiceType,
- OUT EFI_HANDLE *ChildInstanceHandle
-);
+ IN EFI_REST_EX_CONFIG_TYPE ConfigType,
+ IN EFI_REST_EX_SERVICE_TYPE ServiceType,
+ OUT EFI_HANDLE *ChildInstanceHandle
+ );
#endif
diff --git a/RedfishPkg/Include/Pcd/RestExServiceDevicePath.h b/RedfishPkg/Include/Pcd/RestExServiceDevicePath.h index 89de3b1a21..91b1198297 100644 --- a/RedfishPkg/Include/Pcd/RestExServiceDevicePath.h +++ b/RedfishPkg/Include/Pcd/RestExServiceDevicePath.h @@ -21,8 +21,8 @@ typedef enum { } DEVICE_PATH_MATCH_MODE;
typedef struct {
- UINT32 DevicePathMatchMode;
- UINT32 DevicePathNum;
+ UINT32 DevicePathMatchMode;
+ UINT32 DevicePathNum;
//
// Example:
// {DEVICE_PATH("PciRoot(0)/Pci(0,0)/MAC(005056C00002,0x1)")}
@@ -32,7 +32,7 @@ typedef struct { // 0x03,0x0b,0x25,0x00,0x00,0x50,0x56,0xc0,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
// 0x7f,0xff,0x04,0x00}
//
- EFI_DEVICE_PATH_PROTOCOL DevicePath[];
+ EFI_DEVICE_PATH_PROTOCOL DevicePath[];
} REST_EX_SERVICE_DEVICE_PATH_DATA;
#endif
diff --git a/RedfishPkg/Include/Protocol/EdkIIRedfishConfigHandler.h b/RedfishPkg/Include/Protocol/EdkIIRedfishConfigHandler.h index bbd60ed6bd..6604322865 100644 --- a/RedfishPkg/Include/Protocol/EdkIIRedfishConfigHandler.h +++ b/RedfishPkg/Include/Protocol/EdkIIRedfishConfigHandler.h @@ -19,15 +19,15 @@ typedef struct _EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL EDKII_REDFISH_CONFIG_HANDL }
typedef struct {
- EFI_HANDLE RedfishServiceRestExHandle; ///< REST EX EFI handle associated with this Redfish service.
- UINTN RedfishServiceVersion; ///< Redfish service version.
- CHAR16 *RedfishServiceLocation; ///< Redfish service location.
- CHAR16 *RedfishServiceUuid; ///< Redfish service UUID.
- CHAR16 *RedfishServiceOs; ///< Redfish service OS.
- CHAR16 *RedfishServiceOsVersion; ///< Redfish service OS version.
- CHAR16 *RedfishServiceProduct; ///< Redfish service product name.
- CHAR16 *RedfishServiceProductVer; ///< Redfish service product version.
- BOOLEAN RedfishServiceUseHttps; ///< Redfish service uses HTTPS.
+ EFI_HANDLE RedfishServiceRestExHandle; ///< REST EX EFI handle associated with this Redfish service.
+ UINTN RedfishServiceVersion; ///< Redfish service version.
+ CHAR16 *RedfishServiceLocation; ///< Redfish service location.
+ CHAR16 *RedfishServiceUuid; ///< Redfish service UUID.
+ CHAR16 *RedfishServiceOs; ///< Redfish service OS.
+ CHAR16 *RedfishServiceOsVersion; ///< Redfish service OS version.
+ CHAR16 *RedfishServiceProduct; ///< Redfish service product name.
+ CHAR16 *RedfishServiceProductVer; ///< Redfish service product version.
+ BOOLEAN RedfishServiceUseHttps; ///< Redfish service uses HTTPS.
} REDFISH_CONFIG_SERVICE_INFORMATION;
/**
@@ -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,16 +63,15 @@ 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
);
struct _EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL {
- EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_INIT Init;
- EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_STOP Stop;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_INIT Init;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL_STOP Stop;
};
-
-extern EFI_GUID gdkIIRedfishConfigHandlerProtocolGuid;
+extern EFI_GUID gdkIIRedfishConfigHandlerProtocolGuid;
#endif
diff --git a/RedfishPkg/Include/Protocol/EdkIIRedfishCredential.h b/RedfishPkg/Include/Protocol/EdkIIRedfishCredential.h index 34e33b1e00..6aaf9fcde9 100644 --- a/RedfishPkg/Include/Protocol/EdkIIRedfishCredential.h +++ b/RedfishPkg/Include/Protocol/EdkIIRedfishCredential.h @@ -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,16 +85,16 @@ 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
);
struct _EDKII_REDFISH_CREDENTIAL_PROTOCOL {
- EDKII_REDFISH_CREDENTIAL_PROTOCOL_GET_AUTH_INFO GetAuthInfo;
- EDKII_REDFISH_CREDENTIAL_PROTOCOL_STOP_SERVICE StopService;
+ EDKII_REDFISH_CREDENTIAL_PROTOCOL_GET_AUTH_INFO GetAuthInfo;
+ EDKII_REDFISH_CREDENTIAL_PROTOCOL_STOP_SERVICE StopService;
};
-extern EFI_GUID gEdkIIRedfishCredentialProtocolGuid;
+extern EFI_GUID gEdkIIRedfishCredentialProtocolGuid;
#endif
diff --git a/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c b/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c index 891423734b..42839f5139 100644 --- a/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c +++ b/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c @@ -26,17 +26,16 @@ **/
UINT8
GetUTF8SizeForUCS2 (
- IN CHAR8 *Utf8Buffer
+ IN CHAR8 *Utf8Buffer
)
{
- CHAR8 TempChar;
- UINT8 Utf8Size;
+ CHAR8 TempChar;
+ UINT8 Utf8Size;
ASSERT (Utf8Buffer != NULL);
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++;
}
}
}
@@ -74,16 +71,16 @@ GetUTF8SizeForUCS2 ( **/
EFI_STATUS
GetUCS2CharByFormat (
- IN CHAR8 *Utf8Buffer,
- OUT CHAR16 *Ucs2Char
+ IN CHAR8 *Utf8Buffer,
+ OUT CHAR16 *Ucs2Char
)
{
- UINT8 Num1;
- UINT8 Num2;
- UINT8 Index;
- CHAR8 Ucs2CharFormat[UNICODE_FORMAT_CHAR_SIZE]; /// two Hexadecimal digits Ascii string, like "3F"
+ UINT8 Num1;
+ UINT8 Num2;
+ 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;
}
@@ -123,33 +120,30 @@ GetUCS2CharByFormat ( **/
UINT8
UCS2CharToUTF8 (
- IN CHAR16 Ucs2Char,
- OUT CHAR8 *Utf8Buffer
+ IN CHAR16 Ucs2Char,
+ OUT CHAR8 *Utf8Buffer
)
{
- UINT16 Ucs2Number;
+ UINT16 Ucs2Number;
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
@@ -174,23 +168,22 @@ UCS2CharToUTF8 ( **/
EFI_STATUS
UTF8ToUCS2Char (
- IN CHAR8 *Utf8Buffer,
- OUT CHAR16 *Ucs2Char
+ IN CHAR8 *Utf8Buffer,
+ OUT CHAR16 *Ucs2Char
)
{
- UINT8 Utf8Size;
- CHAR8 *Ucs2Buffer;
- CHAR8 TempChar1;
- CHAR8 TempChar2;
- CHAR8 TempChar3;
+ UINT8 Utf8Size;
+ CHAR8 *Ucs2Buffer;
+ CHAR8 TempChar1;
+ CHAR8 TempChar2;
+ CHAR8 TempChar3;
ASSERT (Utf8Buffer != NULL && Ucs2Char != NULL);
ZeroMem (Ucs2Char, sizeof (CHAR16));
- Ucs2Buffer = (CHAR8 *) Ucs2Char;
+ Ucs2Buffer = (CHAR8 *)Ucs2Char;
Utf8Size = GetUTF8SizeForUCS2 (Utf8Buffer);
switch (Utf8Size) {
-
case 1:
//
@@ -271,27 +264,26 @@ UTF8ToUCS2Char ( **/
EFI_STATUS
UCS2StrToUTF8 (
- IN CHAR16 *Ucs2Str,
- OUT CHAR8 **Utf8StrAddr
+ IN CHAR16 *Ucs2Str,
+ OUT CHAR8 **Utf8StrAddr
)
{
- UINTN Ucs2StrIndex;
- UINTN Ucs2StrLength;
- CHAR8 *Utf8Str;
- UINTN Utf8StrLength;
- UINTN Utf8StrIndex;
- CHAR8 Utf8Buffer[UTF8_BUFFER_FOR_UCS2_MAX_SIZE];
- UINT8 Utf8BufferSize;
-
- if (Ucs2Str == NULL || Utf8StrAddr == NULL) {
+ UINTN Ucs2StrIndex;
+ UINTN Ucs2StrLength;
+ CHAR8 *Utf8Str;
+ UINTN Utf8StrLength;
+ UINTN Utf8StrIndex;
+ CHAR8 Utf8Buffer[UTF8_BUFFER_FOR_UCS2_MAX_SIZE];
+ UINT8 Utf8BufferSize;
+
+ 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);
@@ -313,7 +304,7 @@ UCS2StrToUTF8 ( }
Utf8Str[Utf8StrIndex] = '\0';
- *Utf8StrAddr = Utf8Str;
+ *Utf8StrAddr = Utf8Str;
return EFI_SUCCESS;
}
@@ -334,18 +325,18 @@ UCS2StrToUTF8 ( **/
EFI_STATUS
UTF8StrToUCS2 (
- IN CHAR8 *Utf8Str,
- OUT CHAR16 **Ucs2StrAddr
+ IN CHAR8 *Utf8Str,
+ OUT CHAR16 **Ucs2StrAddr
)
{
- EFI_STATUS Status;
- UINTN Utf8StrIndex;
- UINTN Utf8StrLength;
- UINTN Ucs2StrIndex;
- UINT8 Utf8BufferSize;
- CHAR16 *Ucs2StrTemp;
-
- if (Utf8Str == NULL || Ucs2StrAddr == NULL) {
+ EFI_STATUS Status;
+ UINTN Utf8StrIndex;
+ UINTN Utf8StrLength;
+ UINTN Ucs2StrIndex;
+ UINT8 Utf8BufferSize;
+ CHAR16 *Ucs2StrTemp;
+
+ 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;
}
-
diff --git a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c index 05c70c213f..d9acad24de 100644 --- a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c +++ b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c @@ -15,7 +15,7 @@ #include <Protocol/Http.h>
#include <Protocol/RestEx.h>
-#define REST_EX_CONFIG_DATA_LEN_UNKNOWN 0xff
+#define REST_EX_CONFIG_DATA_LEN_UNKNOWN 0xff
/**
This function allows the caller to create child handle for specific
@@ -33,27 +33,28 @@ **/
EFI_STATUS
RestExLibCreateChild (
- IN EFI_HANDLE Image,
+ IN EFI_HANDLE Image,
IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode,
- IN EFI_REST_EX_CONFIG_TYPE ConfigType,
- IN EFI_REST_EX_SERVICE_TYPE ServiceType,
- OUT EFI_HANDLE *ChildInstanceHandle
-)
+ IN EFI_REST_EX_CONFIG_TYPE ConfigType,
+ IN EFI_REST_EX_SERVICE_TYPE ServiceType,
+ OUT EFI_HANDLE *ChildInstanceHandle
+ )
{
- EFI_STATUS Status;
- UINTN NoBuffer;
- EFI_HANDLE *Handle;
- EFI_HANDLE ChildHandle;
- EFI_REST_EX_PROTOCOL *RestEx;
- EFI_REST_EX_SERVICE_INFO *RestExServiceInfo;
- UINT8 LenOfConfig;
-
- if (Image == NULL ||
- AccessMode >= EfiRestExServiceModeMax ||
- ConfigType >= EfiRestExConfigTypeMax ||
- ServiceType >= EfiRestExServiceTypeMax ||
- ChildInstanceHandle == NULL
- ) {
+ EFI_STATUS Status;
+ UINTN NoBuffer;
+ EFI_HANDLE *Handle;
+ EFI_HANDLE ChildHandle;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ EFI_REST_EX_SERVICE_INFO *RestExServiceInfo;
+ UINT8 LenOfConfig;
+
+ if ((Image == NULL) ||
+ (AccessMode >= EfiRestExServiceModeMax) ||
+ (ConfigType >= EfiRestExConfigTypeMax) ||
+ (ServiceType >= EfiRestExServiceTypeMax) ||
+ (ChildInstanceHandle == NULL)
+ )
+ {
return EFI_INVALID_PARAMETER;
}
@@ -61,29 +62,31 @@ RestExLibCreateChild ( //
// Locate all REST EX binding service.
//
- Handle = NULL;
+ Handle = NULL;
NoBuffer = 0;
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiRestExServiceBindingProtocolGuid,
- NULL,
- &NoBuffer,
- &Handle
- );
- if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiRestExServiceBindingProtocolGuid,
+ NULL,
+ &NoBuffer,
+ &Handle
+ );
+ 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,
- NULL,
- &NoBuffer,
- &Handle
- );
+ ByProtocol,
+ &gEfiRestExServiceBindingProtocolGuid,
+ NULL,
+ &NoBuffer,
+ &Handle
+ );
if (EFI_ERROR (Status)) {
FreePool (Handle);
return Status;
@@ -94,21 +97,21 @@ RestExLibCreateChild ( //
while (NoBuffer != 0) {
ChildHandle = NULL;
- Status = NetLibCreateServiceChild (
- *(Handle + (NoBuffer - 1)),
- Image,
- &gEfiRestExServiceBindingProtocolGuid,
- &ChildHandle
- );
+ Status = NetLibCreateServiceChild (
+ *(Handle + (NoBuffer - 1)),
+ Image,
+ &gEfiRestExServiceBindingProtocolGuid,
+ &ChildHandle
+ );
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
- ChildHandle,
- &gEfiRestExProtocolGuid,
- (VOID **)&RestEx,
- Image,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ ChildHandle,
+ &gEfiRestExProtocolGuid,
+ (VOID **)&RestEx,
+ Image,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
@@ -117,12 +120,13 @@ RestExLibCreateChild ( // Get the information of REST service provided by this EFI REST EX driver
//
Status = RestEx->GetService (
- RestEx,
- &RestExServiceInfo
- );
+ RestEx,
+ &RestExServiceInfo
+ );
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;
}
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c index 33d5eaef79..75bd8f9853 100644 --- a/RedfishPkg/Library/JsonLib/JsonLib.c +++ b/RedfishPkg/Library/JsonLib/JsonLib.c @@ -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 ();
}
/**
@@ -83,10 +83,10 @@ JsonValueInitObject ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitAsciiString (
- IN CONST CHAR8 *String
+ IN CONST CHAR8 *String
)
{
- UINTN Index;
+ UINTN Index;
if (String == NULL) {
return NULL;
@@ -124,11 +124,11 @@ JsonValueInitAsciiString ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitUnicodeString (
- IN CHAR16 *String
+ IN CHAR16 *String
)
{
- EFI_STATUS Status;
- CHAR8 *Utf8Str;
+ EFI_STATUS Status;
+ CHAR8 *Utf8Str;
if (String == NULL) {
return NULL;
@@ -160,7 +160,7 @@ JsonValueInitUnicodeString ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitInteger (
- IN INT64 Value
+ IN INT64 Value
)
{
return (EDKII_JSON_VALUE)json_integer (Value);
@@ -180,7 +180,7 @@ JsonValueInitInteger ( EDKII_JSON_VALUE
EFIAPI
JsonValueInitBoolean (
- IN BOOLEAN Value
+ IN BOOLEAN Value
)
{
return (EDKII_JSON_VALUE)json_boolean (Value);
@@ -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 ();
}
/**
@@ -263,10 +263,10 @@ JsonValueInitNull ( VOID
EFIAPI
JsonValueFree (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- json_decref((json_t *)Json);
+ json_decref ((json_t *)Json);
}
/**
@@ -289,10 +289,10 @@ JsonValueFree ( EDKII_JSON_VALUE
EFIAPI
JsonValueClone (
- IN EDKII_JSON_VALUE Json
+ 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);
}
/**
@@ -307,10 +307,10 @@ JsonValueClone ( BOOLEAN
EFIAPI
JsonValueIsArray (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_array ((json_t *) Json);
+ return json_is_array ((json_t *)Json);
}
/**
@@ -325,10 +325,10 @@ JsonValueIsArray ( BOOLEAN
EFIAPI
JsonValueIsObject (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_object ((json_t *) Json);
+ return json_is_object ((json_t *)Json);
}
/**
@@ -344,10 +344,10 @@ JsonValueIsObject ( BOOLEAN
EFIAPI
JsonValueIsString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_string ((json_t *) Json);
+ return json_is_string ((json_t *)Json);
}
/**
@@ -362,10 +362,10 @@ JsonValueIsString ( BOOLEAN
EFIAPI
JsonValueIsInteger (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_integer ((json_t *) Json);
+ return json_is_integer ((json_t *)Json);
}
/**
@@ -380,10 +380,10 @@ JsonValueIsInteger ( BOOLEAN
EFIAPI
JsonValueIsNumber (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_number ((json_t *) Json);
+ return json_is_number ((json_t *)Json);
}
/**
@@ -398,10 +398,10 @@ JsonValueIsNumber ( BOOLEAN
EFIAPI
JsonValueIsBoolean (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_boolean ((json_t *) Json);
+ return json_is_boolean ((json_t *)Json);
}
/**
@@ -416,12 +416,13 @@ JsonValueIsBoolean ( BOOLEAN
EFIAPI
JsonValueIsTrue (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
if (json_is_true ((json_t *)Json)) {
return TRUE;
}
+
return FALSE;
}
@@ -437,14 +438,16 @@ JsonValueIsTrue ( BOOLEAN
EFIAPI
JsonValueIsFalse (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
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.
@@ -457,10 +460,10 @@ JsonValueIsFalse ( BOOLEAN
EFIAPI
JsonValueIsNull (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- return json_is_null ((json_t *) Json);
+ return json_is_null ((json_t *)Json);
}
/**
@@ -476,10 +479,10 @@ JsonValueIsNull ( EDKII_JSON_ARRAY
EFIAPI
JsonValueGetArray (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- if (Json == NULL || !JsonValueIsArray (Json)) {
+ if ((Json == NULL) || !JsonValueIsArray (Json)) {
return NULL;
}
@@ -499,10 +502,10 @@ JsonValueGetArray ( EDKII_JSON_OBJECT
EFIAPI
JsonValueGetObject (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- if (Json == NULL || !JsonValueIsObject (Json)) {
+ if ((Json == NULL) || !JsonValueIsObject (Json)) {
return NULL;
}
@@ -522,13 +525,13 @@ JsonValueGetObject ( CONST CHAR8 *
EFIAPI
JsonValueGetAsciiString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- CONST CHAR8 *AsciiStr;
- UINTN Index;
+ 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,22 +559,22 @@ JsonValueGetAsciiString ( @retval Return the associated Unicode string in JSON value or NULL.
**/
-CHAR16*
+CHAR16 *
EFIAPI
JsonValueGetUnicodeString (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
- EFI_STATUS Status;
- CONST CHAR8 *Utf8Str;
- CHAR16 *Ucs2Str;
+ EFI_STATUS Status;
+ 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;
}
@@ -593,15 +596,15 @@ JsonValueGetUnicodeString ( INT64
EFIAPI
JsonValueGetInteger (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
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);
}
/**
@@ -618,15 +621,15 @@ JsonValueGetInteger ( BOOLEAN
EFIAPI
JsonValueGetBoolean (
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_VALUE Json
)
{
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,10 +642,10 @@ 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
+ IN EDKII_JSON_VALUE Json
)
{
return json_string_value ((const json_t *)Json);
@@ -660,10 +663,10 @@ JsonValueGetString ( UINTN
EFIAPI
JsonObjectSize (
- IN EDKII_JSON_OBJECT JsonObject
+ 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
+ IN EDKII_JSON_OBJECT JsonObj,
+ OUT UINTN *KeyCount
)
{
+ UINTN Index;
+ CONST CHAR8 **KeyArray;
+ CONST CHAR8 *Key;
+ EDKII_JSON_VALUE Value;
- 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++;
}
@@ -740,8 +742,8 @@ JsonObjectGetKeys ( EDKII_JSON_VALUE
EFIAPI
JsonObjectGetValue (
- IN CONST EDKII_JSON_OBJECT JsonObj,
- IN CONST CHAR8 *Key
+ IN CONST EDKII_JSON_OBJECT JsonObj,
+ IN CONST CHAR8 *Key
)
{
return (EDKII_JSON_VALUE)json_object_get ((const json_t *)JsonObj, (const char *)Key);
@@ -768,12 +770,12 @@ JsonObjectGetValue ( EFI_STATUS
EFIAPI
JsonObjectSetValue (
- IN EDKII_JSON_OBJECT JsonObj,
- IN CONST CHAR8 *Key,
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_OBJECT JsonObj,
+ IN CONST CHAR8 *Key,
+ 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;
@@ -792,10 +794,10 @@ JsonObjectSetValue ( UINTN
EFIAPI
JsonArrayCount (
- IN EDKII_JSON_ARRAY JsonArray
+ IN EDKII_JSON_ARRAY JsonArray
)
{
- return json_array_size ((json_t *) JsonArray);
+ return json_array_size ((json_t *)JsonArray);
}
/**
@@ -817,11 +819,11 @@ JsonArrayCount ( EDKII_JSON_VALUE
EFIAPI
JsonArrayGetValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN UINTN Index
+ IN EDKII_JSON_ARRAY JsonArray,
+ 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);
}
/**
@@ -840,11 +842,11 @@ JsonArrayGetValue ( EFI_STATUS
EFIAPI
JsonArrayAppendValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN EDKII_JSON_VALUE Json
+ IN EDKII_JSON_ARRAY JsonArray,
+ 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;
@@ -868,11 +870,11 @@ JsonArrayAppendValue ( EFI_STATUS
EFIAPI
JsonArrayRemoveValue (
- IN EDKII_JSON_ARRAY JsonArray,
- IN UINTN Index
+ IN EDKII_JSON_ARRAY JsonArray,
+ 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;
@@ -904,14 +906,15 @@ JsonArrayRemoveValue ( CHAR8 *
EFIAPI
JsonDumpString (
- IN EDKII_JSON_VALUE JsonValue,
- IN UINTN Flags
+ IN EDKII_JSON_VALUE JsonValue,
+ IN UINTN Flags
)
{
- if (JsonValue == NULL) {
- return NULL;
- }
- return json_dumps((json_t *)JsonValue, Flags);
+ if (JsonValue == NULL) {
+ return NULL;
+ }
+
+ return json_dumps ((json_t *)JsonValue, Flags);
}
/**
@@ -934,12 +937,12 @@ JsonDumpString ( EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
- IN CONST CHAR8* String,
- IN UINT64 Flags,
- IN EDKII_JSON_ERROR *Error
+ 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);
}
/**
@@ -964,13 +967,13 @@ JsonLoadString ( EDKII_JSON_VALUE
EFIAPI
JsonLoadBuffer (
- IN CONST CHAR8 *Buffer,
+ IN CONST CHAR8 *Buffer,
IN UINTN BufferLen,
IN UINTN Flags,
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);
}
/**
@@ -989,7 +992,7 @@ JsonLoadBuffer ( VOID
EFIAPI
JsonDecreaseReference (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
)
{
json_decref (JsonValue);
@@ -1010,7 +1013,7 @@ JsonDecreaseReference ( EDKII_JSON_VALUE
EFIAPI
JsonIncreaseReference (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
)
{
return json_incref (JsonValue);
@@ -1026,7 +1029,7 @@ JsonIncreaseReference ( VOID *
EFIAPI
JsonObjectIterator (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
)
{
return json_object_iter (JsonValue);
@@ -1041,10 +1044,10 @@ JsonObjectIterator ( EDKII_JSON_VALUE
EFIAPI
JsonObjectIteratorValue (
- IN VOID *Iterator
+ IN VOID *Iterator
)
{
- return json_object_iter_value(Iterator);
+ return json_object_iter_value (Iterator);
}
/**
@@ -1058,11 +1061,11 @@ JsonObjectIteratorValue ( VOID *
EFIAPI
JsonObjectIteratorNext (
- IN EDKII_JSON_VALUE JsonValue,
- IN VOID *Iterator
+ IN EDKII_JSON_VALUE JsonValue,
+ IN VOID *Iterator
)
{
- return json_object_iter_next(JsonValue, Iterator);
+ return json_object_iter_next (JsonValue, Iterator);
}
/**
@@ -1074,10 +1077,10 @@ JsonObjectIteratorNext ( CHAR8 *
EFIAPI
JsonObjectIteratorKey (
- IN VOID *Iterator
-)
+ IN VOID *Iterator
+ )
{
- return (CHAR8 *)json_object_iter_key(Iterator);
+ return (CHAR8 *)json_object_iter_key (Iterator);
}
/**
@@ -1089,10 +1092,10 @@ JsonObjectIteratorKey ( VOID *
EFIAPI
JsonObjectKeyToIterator (
- IN CHAR8 *Key
-)
+ IN CHAR8 *Key
+ )
{
- return json_object_key_to_iter(Key);
+ return json_object_key_to_iter (Key);
}
/**
@@ -1104,7 +1107,7 @@ JsonObjectKeyToIterator ( EDKII_JSON_TYPE
EFIAPI
JsonGetType (
- IN EDKII_JSON_VALUE JsonValue
+ IN EDKII_JSON_VALUE JsonValue
)
{
return ((json_t *)JsonValue)->type;
diff --git a/RedfishPkg/Library/JsonLib/jansson_config.h b/RedfishPkg/Library/JsonLib/jansson_config.h index c66d3ced9b..2cde2cf0e0 100644 --- a/RedfishPkg/Library/JsonLib/jansson_config.h +++ b/RedfishPkg/Library/JsonLib/jansson_config.h @@ -16,26 +16,26 @@ ///
/// We support long long on edk2
///
-#define JSON_INTEGER_IS_LONG_LONG 1
+#define JSON_INTEGER_IS_LONG_LONG 1
///
/// We don't support locale on edk2
///
-#define JSON_HAVE_LOCALECONV 0
+#define JSON_HAVE_LOCALECONV 0
///
/// We don't support atomic builtins on edk2
///
-#define JSON_HAVE_ATOMIC_BUILTINS 0
+#define JSON_HAVE_ATOMIC_BUILTINS 0
///
/// We don't support sync builtins on edk2
///
-#define JSON_HAVE_SYNC_BUILTINS 0
+#define JSON_HAVE_SYNC_BUILTINS 0
///
/// Mzximum deepth is set to 2048
///
-#define JSON_PARSER_MAX_DEPTH 2048
+#define JSON_PARSER_MAX_DEPTH 2048
#endif
diff --git a/RedfishPkg/Library/JsonLib/jansson_private_config.h b/RedfishPkg/Library/JsonLib/jansson_private_config.h index 268f91ef8a..03a80571ab 100644 --- a/RedfishPkg/Library/JsonLib/jansson_private_config.h +++ b/RedfishPkg/Library/JsonLib/jansson_private_config.h @@ -11,9 +11,9 @@ #ifndef JANSSON_PRIVATE_CONFIG_H_
#define JANSSON_PRIVATE_CONFIG_H_
-#define HAVE_SYS_TIME_H 1
-#define HAVE_SYS_TYPES_H 1
+#define HAVE_SYS_TIME_H 1
+#define HAVE_SYS_TYPES_H 1
-#define INITIAL_HASHTABLE_ORDER 3
+#define INITIAL_HASHTABLE_ORDER 3
#endif
diff --git a/RedfishPkg/Library/JsonLib/load.c b/RedfishPkg/Library/JsonLib/load.c index 37e0ba4271..958c3ea8c5 100644 --- a/RedfishPkg/Library/JsonLib/load.c +++ b/RedfishPkg/Library/JsonLib/load.c @@ -22,1090 +22,1402 @@ #include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+ #include <unistd.h>
#endif
#include "jansson.h"
#include "strbuffer.h"
#include "utf.h"
-#define STREAM_STATE_OK 0
-#define STREAM_STATE_EOF -1
-#define STREAM_STATE_ERROR -2
+#define STREAM_STATE_OK 0
+#define STREAM_STATE_EOF -1
+#define STREAM_STATE_ERROR -2
-#define TOKEN_INVALID -1
-#define TOKEN_EOF 0
-#define TOKEN_STRING 256
-#define TOKEN_INTEGER 257
-#define TOKEN_REAL 258
-#define TOKEN_TRUE 259
-#define TOKEN_FALSE 260
-#define TOKEN_NULL 261
+#define TOKEN_INVALID -1
+#define TOKEN_EOF 0
+#define TOKEN_STRING 256
+#define TOKEN_INTEGER 257
+#define TOKEN_REAL 258
+#define TOKEN_TRUE 259
+#define TOKEN_FALSE 260
+#define TOKEN_NULL 261
/* Locale independent versions of isxxx() functions */
-#define l_isupper(c) ('A' <= (c) && (c) <= 'Z')
-#define l_islower(c) ('a' <= (c) && (c) <= 'z')
-#define l_isalpha(c) (l_isupper(c) || l_islower(c))
-#define l_isdigit(c) ('0' <= (c) && (c) <= '9')
+#define l_isupper(c) ('A' <= (c) && (c) <= 'Z')
+#define l_islower(c) ('a' <= (c) && (c) <= 'z')
+#define l_isalpha(c) (l_isupper(c) || l_islower(c))
+#define l_isdigit(c) ('0' <= (c) && (c) <= '9')
#define l_isxdigit(c) \
(l_isdigit(c) || ('A' <= (c) && (c) <= 'F') || ('a' <= (c) && (c) <= 'f'))
/* Read one byte from stream, convert to unsigned char, then int, and
return. return EOF on end of file. This corresponds to the
behaviour of fgetc(). */
-typedef int (*get_func)(void *data);
+typedef int (*get_func)(
+ void *data
+ );
typedef struct {
- get_func get;
- void *data;
- char buffer[5];
- size_t buffer_pos;
- int state;
- int line;
- int column, last_column;
- size_t position;
+ get_func get;
+ void *data;
+ char buffer[5];
+ size_t buffer_pos;
+ int state;
+ int line;
+ int column, last_column;
+ size_t position;
} stream_t;
typedef struct {
- stream_t stream;
- strbuffer_t saved_text;
- size_t flags;
- size_t depth;
- int token;
- union {
- struct {
- char *val;
- size_t len;
- } string;
- json_int_t integer;
- double real;
- } value;
+ stream_t stream;
+ strbuffer_t saved_text;
+ size_t flags;
+ size_t depth;
+ int token;
+ union {
+ struct {
+ char *val;
+ size_t len;
+ } string;
+ json_int_t integer;
+ double real;
+ } value;
} lex_t;
-#define stream_to_lex(stream) container_of(stream, lex_t, stream)
+#define stream_to_lex(stream) container_of(stream, lex_t, stream)
/*** error reporting ***/
-static void error_set(json_error_t *error, const lex_t *lex, enum json_error_code code,
- const char *msg, ...) {
- va_list ap;
- char msg_text[JSON_ERROR_TEXT_LENGTH];
- char msg_with_context[JSON_ERROR_TEXT_LENGTH];
-
- int line = -1, col = -1;
- size_t pos = 0;
- const char *result = msg_text;
-
- if (!error)
- return;
-
- va_start(ap, msg);
- vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap);
- msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
- va_end(ap);
-
- if (lex) {
- const char *saved_text = strbuffer_value(&lex->saved_text);
-
- line = lex->stream.line;
- col = lex->stream.column;
- pos = lex->stream.position;
-
- if (saved_text && saved_text[0]) {
- if (lex->saved_text.length <= 20) {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'",
- msg_text, saved_text);
- msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
- result = msg_with_context;
- }
- } else {
- if (code == json_error_invalid_syntax) {
- /* More specific error code for premature end of file. */
- code = json_error_premature_end_of_input;
- }
- if (lex->stream.state == STREAM_STATE_ERROR) {
- /* No context for UTF-8 decoding errors */
- result = msg_text;
- } else {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file",
- msg_text);
- msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
- result = msg_with_context;
- }
- }
+static void
+error_set (
+ json_error_t *error,
+ const lex_t *lex,
+ enum json_error_code code,
+ const char *msg,
+ ...
+ )
+{
+ va_list ap;
+ char msg_text[JSON_ERROR_TEXT_LENGTH];
+ char msg_with_context[JSON_ERROR_TEXT_LENGTH];
+
+ int line = -1, col = -1;
+ size_t pos = 0;
+ const char *result = msg_text;
+
+ if (!error) {
+ return;
+ }
+
+ va_start (ap, msg);
+ vsnprintf (msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap);
+ msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
+ va_end (ap);
+
+ if (lex) {
+ const char *saved_text = strbuffer_value (&lex->saved_text);
+
+ line = lex->stream.line;
+ col = lex->stream.column;
+ pos = lex->stream.position;
+
+ if (saved_text && saved_text[0]) {
+ if (lex->saved_text.length <= 20) {
+ snprintf (
+ msg_with_context,
+ JSON_ERROR_TEXT_LENGTH,
+ "%s near '%s'",
+ msg_text,
+ saved_text
+ );
+ msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
+ result = msg_with_context;
+ }
+ } else {
+ if (code == json_error_invalid_syntax) {
+ /* More specific error code for premature end of file. */
+ code = json_error_premature_end_of_input;
+ }
+
+ if (lex->stream.state == STREAM_STATE_ERROR) {
+ /* No context for UTF-8 decoding errors */
+ result = msg_text;
+ } else {
+ snprintf (
+ msg_with_context,
+ JSON_ERROR_TEXT_LENGTH,
+ "%s near end of file",
+ msg_text
+ );
+ msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
+ result = msg_with_context;
+ }
}
+ }
- jsonp_error_set(error, line, col, pos, code, "%s", result);
+ jsonp_error_set (error, line, col, pos, code, "%s", result);
}
/*** lexical analyzer ***/
-static void stream_init(stream_t *stream, get_func get, void *data) {
- stream->get = get;
- stream->data = data;
- stream->buffer[0] = '\0';
- stream->buffer_pos = 0;
-
- stream->state = STREAM_STATE_OK;
- stream->line = 1;
- stream->column = 0;
- stream->position = 0;
+static void
+stream_init (
+ stream_t *stream,
+ get_func get,
+ void *data
+ )
+{
+ stream->get = get;
+ stream->data = data;
+ stream->buffer[0] = '\0';
+ stream->buffer_pos = 0;
+
+ stream->state = STREAM_STATE_OK;
+ stream->line = 1;
+ stream->column = 0;
+ stream->position = 0;
}
-static int stream_get(stream_t *stream, json_error_t *error) {
- int c;
-
- if (stream->state != STREAM_STATE_OK)
- return stream->state;
-
- if (!stream->buffer[stream->buffer_pos]) {
- c = stream->get(stream->data);
- if (c == EOF) {
- stream->state = STREAM_STATE_EOF;
- return STREAM_STATE_EOF;
- }
+static int
+stream_get (
+ stream_t *stream,
+ json_error_t *error
+ )
+{
+ int c;
+
+ if (stream->state != STREAM_STATE_OK) {
+ return stream->state;
+ }
+
+ if (!stream->buffer[stream->buffer_pos]) {
+ c = stream->get (stream->data);
+ if (c == EOF) {
+ stream->state = STREAM_STATE_EOF;
+ return STREAM_STATE_EOF;
+ }
- stream->buffer[0] = c;
- stream->buffer_pos = 0;
+ stream->buffer[0] = c;
+ stream->buffer_pos = 0;
- if (0x80 <= c && c <= 0xFF) {
- /* multi-byte UTF-8 sequence */
- size_t i, count;
+ if ((0x80 <= c) && (c <= 0xFF)) {
+ /* multi-byte UTF-8 sequence */
+ size_t i, count;
- count = utf8_check_first(c);
- if (!count)
- goto out;
+ count = utf8_check_first (c);
+ if (!count) {
+ goto out;
+ }
- assert(count >= 2);
+ assert (count >= 2);
- for (i = 1; i < count; i++)
- stream->buffer[i] = stream->get(stream->data);
+ for (i = 1; i < count; i++) {
+ stream->buffer[i] = stream->get (stream->data);
+ }
- if (!utf8_check_full(stream->buffer, count, NULL))
- goto out;
+ if (!utf8_check_full (stream->buffer, count, NULL)) {
+ goto out;
+ }
- stream->buffer[count] = '\0';
- } else
- stream->buffer[1] = '\0';
+ stream->buffer[count] = '\0';
+ } else {
+ stream->buffer[1] = '\0';
}
+ }
- c = stream->buffer[stream->buffer_pos++];
-
- stream->position++;
- if (c == '\n') {
- stream->line++;
- stream->last_column = stream->column;
- stream->column = 0;
- } else if (utf8_check_first(c)) {
- /* track the Unicode character column, so increment only if
- this is the first character of a UTF-8 sequence */
- stream->column++;
- }
+ c = stream->buffer[stream->buffer_pos++];
- return c;
+ stream->position++;
+ if (c == '\n') {
+ stream->line++;
+ stream->last_column = stream->column;
+ stream->column = 0;
+ } else if (utf8_check_first (c)) {
+ /* track the Unicode character column, so increment only if
+ this is the first character of a UTF-8 sequence */
+ stream->column++;
+ }
+
+ return c;
out:
- stream->state = STREAM_STATE_ERROR;
- error_set(error, stream_to_lex(stream), json_error_invalid_utf8,
- "unable to decode byte 0x%x", c);
- return STREAM_STATE_ERROR;
+ stream->state = STREAM_STATE_ERROR;
+ error_set (
+ error,
+ stream_to_lex (stream),
+ json_error_invalid_utf8,
+ "unable to decode byte 0x%x",
+ c
+ );
+ return STREAM_STATE_ERROR;
}
-static void stream_unget(stream_t *stream, int c) {
- if (c == STREAM_STATE_EOF || c == STREAM_STATE_ERROR)
- return;
-
- stream->position--;
- if (c == '\n') {
- stream->line--;
- stream->column = stream->last_column;
- } else if (utf8_check_first(c))
- stream->column--;
+static void
+stream_unget (
+ stream_t *stream,
+ int c
+ )
+{
+ if ((c == STREAM_STATE_EOF) || (c == STREAM_STATE_ERROR)) {
+ return;
+ }
+
+ stream->position--;
+ if (c == '\n') {
+ stream->line--;
+ stream->column = stream->last_column;
+ } else if (utf8_check_first (c)) {
+ stream->column--;
+ }
+
+ assert (stream->buffer_pos > 0);
+ stream->buffer_pos--;
+ assert (stream->buffer[stream->buffer_pos] == c);
+}
- assert(stream->buffer_pos > 0);
- stream->buffer_pos--;
- assert(stream->buffer[stream->buffer_pos] == c);
+static int
+lex_get (
+ lex_t *lex,
+ json_error_t *error
+ )
+{
+ return stream_get (&lex->stream, error);
}
-static int lex_get(lex_t *lex, json_error_t *error) {
- return stream_get(&lex->stream, error);
+static void
+lex_save (
+ lex_t *lex,
+ int c
+ )
+{
+ strbuffer_append_byte (&lex->saved_text, c);
}
-static void lex_save(lex_t *lex, int c) { strbuffer_append_byte(&lex->saved_text, c); }
+static int
+lex_get_save (
+ lex_t *lex,
+ json_error_t *error
+ )
+{
+ int c = stream_get (&lex->stream, error);
-static int lex_get_save(lex_t *lex, json_error_t *error) {
- int c = stream_get(&lex->stream, error);
- if (c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR)
- lex_save(lex, c);
- return c;
+ if ((c != STREAM_STATE_EOF) && (c != STREAM_STATE_ERROR)) {
+ lex_save (lex, c);
+ }
+
+ return c;
}
-static void lex_unget(lex_t *lex, int c) { stream_unget(&lex->stream, c); }
+static void
+lex_unget (
+ lex_t *lex,
+ int c
+ )
+{
+ stream_unget (&lex->stream, c);
+}
-static void lex_unget_unsave(lex_t *lex, int c) {
- if (c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) {
-/* Since we treat warnings as errors, when assertions are turned
- * off the "d" variable would be set but never used. Which is
- * treated as an error by GCC.
- */
-#ifndef NDEBUG
- char d;
-#endif
- stream_unget(&lex->stream, c);
-#ifndef NDEBUG
- d =
-#endif
- strbuffer_pop(&lex->saved_text);
- assert(c == d);
- }
+static void
+lex_unget_unsave (
+ lex_t *lex,
+ int c
+ )
+{
+ if ((c != STREAM_STATE_EOF) && (c != STREAM_STATE_ERROR)) {
+ /* Since we treat warnings as errors, when assertions are turned
+ * off the "d" variable would be set but never used. Which is
+ * treated as an error by GCC.
+ */
+ #ifndef NDEBUG
+ char d;
+ #endif
+ stream_unget (&lex->stream, c);
+ #ifndef NDEBUG
+ d =
+ #endif
+ strbuffer_pop (&lex->saved_text);
+ assert (c == d);
+ }
}
-static void lex_save_cached(lex_t *lex) {
- while (lex->stream.buffer[lex->stream.buffer_pos] != '\0') {
- lex_save(lex, lex->stream.buffer[lex->stream.buffer_pos]);
- lex->stream.buffer_pos++;
- lex->stream.position++;
- }
+static void
+lex_save_cached (
+ lex_t *lex
+ )
+{
+ while (lex->stream.buffer[lex->stream.buffer_pos] != '\0') {
+ lex_save (lex, lex->stream.buffer[lex->stream.buffer_pos]);
+ lex->stream.buffer_pos++;
+ lex->stream.position++;
+ }
}
-static void lex_free_string(lex_t *lex) {
- jsonp_free(lex->value.string.val);
- lex->value.string.val = NULL;
- lex->value.string.len = 0;
+static void
+lex_free_string (
+ lex_t *lex
+ )
+{
+ jsonp_free (lex->value.string.val);
+ lex->value.string.val = NULL;
+ lex->value.string.len = 0;
}
/* assumes that str points to 'u' plus at least 4 valid hex digits */
-static int32_t decode_unicode_escape(const char *str) {
- int i;
- int32_t value = 0;
-
- assert(str[0] == 'u');
-
- for (i = 1; i <= 4; i++) {
- char c = str[i];
- value <<= 4;
- if (l_isdigit(c))
- value += c - '0';
- else if (l_islower(c))
- value += c - 'a' + 10;
- else if (l_isupper(c))
- value += c - 'A' + 10;
- else
- return -1;
+static int32_t
+decode_unicode_escape (
+ const char *str
+ )
+{
+ int i;
+ int32_t value = 0;
+
+ assert (str[0] == 'u');
+
+ for (i = 1; i <= 4; i++) {
+ char c = str[i];
+ value <<= 4;
+ if (l_isdigit (c)) {
+ value += c - '0';
+ } else if (l_islower (c)) {
+ value += c - 'a' + 10;
+ } else if (l_isupper (c)) {
+ value += c - 'A' + 10;
+ } else {
+ return -1;
}
+ }
- return value;
+ return value;
}
-static void lex_scan_string(lex_t *lex, json_error_t *error) {
- int c;
- const char *p;
- char *t;
- int i;
+static void
+lex_scan_string (
+ lex_t *lex,
+ json_error_t *error
+ )
+{
+ int c;
+ const char *p;
+ char *t;
+ int i;
- lex->value.string.val = NULL;
- lex->token = TOKEN_INVALID;
+ lex->value.string.val = NULL;
+ lex->token = TOKEN_INVALID;
- c = lex_get_save(lex, error);
+ c = lex_get_save (lex, error);
- while (c != '"') {
- if (c == STREAM_STATE_ERROR)
+ while (c != '"') {
+ if (c == STREAM_STATE_ERROR) {
+ goto out;
+ } else if (c == STREAM_STATE_EOF) {
+ error_set (
+ error,
+ lex,
+ json_error_premature_end_of_input,
+ "premature end of input"
+ );
+ goto out;
+ } else if ((0 <= c) && (c <= 0x1F)) {
+ /* control character */
+ lex_unget_unsave (lex, c);
+ if (c == '\n') {
+ error_set (error, lex, json_error_invalid_syntax, "unexpected newline");
+ } else {
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "control character 0x%x",
+ c
+ );
+ }
+
+ goto out;
+ } else if (c == '\\') {
+ c = lex_get_save (lex, error);
+ if (c == 'u') {
+ c = lex_get_save (lex, error);
+ for (i = 0; i < 4; i++) {
+ if (!l_isxdigit (c)) {
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid escape"
+ );
goto out;
+ }
- else if (c == STREAM_STATE_EOF) {
- error_set(error, lex, json_error_premature_end_of_input,
- "premature end of input");
- goto out;
+ c = lex_get_save (lex, error);
}
-
- else if (0 <= c && c <= 0x1F) {
- /* control character */
- lex_unget_unsave(lex, c);
- if (c == '\n')
- error_set(error, lex, json_error_invalid_syntax, "unexpected newline");
- else
- error_set(error, lex, json_error_invalid_syntax, "control character 0x%x",
- c);
- goto out;
+ } else if ((c == '"') || (c == '\\') || (c == '/') || (c == 'b') || (c == 'f') ||
+ (c == 'n') || (c == 'r') || (c == 't'))
+ {
+ c = lex_get_save (lex, error);
+ } else {
+ error_set (error, lex, json_error_invalid_syntax, "invalid escape");
+ goto out;
+ }
+ } else {
+ c = lex_get_save (lex, error);
+ }
+ }
+
+ /* the actual value is at most of the same length as the source
+ string, because:
+ - shortcut escapes (e.g. "\t") (length 2) are converted to 1 byte
+ - a single \uXXXX escape (length 6) is converted to at most 3 bytes
+ - two \uXXXX escapes (length 12) forming an UTF-16 surrogate pair
+ are converted to 4 bytes
+ */
+ t = jsonp_malloc (lex->saved_text.length + 1);
+ if (!t) {
+ /* this is not very nice, since TOKEN_INVALID is returned */
+ goto out;
+ }
+
+ lex->value.string.val = t;
+
+ /* + 1 to skip the " */
+ p = strbuffer_value (&lex->saved_text) + 1;
+
+ while (*p != '"') {
+ if (*p == '\\') {
+ p++;
+ if (*p == 'u') {
+ size_t length;
+ int32_t value;
+
+ value = decode_unicode_escape (p);
+ if (value < 0) {
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid Unicode escape '%.6s'",
+ p - 1
+ );
+ goto out;
}
- else if (c == '\\') {
- c = lex_get_save(lex, error);
- if (c == 'u') {
- c = lex_get_save(lex, error);
- for (i = 0; i < 4; i++) {
- if (!l_isxdigit(c)) {
- error_set(error, lex, json_error_invalid_syntax,
- "invalid escape");
- goto out;
- }
- c = lex_get_save(lex, error);
- }
- } else if (c == '"' || c == '\\' || c == '/' || c == 'b' || c == 'f' ||
- c == 'n' || c == 'r' || c == 't')
- c = lex_get_save(lex, error);
- else {
- error_set(error, lex, json_error_invalid_syntax, "invalid escape");
- goto out;
+ p += 5;
+
+ if ((0xD800 <= value) && (value <= 0xDBFF)) {
+ /* surrogate pair */
+ if ((*p == '\\') && (*(p + 1) == 'u')) {
+ int32_t value2 = decode_unicode_escape (++p);
+ if (value2 < 0) {
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid Unicode escape '%.6s'",
+ p - 1
+ );
+ goto out;
}
- } else
- c = lex_get_save(lex, error);
- }
- /* the actual value is at most of the same length as the source
- string, because:
- - shortcut escapes (e.g. "\t") (length 2) are converted to 1 byte
- - a single \uXXXX escape (length 6) is converted to at most 3 bytes
- - two \uXXXX escapes (length 12) forming an UTF-16 surrogate pair
- are converted to 4 bytes
- */
- t = jsonp_malloc(lex->saved_text.length + 1);
- if (!t) {
- /* this is not very nice, since TOKEN_INVALID is returned */
- goto out;
- }
- lex->value.string.val = t;
-
- /* + 1 to skip the " */
- p = strbuffer_value(&lex->saved_text) + 1;
-
- while (*p != '"') {
- if (*p == '\\') {
- p++;
- if (*p == 'u') {
- size_t length;
- int32_t value;
-
- value = decode_unicode_escape(p);
- if (value < 0) {
- error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode escape '%.6s'", p - 1);
- goto out;
- }
- p += 5;
-
- if (0xD800 <= value && value <= 0xDBFF) {
- /* surrogate pair */
- if (*p == '\\' && *(p + 1) == 'u') {
- int32_t value2 = decode_unicode_escape(++p);
- if (value2 < 0) {
- error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode escape '%.6s'", p - 1);
- goto out;
- }
- p += 5;
-
- if (0xDC00 <= value2 && value2 <= 0xDFFF) {
- /* valid second surrogate */
- value =
- ((value - 0xD800) << 10) + (value2 - 0xDC00) + 0x10000;
- } else {
- /* invalid second surrogate */
- error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode '\\u%04X\\u%04X'", value, value2);
- goto out;
- }
- } else {
- /* no second surrogate */
- error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode '\\u%04X'", value);
- goto out;
- }
- } else if (0xDC00 <= value && value <= 0xDFFF) {
- error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode '\\u%04X'", value);
- goto out;
- }
-
- if (utf8_encode(value, t, &length))
- assert(0);
- t += length;
+ p += 5;
+
+ if ((0xDC00 <= value2) && (value2 <= 0xDFFF)) {
+ /* valid second surrogate */
+ value =
+ ((value - 0xD800) << 10) + (value2 - 0xDC00) + 0x10000;
} else {
- switch (*p) {
- case '"':
- case '\\':
- case '/':
- *t = *p;
- break;
- case 'b':
- *t = '\b';
- break;
- case 'f':
- *t = '\f';
- break;
- case 'n':
- *t = '\n';
- break;
- case 'r':
- *t = '\r';
- break;
- case 't':
- *t = '\t';
- break;
- default:
- assert(0);
- }
- t++;
- p++;
+ /* invalid second surrogate */
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid Unicode '\\u%04X\\u%04X'",
+ value,
+ value2
+ );
+ goto out;
}
- } else
- *(t++) = *(p++);
+ } else {
+ /* no second surrogate */
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid Unicode '\\u%04X'",
+ value
+ );
+ goto out;
+ }
+ } else if ((0xDC00 <= value) && (value <= 0xDFFF)) {
+ error_set (
+ error,
+ lex,
+ json_error_invalid_syntax,
+ "invalid Unicode '\\u%04X'",
+ value
+ );
+ goto out;
+ }
+
+ if (utf8_encode (value, t, &length)) {
+ assert (0);
+ }
+
+ t += length;
+ } else {
+ switch (*p) {
+ case '"':
+ case '\\':
+ case '/':
+ *t = *p;
+ break;
+ case 'b':
+ *t = '\b';
+ break;
+ case 'f':
+ *t = '\f';
+ break;
+ case 'n':
+ *t = '\n';
+ break;
+ case 'r':
+ *t = '\r';
+ break;
+ case 't':
+ *t = '\t';
+ break;
+ default:
+ assert (0);
+ }
+
+ t++;
+ p++;
+ }
+ } else {
+ *(t++) = *(p++);
}
- *t = '\0';
- lex->value.string.len = t - lex->value.string.val;
- lex->token = TOKEN_STRING;
- return;
+ }
+
+ *t = '\0';
+ lex->value.string.len = t - lex->value.string.val;
+ lex->token = TOKEN_STRING;
+ return;
out:
- lex_free_string(lex);
+ lex_free_string (lex);
}
#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */
-#if JSON_INTEGER_IS_LONG_LONG
-#ifdef _MSC_VER /* Microsoft Visual Studio */
-#define json_strtoint _strtoi64
-#else
-#define json_strtoint strtoll
-#endif
-#else
-#define json_strtoint strtol
-#endif
+ #if JSON_INTEGER_IS_LONG_LONG
+ #ifdef _MSC_VER /* Microsoft Visual Studio */
+#define json_strtoint _strtoi64
+ #else
+#define json_strtoint strtoll
+ #endif
+ #else
+#define json_strtoint strtol
+ #endif
#endif
-static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
- const char *saved_text;
- char *end;
- double doubleval;
-
- lex->token = TOKEN_INVALID;
-
- if (c == '-')
- c = lex_get_save(lex, error);
-
- if (c == '0') {
- c = lex_get_save(lex, error);
- if (l_isdigit(c)) {
- lex_unget_unsave(lex, c);
- goto out;
- }
- } else if (l_isdigit(c)) {
- do
- c = lex_get_save(lex, error);
- while (l_isdigit(c));
- } else {
- lex_unget_unsave(lex, c);
- goto out;
+static int
+lex_scan_number (
+ lex_t *lex,
+ int c,
+ json_error_t *error
+ )
+{
+ const char *saved_text;
+ char *end;
+ double doubleval;
+
+ lex->token = TOKEN_INVALID;
+
+ if (c == '-') {
+ c = lex_get_save (lex, error);
+ }
+
+ if (c == '0') {
+ c = lex_get_save (lex, error);
+ if (l_isdigit (c)) {
+ lex_unget_unsave (lex, c);
+ goto out;
+ }
+ } else if (l_isdigit (c)) {
+ do {
+ c = lex_get_save (lex, error);
+ } while (l_isdigit (c));
+ } else {
+ lex_unget_unsave (lex, c);
+ goto out;
+ }
+
+ if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && (c != '.') && (c != 'E') && (c != 'e')) {
+ json_int_t intval;
+
+ lex_unget_unsave (lex, c);
+
+ saved_text = strbuffer_value (&lex->saved_text);
+
+ errno = 0;
+ intval = json_strtoint (saved_text, &end, 10);
+ if (errno == ERANGE) {
+ if (intval < 0) {
+ error_set (
+ error,
+ lex,
+ json_error_numeric_overflow,
+ "too big negative integer"
+ );
+ } else {
+ error_set (error, lex, json_error_numeric_overflow, "too big integer");
+ }
+
+ goto out;
}
- if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && c != '.' && c != 'E' && c != 'e') {
- json_int_t intval;
+ assert (end == saved_text + lex->saved_text.length);
- lex_unget_unsave(lex, c);
+ lex->token = TOKEN_INTEGER;
+ lex->value.integer = intval;
+ return 0;
+ }
- saved_text = strbuffer_value(&lex->saved_text);
+ if (c == '.') {
+ c = lex_get (lex, error);
+ if (!l_isdigit (c)) {
+ lex_unget (lex, c);
+ goto out;
+ }
- errno = 0;
- intval = json_strtoint(saved_text, &end, 10);
- if (errno == ERANGE) {
- if (intval < 0)
- error_set(error, lex, json_error_numeric_overflow,
- "too big negative integer");
- else
- error_set(error, lex, json_error_numeric_overflow, "too big integer");
- goto out;
- }
+ lex_save (lex, c);
- assert(end == saved_text + lex->saved_text.length);
+ do {
+ c = lex_get_save (lex, error);
+ } while (l_isdigit (c));
+ }
- lex->token = TOKEN_INTEGER;
- lex->value.integer = intval;
- return 0;
+ if ((c == 'E') || (c == 'e')) {
+ c = lex_get_save (lex, error);
+ if ((c == '+') || (c == '-')) {
+ c = lex_get_save (lex, error);
}
- if (c == '.') {
- c = lex_get(lex, error);
- if (!l_isdigit(c)) {
- lex_unget(lex, c);
- goto out;
- }
- lex_save(lex, c);
-
- do
- c = lex_get_save(lex, error);
- while (l_isdigit(c));
+ if (!l_isdigit (c)) {
+ lex_unget_unsave (lex, c);
+ goto out;
}
- if (c == 'E' || c == 'e') {
- c = lex_get_save(lex, error);
- if (c == '+' || c == '-')
- c = lex_get_save(lex, error);
+ do {
+ c = lex_get_save (lex, error);
+ } while (l_isdigit (c));
+ }
- if (!l_isdigit(c)) {
- lex_unget_unsave(lex, c);
- goto out;
- }
+ lex_unget_unsave (lex, c);
- do
- c = lex_get_save(lex, error);
- while (l_isdigit(c));
- }
+ if (jsonp_strtod (&lex->saved_text, &doubleval)) {
+ error_set (error, lex, json_error_numeric_overflow, "real number overflow");
+ goto out;
+ }
- lex_unget_unsave(lex, c);
-
- if (jsonp_strtod(&lex->saved_text, &doubleval)) {
- error_set(error, lex, json_error_numeric_overflow, "real number overflow");
- goto out;
- }
-
- lex->token = TOKEN_REAL;
- lex->value.real = doubleval;
- return 0;
+ lex->token = TOKEN_REAL;
+ lex->value.real = doubleval;
+ return 0;
out:
- return -1;
+ return -1;
}
-static int lex_scan(lex_t *lex, json_error_t *error) {
- int c;
+static int
+lex_scan (
+ lex_t *lex,
+ json_error_t *error
+ )
+{
+ int c;
- strbuffer_clear(&lex->saved_text);
+ strbuffer_clear (&lex->saved_text);
- if (lex->token == TOKEN_STRING)
- lex_free_string(lex);
+ if (lex->token == TOKEN_STRING) {
+ lex_free_string (lex);
+ }
- do
- c = lex_get(lex, error);
- while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
+ do {
+ c = lex_get (lex, error);
+ } while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
- if (c == STREAM_STATE_EOF) {
- lex->token = TOKEN_EOF;
- goto out;
- }
+ if (c == STREAM_STATE_EOF) {
+ lex->token = TOKEN_EOF;
+ goto out;
+ }
- if (c == STREAM_STATE_ERROR) {
- lex->token = TOKEN_INVALID;
- goto out;
+ if (c == STREAM_STATE_ERROR) {
+ lex->token = TOKEN_INVALID;
+ goto out;
+ }
+
+ lex_save (lex, c);
+
+ if ((c == '{') || (c == '}') || (c == '[') || (c == ']') || (c == ':') || (c == ',')) {
+ lex->token = c;
+ } else if (c == '"') {
+ lex_scan_string (lex, error);
+ } else if (l_isdigit (c) || (c == '-')) {
+ if (lex_scan_number (lex, c, error)) {
+ goto out;
}
+ } else if (l_isalpha (c)) {
+ /* eat up the whole identifier for clearer error messages */
+ const char *saved_text;
- lex_save(lex, c);
+ do {
+ c = lex_get_save (lex, error);
+ } while (l_isalpha (c));
- if (c == '{' || c == '}' || c == '[' || c == ']' || c == ':' || c == ',')
- lex->token = c;
+ lex_unget_unsave (lex, c);
- else if (c == '"')
- lex_scan_string(lex, error);
-
- else if (l_isdigit(c) || c == '-') {
- if (lex_scan_number(lex, c, error))
- goto out;
- }
+ saved_text = strbuffer_value (&lex->saved_text);
- else if (l_isalpha(c)) {
- /* eat up the whole identifier for clearer error messages */
- const char *saved_text;
-
- do
- c = lex_get_save(lex, error);
- while (l_isalpha(c));
- lex_unget_unsave(lex, c);
-
- saved_text = strbuffer_value(&lex->saved_text);
-
- if (strcmp(saved_text, "true") == 0)
- lex->token = TOKEN_TRUE;
- else if (strcmp(saved_text, "false") == 0)
- lex->token = TOKEN_FALSE;
- else if (strcmp(saved_text, "null") == 0)
- lex->token = TOKEN_NULL;
- else
- lex->token = TOKEN_INVALID;
- }
-
- else {
- /* save the rest of the input UTF-8 sequence to get an error
- message of valid UTF-8 */
- lex_save_cached(lex);
- lex->token = TOKEN_INVALID;
+ if (strcmp (saved_text, "true") == 0) {
+ lex->token = TOKEN_TRUE;
+ } else if (strcmp (saved_text, "false") == 0) {
+ lex->token = TOKEN_FALSE;
+ } else if (strcmp (saved_text, "null") == 0) {
+ lex->token = TOKEN_NULL;
+ } else {
+ lex->token = TOKEN_INVALID;
}
+ } else {
+ /* save the rest of the input UTF-8 sequence to get an error
+ message of valid UTF-8 */
+ lex_save_cached (lex);
+ lex->token = TOKEN_INVALID;
+ }
out:
- return lex->token;
+ return lex->token;
}
-static char *lex_steal_string(lex_t *lex, size_t *out_len) {
- char *result = NULL;
- if (lex->token == TOKEN_STRING) {
- result = lex->value.string.val;
- *out_len = lex->value.string.len;
- lex->value.string.val = NULL;
- lex->value.string.len = 0;
- }
- return result;
+static char *
+lex_steal_string (
+ lex_t *lex,
+ size_t *out_len
+ )
+{
+ char *result = NULL;
+
+ if (lex->token == TOKEN_STRING) {
+ result = lex->value.string.val;
+ *out_len = lex->value.string.len;
+ lex->value.string.val = NULL;
+ lex->value.string.len = 0;
+ }
+
+ return result;
}
-static int lex_init(lex_t *lex, get_func get, size_t flags, void *data) {
- stream_init(&lex->stream, get, data);
- if (strbuffer_init(&lex->saved_text))
- return -1;
+static int
+lex_init (
+ lex_t *lex,
+ get_func get,
+ size_t flags,
+ void *data
+ )
+{
+ stream_init (&lex->stream, get, data);
+ if (strbuffer_init (&lex->saved_text)) {
+ return -1;
+ }
- lex->flags = flags;
- lex->token = TOKEN_INVALID;
- return 0;
+ lex->flags = flags;
+ lex->token = TOKEN_INVALID;
+ return 0;
}
-static void lex_close(lex_t *lex) {
- if (lex->token == TOKEN_STRING)
- lex_free_string(lex);
- strbuffer_close(&lex->saved_text);
+static void
+lex_close (
+ lex_t *lex
+ )
+{
+ if (lex->token == TOKEN_STRING) {
+ lex_free_string (lex);
+ }
+
+ strbuffer_close (&lex->saved_text);
}
/*** parser ***/
-static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error);
-
-static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
- json_t *object = json_object();
- if (!object)
- return NULL;
+static json_t *
+parse_value (
+ lex_t *lex,
+ size_t flags,
+ json_error_t *error
+ );
+
+static json_t *
+parse_object (
+ lex_t *lex,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ json_t *object = json_object ();
+
+ if (!object) {
+ return NULL;
+ }
- lex_scan(lex, error);
- if (lex->token == '}')
- return object;
+ lex_scan (lex, error);
+ if (lex->token == '}') {
+ return object;
+ }
- while (1) {
- char *key;
- size_t len;
- json_t *value;
+ while (1) {
+ char *key;
+ size_t len;
+ json_t *value;
- if (lex->token != TOKEN_STRING) {
- error_set(error, lex, json_error_invalid_syntax, "string or '}' expected");
- goto error;
- }
+ if (lex->token != TOKEN_STRING) {
+ error_set (error, lex, json_error_invalid_syntax, "string or '}' expected");
+ goto error;
+ }
- key = lex_steal_string(lex, &len);
- if (!key)
- return NULL;
- if (memchr(key, '\0', len)) {
- jsonp_free(key);
- error_set(error, lex, json_error_null_byte_in_key,
- "NUL byte in object key not supported");
- goto error;
- }
+ key = lex_steal_string (lex, &len);
+ if (!key) {
+ return NULL;
+ }
- if (flags & JSON_REJECT_DUPLICATES) {
- if (json_object_get(object, key)) {
- jsonp_free(key);
- error_set(error, lex, json_error_duplicate_key, "duplicate object key");
- goto error;
- }
- }
+ if (memchr (key, '\0', len)) {
+ jsonp_free (key);
+ error_set (
+ error,
+ lex,
+ json_error_null_byte_in_key,
+ "NUL byte in object key not supported"
+ );
+ goto error;
+ }
- lex_scan(lex, error);
- if (lex->token != ':') {
- jsonp_free(key);
- error_set(error, lex, json_error_invalid_syntax, "':' expected");
- goto error;
- }
+ if (flags & JSON_REJECT_DUPLICATES) {
+ if (json_object_get (object, key)) {
+ jsonp_free (key);
+ error_set (error, lex, json_error_duplicate_key, "duplicate object key");
+ goto error;
+ }
+ }
- lex_scan(lex, error);
- value = parse_value(lex, flags, error);
- if (!value) {
- jsonp_free(key);
- goto error;
- }
+ lex_scan (lex, error);
+ if (lex->token != ':') {
+ jsonp_free (key);
+ error_set (error, lex, json_error_invalid_syntax, "':' expected");
+ goto error;
+ }
- if (json_object_set_new_nocheck(object, key, value)) {
- jsonp_free(key);
- goto error;
- }
+ lex_scan (lex, error);
+ value = parse_value (lex, flags, error);
+ if (!value) {
+ jsonp_free (key);
+ goto error;
+ }
- jsonp_free(key);
+ if (json_object_set_new_nocheck (object, key, value)) {
+ jsonp_free (key);
+ goto error;
+ }
- lex_scan(lex, error);
- if (lex->token != ',')
- break;
+ jsonp_free (key);
- lex_scan(lex, error);
+ lex_scan (lex, error);
+ if (lex->token != ',') {
+ break;
}
- if (lex->token != '}') {
- error_set(error, lex, json_error_invalid_syntax, "'}' expected");
- goto error;
- }
+ lex_scan (lex, error);
+ }
- return object;
+ if (lex->token != '}') {
+ error_set (error, lex, json_error_invalid_syntax, "'}' expected");
+ goto error;
+ }
+
+ return object;
error:
- json_decref(object);
- return NULL;
+ json_decref (object);
+ return NULL;
}
-static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error) {
- json_t *array = json_array();
- if (!array)
- return NULL;
+static json_t *
+parse_array (
+ lex_t *lex,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ json_t *array = json_array ();
- lex_scan(lex, error);
- if (lex->token == ']')
- return array;
-
- while (lex->token) {
- json_t *elem = parse_value(lex, flags, error);
- if (!elem)
- goto error;
+ if (!array) {
+ return NULL;
+ }
- if (json_array_append_new(array, elem)) {
- goto error;
- }
+ lex_scan (lex, error);
+ if (lex->token == ']') {
+ return array;
+ }
- lex_scan(lex, error);
- if (lex->token != ',')
- break;
+ while (lex->token) {
+ json_t *elem = parse_value (lex, flags, error);
+ if (!elem) {
+ goto error;
+ }
- lex_scan(lex, error);
+ if (json_array_append_new (array, elem)) {
+ goto error;
}
- if (lex->token != ']') {
- error_set(error, lex, json_error_invalid_syntax, "']' expected");
- goto error;
+ lex_scan (lex, error);
+ if (lex->token != ',') {
+ break;
}
- return array;
+ lex_scan (lex, error);
+ }
+
+ if (lex->token != ']') {
+ error_set (error, lex, json_error_invalid_syntax, "']' expected");
+ goto error;
+ }
+
+ return array;
error:
- json_decref(array);
- return NULL;
+ json_decref (array);
+ return NULL;
}
-static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
- json_t *json;
+static json_t *
+parse_value (
+ lex_t *lex,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ json_t *json;
+
+ lex->depth++;
+ if (lex->depth > JSON_PARSER_MAX_DEPTH) {
+ error_set (error, lex, json_error_stack_overflow, "maximum parsing depth reached");
+ return NULL;
+ }
+
+ switch (lex->token) {
+ case TOKEN_STRING:
+ {
+ const char *value = lex->value.string.val;
+ size_t len = lex->value.string.len;
+
+ if (!(flags & JSON_ALLOW_NUL)) {
+ if (memchr (value, '\0', len)) {
+ error_set (
+ error,
+ lex,
+ json_error_null_character,
+ "\\u0000 is not allowed without JSON_ALLOW_NUL"
+ );
+ return NULL;
+ }
+ }
- lex->depth++;
- if (lex->depth > JSON_PARSER_MAX_DEPTH) {
- error_set(error, lex, json_error_stack_overflow, "maximum parsing depth reached");
- return NULL;
+ json = jsonp_stringn_nocheck_own (value, len);
+ lex->value.string.val = NULL;
+ lex->value.string.len = 0;
+ break;
}
- switch (lex->token) {
- case TOKEN_STRING: {
- const char *value = lex->value.string.val;
- size_t len = lex->value.string.len;
-
- if (!(flags & JSON_ALLOW_NUL)) {
- if (memchr(value, '\0', len)) {
- error_set(error, lex, json_error_null_character,
- "\\u0000 is not allowed without JSON_ALLOW_NUL");
- return NULL;
- }
- }
-
- json = jsonp_stringn_nocheck_own(value, len);
- lex->value.string.val = NULL;
- lex->value.string.len = 0;
- break;
- }
-
- case TOKEN_INTEGER: {
- json = json_integer(lex->value.integer);
- break;
- }
+ case TOKEN_INTEGER:
+ {
+ json = json_integer (lex->value.integer);
+ break;
+ }
- case TOKEN_REAL: {
- json = json_real(lex->value.real);
- break;
- }
+ case TOKEN_REAL:
+ {
+ json = json_real (lex->value.real);
+ break;
+ }
- case TOKEN_TRUE:
- json = json_true();
- break;
+ case TOKEN_TRUE:
+ json = json_true ();
+ break;
- case TOKEN_FALSE:
- json = json_false();
- break;
+ case TOKEN_FALSE:
+ json = json_false ();
+ break;
- case TOKEN_NULL:
- json = json_null();
- break;
+ case TOKEN_NULL:
+ json = json_null ();
+ break;
- case '{':
- json = parse_object(lex, flags, error);
- break;
+ case '{':
+ json = parse_object (lex, flags, error);
+ break;
- case '[':
- json = parse_array(lex, flags, error);
- break;
+ case '[':
+ json = parse_array (lex, flags, error);
+ break;
- case TOKEN_INVALID:
- error_set(error, lex, json_error_invalid_syntax, "invalid token");
- return NULL;
+ case TOKEN_INVALID:
+ error_set (error, lex, json_error_invalid_syntax, "invalid token");
+ return NULL;
- default:
- error_set(error, lex, json_error_invalid_syntax, "unexpected token");
- return NULL;
- }
+ default:
+ error_set (error, lex, json_error_invalid_syntax, "unexpected token");
+ return NULL;
+ }
- if (!json)
- return NULL;
+ if (!json) {
+ return NULL;
+ }
- lex->depth--;
- return json;
+ lex->depth--;
+ return json;
}
-static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error) {
- json_t *result;
-
- lex->depth = 0;
-
- lex_scan(lex, error);
- if (!(flags & JSON_DECODE_ANY)) {
- if (lex->token != '[' && lex->token != '{') {
- error_set(error, lex, json_error_invalid_syntax, "'[' or '{' expected");
- return NULL;
- }
+static json_t *
+parse_json (
+ lex_t *lex,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ json_t *result;
+
+ lex->depth = 0;
+
+ lex_scan (lex, error);
+ if (!(flags & JSON_DECODE_ANY)) {
+ if ((lex->token != '[') && (lex->token != '{')) {
+ error_set (error, lex, json_error_invalid_syntax, "'[' or '{' expected");
+ return NULL;
}
+ }
- result = parse_value(lex, flags, error);
- if (!result)
- return NULL;
-
- if (!(flags & JSON_DISABLE_EOF_CHECK)) {
- lex_scan(lex, error);
- if (lex->token != TOKEN_EOF) {
- error_set(error, lex, json_error_end_of_input_expected,
- "end of file expected");
- json_decref(result);
- return NULL;
- }
+ result = parse_value (lex, flags, error);
+ if (!result) {
+ return NULL;
+ }
+
+ if (!(flags & JSON_DISABLE_EOF_CHECK)) {
+ lex_scan (lex, error);
+ if (lex->token != TOKEN_EOF) {
+ error_set (
+ error,
+ lex,
+ json_error_end_of_input_expected,
+ "end of file expected"
+ );
+ json_decref (result);
+ return NULL;
}
+ }
- if (error) {
- /* Save the position even though there was no error */
- error->position = (int)lex->stream.position;
- }
+ if (error) {
+ /* Save the position even though there was no error */
+ error->position = (int)lex->stream.position;
+ }
- return result;
+ return result;
}
typedef struct {
- const char *data;
- size_t pos;
+ const char *data;
+ size_t pos;
} string_data_t;
-static int string_get(void *data) {
- char c;
- string_data_t *stream = (string_data_t *)data;
- c = stream->data[stream->pos];
- if (c == '\0')
- return EOF;
- else {
- stream->pos++;
- return (unsigned char)c;
- }
-}
-
-json_t *json_loads(const char *string, size_t flags, json_error_t *error) {
- lex_t lex;
- json_t *result;
- string_data_t stream_data;
+static int
+string_get (
+ void *data
+ )
+{
+ char c;
+ string_data_t *stream = (string_data_t *)data;
- jsonp_error_init(error, "<string>");
+ c = stream->data[stream->pos];
+ if (c == '\0') {
+ return EOF;
+ } else {
+ stream->pos++;
+ return (unsigned char)c;
+ }
+}
- if (string == NULL) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+json_t *
+json_loads (
+ const char *string,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ lex_t lex;
+ json_t *result;
+ string_data_t stream_data;
+
+ jsonp_error_init (error, "<string>");
+
+ if (string == NULL) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
- stream_data.data = string;
- stream_data.pos = 0;
+ stream_data.data = string;
+ stream_data.pos = 0;
- if (lex_init(&lex, string_get, flags, (void *)&stream_data))
- return NULL;
+ if (lex_init (&lex, string_get, flags, (void *)&stream_data)) {
+ return NULL;
+ }
- result = parse_json(&lex, flags, error);
+ result = parse_json (&lex, flags, error);
- lex_close(&lex);
- return result;
+ lex_close (&lex);
+ return result;
}
typedef struct {
- const char *data;
- size_t len;
- size_t pos;
+ const char *data;
+ size_t len;
+ size_t pos;
} buffer_data_t;
-static int buffer_get(void *data) {
- char c;
- buffer_data_t *stream = data;
- if (stream->pos >= stream->len)
- return EOF;
+static int
+buffer_get (
+ void *data
+ )
+{
+ char c;
+ buffer_data_t *stream = data;
- c = stream->data[stream->pos];
- stream->pos++;
- return (unsigned char)c;
-}
-
-json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error) {
- lex_t lex;
- json_t *result;
- buffer_data_t stream_data;
+ if (stream->pos >= stream->len) {
+ return EOF;
+ }
- jsonp_error_init(error, "<buffer>");
+ c = stream->data[stream->pos];
+ stream->pos++;
+ return (unsigned char)c;
+}
- if (buffer == NULL) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+json_t *
+json_loadb (
+ const char *buffer,
+ size_t buflen,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ lex_t lex;
+ json_t *result;
+ buffer_data_t stream_data;
+
+ jsonp_error_init (error, "<buffer>");
+
+ if (buffer == NULL) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
- stream_data.data = buffer;
- stream_data.pos = 0;
- stream_data.len = buflen;
+ stream_data.data = buffer;
+ stream_data.pos = 0;
+ stream_data.len = buflen;
- if (lex_init(&lex, buffer_get, flags, (void *)&stream_data))
- return NULL;
+ if (lex_init (&lex, buffer_get, flags, (void *)&stream_data)) {
+ return NULL;
+ }
- result = parse_json(&lex, flags, error);
+ result = parse_json (&lex, flags, error);
- lex_close(&lex);
- return result;
+ lex_close (&lex);
+ return result;
}
-json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) {
- lex_t lex;
- const char *source;
- json_t *result;
-#ifdef HAVE_UNISTD_H
- if (input == stdin)
- source = "<stdin>";
- else
-#endif
- source = "<stream>";
-
- jsonp_error_init(error, source);
-
- if (input == NULL) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+json_t *
+json_loadf (
+ FILE *input,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ lex_t lex;
+ const char *source;
+ json_t *result;
+
+ #ifdef HAVE_UNISTD_H
+ if (input == stdin) {
+ source = "<stdin>";
+ } else
+ #endif
+ source = "<stream>";
+
+ jsonp_error_init (error, source);
+
+ if (input == NULL) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
- if (lex_init(&lex, (get_func)fgetc, flags, input))
- return NULL;
+ if (lex_init (&lex, (get_func)fgetc, flags, input)) {
+ return NULL;
+ }
- result = parse_json(&lex, flags, error);
+ result = parse_json (&lex, flags, error);
- lex_close(&lex);
- return result;
-}
-
-static int fd_get_func(int *fd) {
-#ifdef HAVE_UNISTD_H
- uint8_t c;
- if (read(*fd, &c, 1) == 1)
- return c;
-#endif
- return EOF;
+ lex_close (&lex);
+ return result;
}
-json_t *json_loadfd(int input, size_t flags, json_error_t *error) {
- lex_t lex;
- const char *source;
- json_t *result;
-
-#ifdef HAVE_UNISTD_H
- if (input == STDIN_FILENO)
- source = "<stdin>";
- else
-#endif
- source = "<stream>";
+static int
+fd_get_func (
+ int *fd
+ )
+{
+ #ifdef HAVE_UNISTD_H
+ uint8_t c;
+ if (read (*fd, &c, 1) == 1) {
+ return c;
+ }
- jsonp_error_init(error, source);
+ #endif
+ return EOF;
+}
- if (input < 0) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+json_t *
+json_loadfd (
+ int input,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ lex_t lex;
+ const char *source;
+ json_t *result;
+
+ #ifdef HAVE_UNISTD_H
+ if (input == STDIN_FILENO) {
+ source = "<stdin>";
+ } else
+ #endif
+ source = "<stream>";
+
+ jsonp_error_init (error, source);
+
+ if (input < 0) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
- if (lex_init(&lex, (get_func)fd_get_func, flags, &input))
- return NULL;
+ if (lex_init (&lex, (get_func)fd_get_func, flags, &input)) {
+ return NULL;
+ }
- result = parse_json(&lex, flags, error);
+ result = parse_json (&lex, flags, error);
- lex_close(&lex);
- return result;
+ lex_close (&lex);
+ return result;
}
-json_t *json_load_file(const char *path, size_t flags, json_error_t *error) {
- json_t *result;
- FILE *fp;
+json_t *
+json_load_file (
+ const char *path,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ json_t *result;
+ FILE *fp;
- jsonp_error_init(error, path);
-
- if (path == NULL) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+ jsonp_error_init (error, path);
- fp = fopen(path, "rb");
- if (!fp) {
- error_set(error, NULL, json_error_cannot_open_file, "unable to open %s: %s", path,
- strerror(errno));
- return NULL;
- }
+ if (path == NULL) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
+
+ fp = fopen (path, "rb");
+ if (!fp) {
+ error_set (
+ error,
+ NULL,
+ json_error_cannot_open_file,
+ "unable to open %s: %s",
+ path,
+ strerror (errno)
+ );
+ return NULL;
+ }
- result = json_loadf(fp, flags, error);
+ result = json_loadf (fp, flags, error);
- fclose(fp);
- return result;
+ fclose (fp);
+ return result;
}
-#define MAX_BUF_LEN 1024
+#define MAX_BUF_LEN 1024
typedef struct {
- char data[MAX_BUF_LEN];
- size_t len;
- size_t pos;
- json_load_callback_t callback;
- void *arg;
+ char data[MAX_BUF_LEN];
+ size_t len;
+ size_t pos;
+ json_load_callback_t callback;
+ void *arg;
} callback_data_t;
-static int callback_get(void *data) {
- char c;
- callback_data_t *stream = data;
-
- if (stream->pos >= stream->len) {
- stream->pos = 0;
- stream->len = stream->callback(stream->data, MAX_BUF_LEN, stream->arg);
- if (stream->len == 0 || stream->len == (size_t)-1)
- return EOF;
+static int
+callback_get (
+ void *data
+ )
+{
+ char c;
+ callback_data_t *stream = data;
+
+ if (stream->pos >= stream->len) {
+ stream->pos = 0;
+ stream->len = stream->callback (stream->data, MAX_BUF_LEN, stream->arg);
+ if ((stream->len == 0) || (stream->len == (size_t)-1)) {
+ return EOF;
}
+ }
- c = stream->data[stream->pos];
- stream->pos++;
- return (unsigned char)c;
+ c = stream->data[stream->pos];
+ stream->pos++;
+ return (unsigned char)c;
}
-json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags,
- json_error_t *error) {
- lex_t lex;
- json_t *result;
+json_t *
+json_load_callback (
+ json_load_callback_t callback,
+ void *arg,
+ size_t flags,
+ json_error_t *error
+ )
+{
+ lex_t lex;
+ json_t *result;
- callback_data_t stream_data;
+ callback_data_t stream_data;
- memset(&stream_data, 0, sizeof(stream_data));
- stream_data.callback = callback;
- stream_data.arg = arg;
+ memset (&stream_data, 0, sizeof (stream_data));
+ stream_data.callback = callback;
+ stream_data.arg = arg;
- jsonp_error_init(error, "<callback>");
+ jsonp_error_init (error, "<callback>");
- if (callback == NULL) {
- error_set(error, NULL, json_error_invalid_argument, "wrong arguments");
- return NULL;
- }
+ if (callback == NULL) {
+ error_set (error, NULL, json_error_invalid_argument, "wrong arguments");
+ return NULL;
+ }
- if (lex_init(&lex, (get_func)callback_get, flags, &stream_data))
- return NULL;
+ if (lex_init (&lex, (get_func)callback_get, flags, &stream_data)) {
+ return NULL;
+ }
- result = parse_json(&lex, flags, error);
+ result = parse_json (&lex, flags, error);
- lex_close(&lex);
- return result;
+ lex_close (&lex);
+ return result;
}
diff --git a/RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.c b/RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.c index 39de622d59..4db5778336 100644 --- a/RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.c +++ b/RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.c @@ -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;
}
@@ -92,10 +93,9 @@ LibCredentialGetAuthInfo ( EFI_STATUS
EFIAPI
LibStopRedfishService (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
)
{
return EFI_UNSUPPORTED;
}
-
diff --git a/RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLibNull.c b/RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLibNull.c index 5c93a003e3..b30f9e37a4 100644 --- a/RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLibNull.c +++ b/RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLibNull.c @@ -23,12 +23,13 @@ **/
EFI_STATUS
RedfishPlatformHostInterfaceDeviceDescriptor (
- IN UINT8 *DeviceType,
+ 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.
@@ -44,9 +45,9 @@ RedfishPlatformHostInterfaceDeviceDescriptor ( **/
EFI_STATUS
RedfishPlatformHostInterfaceProtocolData (
- IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
- IN UINT8 IndexOfProtocolData
-)
+ IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,
+ IN UINT8 IndexOfProtocolData
+ )
{
return EFI_NOT_FOUND;
}
diff --git a/RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.c b/RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.c index 6d13256e83..5c51a8b295 100644 --- a/RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.c +++ b/RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.c @@ -34,11 +34,11 @@ **/
EFI_STATUS
RedfishContentEncode (
- IN CHAR8 *ContentEncodedValue,
- IN CHAR8 *OriginalContent,
- IN UINTN OriginalContentLength,
- OUT VOID **EncodedContentPointer,
- OUT UINTN *EncodedContentLength
+ IN CHAR8 *ContentEncodedValue,
+ IN CHAR8 *OriginalContent,
+ IN UINTN OriginalContentLength,
+ OUT VOID **EncodedContentPointer,
+ OUT UINTN *EncodedContentLength
)
{
return EFI_UNSUPPORTED;
@@ -70,11 +70,11 @@ RedfishContentEncode ( **/
EFI_STATUS
RedfishContentDecode (
- IN CHAR8 *ContentDecodedValue,
- IN VOID *ContentPointer,
- IN UINTN ContentLength,
- OUT VOID **DecodedContentPointer,
- OUT UINTN *DecodedContentLength
+ IN CHAR8 *ContentDecodedValue,
+ IN VOID *ContentPointer,
+ IN UINTN ContentLength,
+ OUT VOID **DecodedContentPointer,
+ OUT UINTN *DecodedContentLength
)
{
return EFI_UNSUPPORTED;
diff --git a/RedfishPkg/PrivateInclude/Crt/stdarg.h b/RedfishPkg/PrivateInclude/Crt/stdarg.h index 411275b58e..c94527f7a7 100644 --- a/RedfishPkg/PrivateInclude/Crt/stdarg.h +++ b/RedfishPkg/PrivateInclude/Crt/stdarg.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CRT_STDARG_H_
#define REDFISH_CRT_STDARG_H_
diff --git a/RedfishPkg/PrivateInclude/Crt/stdio.h b/RedfishPkg/PrivateInclude/Crt/stdio.h index a6b8c32df6..10c8e4d11d 100644 --- a/RedfishPkg/PrivateInclude/Crt/stdio.h +++ b/RedfishPkg/PrivateInclude/Crt/stdio.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CRT_STDIO_H_
#define REDFISH_CRT_STDIO_H_
diff --git a/RedfishPkg/PrivateInclude/Crt/sys/time.h b/RedfishPkg/PrivateInclude/Crt/sys/time.h index 3ae791ae68..f3000f2303 100644 --- a/RedfishPkg/PrivateInclude/Crt/sys/time.h +++ b/RedfishPkg/PrivateInclude/Crt/sys/time.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CRT_SYS_TIME_H_
#define REDFISH_CRT_SYS_TIME_H_
diff --git a/RedfishPkg/PrivateInclude/Crt/sys/types.h b/RedfishPkg/PrivateInclude/Crt/sys/types.h index e69510849d..1d9816c7e3 100644 --- a/RedfishPkg/PrivateInclude/Crt/sys/types.h +++ b/RedfishPkg/PrivateInclude/Crt/sys/types.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CRT_SYS_TYPES_H_
#define REDFISH_CRT_SYS_TYPES_H_
diff --git a/RedfishPkg/PrivateInclude/Crt/time.h b/RedfishPkg/PrivateInclude/Crt/time.h index e378c31ab8..ef15cc3bd3 100644 --- a/RedfishPkg/PrivateInclude/Crt/time.h +++ b/RedfishPkg/PrivateInclude/Crt/time.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef REDFISH_CRT_TIME_H_
#define REDFISH_CRT_TIME_H_
diff --git a/RedfishPkg/PrivateInclude/Library/RedfishLib.h b/RedfishPkg/PrivateInclude/Library/RedfishLib.h index 315b1ec137..b2488abbd4 100644 --- a/RedfishPkg/PrivateInclude/Library/RedfishLib.h +++ b/RedfishPkg/PrivateInclude/Library/RedfishLib.h @@ -80,25 +80,25 @@ ///
/// 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
///
typedef struct {
- EFI_HTTP_STATUS_CODE *StatusCode;
- UINTN HeaderCount;
- EFI_HTTP_HEADER *Headers;
- REDFISH_PAYLOAD Payload;
+ EFI_HTTP_STATUS_CODE *StatusCode;
+ UINTN HeaderCount;
+ EFI_HTTP_HEADER *Headers;
+ REDFISH_PAYLOAD Payload;
} REDFISH_RESPONSE;
///
/// 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;
/**
@@ -117,7 +117,7 @@ typedef struct { REDFISH_SERVICE
EFIAPI
RedfishCreateService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
);
/**
@@ -129,7 +129,7 @@ RedfishCreateService ( VOID
EFIAPI
RedfishCleanupService (
- IN REDFISH_SERVICE RedfishService
+ IN REDFISH_SERVICE RedfishService
);
/**
@@ -150,8 +150,8 @@ RedfishCleanupService ( REDFISH_PAYLOAD
EFIAPI
RedfishCreatePayload (
- IN EDKII_JSON_VALUE Value,
- IN REDFISH_SERVICE RedfishService
+ IN EDKII_JSON_VALUE Value,
+ IN REDFISH_SERVICE RedfishService
);
/**
@@ -163,7 +163,7 @@ RedfishCreatePayload ( VOID
EFIAPI
RedfishCleanupPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
);
/**
@@ -180,7 +180,7 @@ RedfishCleanupPayload ( EDKII_JSON_VALUE
EFIAPI
RedfishJsonInPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
);
/**
@@ -205,9 +205,9 @@ RedfishJsonInPayload ( CHAR8 *
EFIAPI
RedfishBuildPathWithSystemUuid (
- IN CONST CHAR8 *RedPath,
- IN BOOLEAN FromSmbios,
- IN CHAR8 *IdString OPTIONAL
+ IN CONST CHAR8 *RedPath,
+ IN BOOLEAN FromSmbios,
+ IN CHAR8 *IdString OPTIONAL
);
/**
@@ -236,9 +236,9 @@ RedfishBuildPathWithSystemUuid ( EFI_STATUS
EFIAPI
RedfishGetByService (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -266,9 +266,9 @@ RedfishGetByService ( EFI_STATUS
EFIAPI
RedfishGetByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -300,9 +300,9 @@ RedfishGetByUri ( EFI_STATUS
EFIAPI
RedfishGetByPayload (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -338,10 +338,10 @@ RedfishGetByPayload ( EFI_STATUS
EFIAPI
RedfishPatchToUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- IN CONST CHAR8 *Content,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ IN CONST CHAR8 *Content,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -375,9 +375,9 @@ RedfishPatchToUri ( EFI_STATUS
EFIAPI
RedfishPatchToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -410,9 +410,9 @@ RedfishPatchToPayload ( EFI_STATUS
EFIAPI
RedfishPostToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -445,9 +445,9 @@ RedfishPostToPayload ( EFI_STATUS
EFIAPI
RedfishDeleteByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
);
/**
@@ -458,7 +458,7 @@ RedfishDeleteByUri ( **/
VOID
RedfishDumpJsonStringFractions (
- IN CHAR8 *String
+ IN CHAR8 *String
);
/**
@@ -469,8 +469,9 @@ RedfishDumpJsonStringFractions ( **/
VOID
RedfishDumpPayload (
- IN REDFISH_PAYLOAD Payload
+ 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.
@@ -511,10 +513,10 @@ RedfishFreeResponse ( **/
BOOLEAN
RedfishIsValidOdataType (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *OdataTypeName,
- IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
- IN UINTN OdataTypeMappingListSize
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *OdataTypeName,
+ IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
+ IN UINTN OdataTypeMappingListSize
);
/**
@@ -527,8 +529,9 @@ RedfishIsValidOdataType ( **/
BOOLEAN
RedfishIsPayloadCollection (
- IN REDFISH_PAYLOAD Payload
-);
+ 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(
- IN REDFISH_PAYLOAD Payload,
- IN UINTN *CollectionSize
-);
+RedfishGetCollectionSize (
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN *CollectionSize
+ );
+
/**
Get Redfish payload of collection member
@@ -554,9 +558,9 @@ RedfishGetCollectionSize( **/
REDFISH_PAYLOAD
RedfishGetPayloadByIndex (
- IN REDFISH_PAYLOAD Payload,
- IN UINTN Index
-);
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN Index
+ );
/**
Check and return Redfish resource of the given Redpath.
@@ -569,10 +573,10 @@ RedfishGetPayloadByIndex ( **/
EFI_STATUS
RedfishCheckIfRedpathExist (
- IN REDFISH_SERVICE RedfishService,
- IN CHAR8 *Redpath,
- IN REDFISH_RESPONSE *Response OPTIONAL
-);
+ IN REDFISH_SERVICE RedfishService,
+ IN CHAR8 *Redpath,
+ IN REDFISH_RESPONSE *Response OPTIONAL
+ );
/**
This function returns the string of Redfish service version.
@@ -584,9 +588,9 @@ RedfishCheckIfRedpathExist ( **/
EFI_STATUS
-RedfishGetServiceVersion(
- IN REDFISH_SERVICE RedfishService,
- OUT CHAR8 **ServiceVersionStr
+RedfishGetServiceVersion (
+ IN REDFISH_SERVICE RedfishService,
+ OUT CHAR8 **ServiceVersionStr
);
/**
@@ -603,9 +607,10 @@ RedfishGetServiceVersion( **/
EFI_STATUS
RedfishBuildRedpathUseId (
- IN CHAR8 *ServiceVerisonStr,
- IN CHAR8 *Url,
- IN CHAR8 *Id,
- OUT CHAR8 **Redpath
+ IN CHAR8 *ServiceVerisonStr,
+ IN CHAR8 *Url,
+ IN CHAR8 *Id,
+ OUT CHAR8 **Redpath
);
+
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c index 58ef4f8fdb..f240dfba13 100644 --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c @@ -14,17 +14,20 @@ #include <Library/SortLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
-int errno = 0;
-char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n";
+int errno = 0;
+char errnum_message[] = "We don't support to map errnum to the error message on edk2 Redfish\n";
// This is required to keep VC++ happy if you use floating-point
-int _fltused = 1;
+int _fltused = 1;
/**
Determine if a particular character is an alphanumeric character
@return Returns 1 if c is an alphanumeric character, otherwise returns 0.
**/
-int isalnum (int c)
+int
+isalnum (
+ int c
+ )
{
//
// <alnum> ::= [0-9] | [a-z] | [A-Z]
@@ -39,7 +42,10 @@ int isalnum (int c) @return Returns 1 if c is an digital character, otherwise returns 0.
**/
-int isdchar (int c)
+int
+isdchar (
+ int c
+ )
{
//
// [0-9] | [e +-.]
@@ -55,7 +61,10 @@ int isdchar (int c) @return Returns 1 if c is a space character
**/
-int isspace (int c)
+int
+isspace (
+ int c
+ )
{
//
// <space> ::= [ ]
@@ -66,15 +75,21 @@ int isspace (int c) /**
Allocates memory blocks
*/
-void *malloc (size_t size)
+void *
+malloc (
+ size_t size
+ )
{
- return AllocatePool ((UINTN) size);
+ return AllocatePool ((UINTN)size);
}
/**
De-allocates or frees a memory block
*/
-void free (void *ptr)
+void
+free (
+ void *ptr
+ )
{
//
// In Standard C, free() handles a null pointer argument transparently. This
@@ -90,15 +105,20 @@ void free (void *ptr) @return Returns the pointer to duplicated string.
**/
-char * strdup(const char *str)
+char *
+strdup (
+ const char *str
+ )
{
- size_t len;
- char *copy;
+ size_t len;
+ char *copy;
- len = strlen(str) + 1;
- if ((copy = malloc(len)) == NULL)
+ len = strlen (str) + 1;
+ if ((copy = malloc (len)) == NULL) {
return (NULL);
- memcpy(copy, str, len);
+ }
+
+ memcpy (copy, str, len);
return (copy);
}
@@ -115,13 +135,14 @@ char * strdup(const char *str) returned unchanged.
**/
int
-toupper(
- IN int c
+toupper (
+ IN int c
)
{
- if ( (c >= 'a') && (c <= 'z') ) {
+ if ((c >= 'a') && (c <= 'z')) {
c = c - ('a' - 'A');
}
+
return c;
}
@@ -131,15 +152,18 @@ toupper( @return Returns the value of digit.
**/
int
-Digit2Val( int c)
+Digit2Val (
+ int c
+ )
{
- if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) { /* If c is one of [A-Za-z]... */
- c = toupper(c) - 7; // Adjust so 'A' is ('9' + 1)
+ if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) {
+ /* If c is one of [A-Za-z]... */
+ c = toupper (c) - 7; // Adjust so 'A' is ('9' + 1)
}
+
return c - '0'; // Value returned is between 0 and 35, inclusive.
}
-
/** The strtoll function converts the initial portion of the string pointed to
by nptr to long long int representation.
@@ -152,9 +176,13 @@ Digit2Val( int c) and the value of the macro ERANGE is stored in errno.
**/
long long
-strtoll(const char * nptr, char ** endptr, int base)
+strtoll (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
+ const char *pEnd;
long long Result = 0;
long long Previous;
int temp;
@@ -162,71 +190,86 @@ strtoll(const char * nptr, char ** endptr, int base) pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
Negative = FALSE;
++nptr;
- }
- else if(*nptr == '-') {
+ } else if (*nptr == '-') {
Negative = TRUE;
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = MultS64x64 (Result, base) + (long long int)temp;
- if( Result <= Previous) { // Detect Overflow
- if(Negative) {
+ Result = MultS64x64 (Result, base) + (long long int)temp;
+ if ( Result <= Previous) {
+ // Detect Overflow
+ if (Negative) {
Result = LLONG_MIN;
- }
- else {
+ } else {
Result = LLONG_MAX;
}
+
Negative = FALSE;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
- if(Negative) {
+
+ if (Negative) {
Result = -Result;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -285,9 +328,13 @@ strtoll(const char * nptr, char ** endptr, int base) is stored in errno.
**/
long
-strtol(const char * nptr, char ** endptr, int base)
+strtol (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
+ const char *pEnd;
long Result = 0;
long Previous;
int temp;
@@ -295,71 +342,86 @@ strtol(const char * nptr, char ** endptr, int base) pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
Negative = FALSE;
++nptr;
- }
- else if(*nptr == '-') {
+ } else if (*nptr == '-') {
Negative = TRUE;
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = (Result * base) + (long int)temp;
- if( Result <= Previous) { // Detect Overflow
- if(Negative) {
+ Result = (Result * base) + (long int)temp;
+ if ( Result <= Previous) {
+ // Detect Overflow
+ if (Negative) {
Result = LONG_MIN;
- }
- else {
+ } else {
Result = LONG_MAX;
}
+
Negative = FALSE;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
- if(Negative) {
+
+ if (Negative) {
Result = -Result;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -374,66 +436,85 @@ strtol(const char * nptr, char ** endptr, int base) returned and the value of the macro ERANGE is stored in errno.
**/
unsigned long long
-strtoull(const char * nptr, char ** endptr, int base)
+strtoull (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
{
- const char *pEnd;
- unsigned long long Result = 0;
- unsigned long long Previous;
- int temp;
+ const char *pEnd;
+ unsigned long long Result = 0;
+ unsigned long long Previous;
+ int temp;
pEnd = nptr;
- if((base < 0) || (base == 1) || (base > 36)) {
- if(endptr != NULL) {
- *endptr = NULL;
+ if ((base < 0) || (base == 1) || (base > 36)) {
+ if (endptr != NULL) {
+ *endptr = NULL;
}
+
return 0;
}
+
// Skip leading spaces.
- while(isspace(*nptr)) ++nptr;
+ while (isspace (*nptr)) {
+ ++nptr;
+ }
// Process Subject sequence: optional + sign followed by digits.
- if(*nptr == '+') {
+ if (*nptr == '+') {
++nptr;
}
- if(*nptr == '0') { /* Might be Octal or Hex */
- if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
- if((base == 0) || (base == 16)) {
+ if (*nptr == '0') {
+ /* Might be Octal or Hex */
+ if (toupper (nptr[1]) == 'X') {
+ /* Looks like Hex */
+ if ((base == 0) || (base == 16)) {
nptr += 2; /* Skip the "0X" */
- base = 16; /* In case base was 0 */
+ base = 16; /* In case base was 0 */
}
- }
- else { /* Looks like Octal */
- if((base == 0) || (base == 8)) {
+ } else {
+ /* Looks like Octal */
+ if ((base == 0) || (base == 8)) {
++nptr; /* Skip the leading "0" */
base = 8; /* In case base was 0 */
}
}
}
- if(base == 0) { /* If still zero then must be decimal */
+
+ if (base == 0) {
+ /* If still zero then must be decimal */
base = 10;
}
- if(*nptr == '0') {
- for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+
+ if (*nptr == '0') {
+ for ( ; *nptr == '0'; ++nptr) {
+ /* Skip any remaining leading zeros */
+ }
+
pEnd = nptr;
}
- while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ while ( isalnum (*nptr) && ((temp = Digit2Val (*nptr)) < base)) {
Previous = Result;
- Result = DivU64x32 (Result, base) + (unsigned long long)temp;
- if( Result < Previous) { // If we overflowed
+ Result = DivU64x32 (Result, base) + (unsigned long long)temp;
+ if ( Result < Previous) {
+ // If we overflowed
Result = ULLONG_MAX;
- errno = ERANGE;
+ errno = ERANGE;
break;
}
+
pEnd = ++nptr;
}
// Save pointer to final sequence
- if(endptr != NULL) {
+ if (endptr != NULL) {
*endptr = (char *)pEnd;
}
+
return Result;
}
@@ -462,27 +543,34 @@ strtoull(const char * nptr, char ** endptr, int base) @return Return 0.
**/
double
-strtod (const char * __restrict nptr, char ** __restrict endptr) {
-
- DEBUG((DEBUG_INFO, "We don't supprot double type on edk2 yet!"));
- ASSERT(FALSE);
- return (double)0;
+strtod (
+ const char *__restrict nptr,
+ char **__restrict endptr
+ )
+{
+ DEBUG ((DEBUG_INFO, "We don't supprot double type on edk2 yet!"));
+ ASSERT (FALSE);
+ return (double)0;
}
static UINT8 BitMask[] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
- };
+};
#define WHICH8(c) ((unsigned char)(c) >> 3)
#define WHICH_BIT(c) (BitMask[((c) & 0x7)])
-#define BITMAP64 ((UINT64 *)bitmap)
+#define BITMAP64 ((UINT64 *)bitmap)
static
void
-BuildBitmap(unsigned char * bitmap, const char *s2, int n)
+BuildBitmap (
+ unsigned char *bitmap,
+ const char *s2,
+ int n
+ )
{
- unsigned char bit;
- int index;
+ unsigned char bit;
+ int index;
// Initialize bitmap. Bit 0 is always 1 which corresponds to '\0'
for (BITMAP64[0] = index = 1; index < n; index++) {
@@ -490,9 +578,9 @@ BuildBitmap(unsigned char * bitmap, const char *s2, int n) }
// Set bits in bitmap corresponding to the characters in s2
- for (; *s2 != '\0'; s2++) {
- index = WHICH8(*s2);
- bit = WHICH_BIT(*s2);
+ for ( ; *s2 != '\0'; s2++) {
+ index = WHICH8 (*s2);
+ bit = WHICH_BIT (*s2);
bitmap[index] = bitmap[index] | bit;
}
}
@@ -504,21 +592,25 @@ BuildBitmap(unsigned char * bitmap, const char *s2, int n) null pointer if no character from s2 occurs in s1.
**/
char *
-strpbrk(const char *s1, const char *s2)
+strpbrk (
+ const char *s1,
+ const char *s2
+ )
{
- UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
- UINT8 bit;
- int index;
+ UINT8 bitmap[(((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ UINT8 bit;
+ int index;
- BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+ BuildBitmap (bitmap, s2, sizeof (bitmap) / sizeof (UINT64));
- for( ; *s1 != '\0'; ++s1) {
- index = WHICH8(*s1);
- bit = WHICH_BIT(*s1);
- if( (bitmap[index] & bit) != 0) {
+ for ( ; *s1 != '\0'; ++s1) {
+ index = WHICH8 (*s1);
+ bit = WHICH_BIT (*s1);
+ if ((bitmap[index] & bit) != 0) {
return (char *)s1;
}
}
+
return NULL;
}
@@ -535,7 +627,9 @@ strpbrk(const char *s1, const char *s2) a subsequent call to the strerror function.
**/
char *
-strerror(int errnum)
+strerror (
+ int errnum
+ )
{
return errnum_message;
}
@@ -544,20 +638,24 @@ strerror(int errnum) Allocate and zero-initialize array.
**/
void *
-calloc(size_t Num, size_t Size)
+calloc (
+ size_t Num,
+ size_t Size
+ )
{
- void *RetVal;
- size_t NumSize;
+ void *RetVal;
+ size_t NumSize;
NumSize = Num * Size;
RetVal = NULL;
if (NumSize != 0) {
- RetVal = malloc(NumSize);
- if( RetVal != NULL) {
- (VOID)ZeroMem( RetVal, NumSize);
- }
+ RetVal = malloc (NumSize);
+ if ( RetVal != NULL) {
+ (VOID)ZeroMem (RetVal, NumSize);
+ }
}
- DEBUG((DEBUG_POOL, "0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
+
+ DEBUG ((DEBUG_POOL, "0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
return RetVal;
}
@@ -567,7 +665,7 @@ calloc(size_t Num, size_t Size) // month number used as the index (1 -> 12) for regular and leap years.
// The value at index 13 is for the whole year.
//
-UINTN CumulativeDays[2][14] = {
+UINTN CumulativeDays[2][14] = {
{
0,
0,
@@ -602,15 +700,18 @@ UINTN CumulativeDays[2][14] = { }
};
-#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-#define SECSPERMIN (60)
-#define SECSPERHOUR (60 * 60)
-#define SECSPERDAY (24 * SECSPERHOUR)
+#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define SECSPERMIN (60)
+#define SECSPERHOUR (60 * 60)
+#define SECSPERDAY (24 * SECSPERHOUR)
/**
Get the system time as seconds elapsed since midnight, January 1, 1970.
**/
-time_t time (time_t *timer)
+time_t
+time (
+ time_t *timer
+ )
{
EFI_TIME Time;
time_t CalTime;
@@ -626,7 +727,7 @@ time_t time (time_t *timer) // UTime should now be set to 00:00:00 on Jan 1 of the current year.
//
for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
- CalTime = CalTime + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);
+ CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
}
//
@@ -634,7 +735,7 @@ time_t time (time_t *timer) //
CalTime = CalTime +
(time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +
- (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) +
+ (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
(time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
(time_t)(Time.Hour * SECSPERHOUR) +
(time_t)(Time.Minute * 60) +
@@ -650,9 +751,14 @@ time_t time (time_t *timer) /**
Performs a quick sort
**/
-void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
+void
+qsort (
+ void *base,
+ size_t num,
+ size_t width,
+ int ( *compare )(const void *, const void *)
+ )
{
-
ASSERT (base != NULL);
ASSERT (compare != NULL);
@@ -666,54 +772,93 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c @return Returns the character currently pointed by the internal file position indicator of the specified stream
**/
-int fgetc(FILE * _File){
- return EOF;
+int
+fgetc (
+ FILE *_File
+ )
+{
+ return EOF;
}
+
/**
Open stream file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-FILE *fopen (const char *filename, const char *mode) {
+FILE *
+fopen (
+ const char *filename,
+ const char *mode
+ )
+{
return NULL;
}
+
/**
Read stream from file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {
+size_t
+fread (
+ void *ptr,
+ size_t size,
+ size_t count,
+ FILE *stream
+ )
+{
return 0;
}
+
/**
Write stream from file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-size_t fwrite (const void * ptr, size_t size, size_t count, FILE * stream) {
+size_t
+fwrite (
+ const void *ptr,
+ size_t size,
+ size_t count,
+ FILE *stream
+ )
+{
return 0;
}
+
/**
Close file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-int fclose (FILE * stream) {
+int
+fclose (
+ FILE *stream
+ )
+{
return EOF;
}
+
/**
Write the formatted string to file, we don't support file operastion on edk2 JSON library.
@return 0 Unsupported
**/
-int fprintf (FILE * stream, const char * format, ...) {
+int
+fprintf (
+ FILE *stream,
+ const char *format,
+ ...
+ )
+{
return -1;
}
+
/**
This function check if this is the formating string specifier.
@@ -730,12 +875,12 @@ int fprintf (FILE * stream, const char * format, ...) { **/
BOOLEAN
CheckFormatingString (
- IN CONST CHAR8 *FormatString,
- IN OUT UINTN *CurrentPosition,
- IN UINTN StrLength
+ IN CONST CHAR8 *FormatString,
+ IN OUT UINTN *CurrentPosition,
+ IN UINTN StrLength
)
{
- CHAR8 FormatStringParamater;
+ CHAR8 FormatStringParamater;
while (*(FormatString + *CurrentPosition) != 's') {
//
@@ -749,14 +894,17 @@ CheckFormatingString ( (FormatStringParamater != '*') &&
(FormatStringParamater != '.') &&
!(((UINTN)FormatStringParamater >= (UINTN)'0') && ((UINTN)FormatStringParamater <= (UINTN)'9'))
- ) {
+ )
+ {
return FALSE;
}
+
(*CurrentPosition)++;
if (*CurrentPosition >= StrLength) {
return FALSE;
}
- };
+ }
+
return TRUE;
}
@@ -772,15 +920,15 @@ CheckFormatingString ( **/
CHAR8 *
ReplaceUnicodeToAsciiStrFormat (
- IN CONST CHAR8 *FormatString
-)
+ IN CONST CHAR8 *FormatString
+ )
{
- UINTN FormatStrSize;
- UINTN FormatStrIndex;
- UINTN FormatStrSpecifier;
- BOOLEAN PercentageMark;
- CHAR8 *TempFormatBuffer;
- BOOLEAN IsFormatString;
+ UINTN FormatStrSize;
+ UINTN FormatStrIndex;
+ UINTN FormatStrSpecifier;
+ BOOLEAN PercentageMark;
+ CHAR8 *TempFormatBuffer;
+ BOOLEAN IsFormatString;
//
// Error checking.
@@ -788,15 +936,18 @@ ReplaceUnicodeToAsciiStrFormat ( if (FormatString == NULL) {
return NULL;
}
- FormatStrSize = AsciiStrSize(FormatString);
+
+ FormatStrSize = AsciiStrSize (FormatString);
if (FormatStrSize == 0) {
return NULL;
}
- TempFormatBuffer = AllocatePool(FormatStrSize); // Allocate memory for the
- // new string.
- if (TempFormatBuffer== NULL) {
+
+ TempFormatBuffer = AllocatePool (FormatStrSize); // Allocate memory for the
+ // new string.
+ if (TempFormatBuffer == NULL) {
return NULL;
}
+
//
// Clone *FormatString but replace "%s" wih "%a".
// "%%" is not considered as the format tag.
@@ -809,18 +960,21 @@ ReplaceUnicodeToAsciiStrFormat ( // Previous character is "%".
//
PercentageMark = FALSE;
- if (*(FormatString + FormatStrIndex) != '%') { // Check if this is double "%".
+ if (*(FormatString + FormatStrIndex) != '%') {
+ // Check if this is double "%".
FormatStrSpecifier = FormatStrIndex;
//
// Check if this is the formating string specifier.
//
IsFormatString = CheckFormatingString (FormatString, &FormatStrSpecifier, FormatStrSize);
if ((FormatStrSpecifier - FormatStrIndex) != 0) {
- CopyMem((VOID *)(TempFormatBuffer + FormatStrIndex),
- (VOID *)(FormatString + FormatStrIndex),
- FormatStrSpecifier - FormatStrIndex
- );
+ CopyMem (
+ (VOID *)(TempFormatBuffer + FormatStrIndex),
+ (VOID *)(FormatString + FormatStrIndex),
+ FormatStrSpecifier - FormatStrIndex
+ );
}
+
FormatStrIndex = FormatStrSpecifier;
if (IsFormatString == TRUE) {
//
@@ -828,18 +982,22 @@ ReplaceUnicodeToAsciiStrFormat ( // format on edk2 environment.
//
*(TempFormatBuffer + FormatStrSpecifier) = 'a';
- FormatStrIndex ++;
+ FormatStrIndex++;
}
+
continue;
}
+
goto ContinueCheck;
}
+
if (*(FormatString + FormatStrIndex) == '%') {
//
// This character is "%", set the flag.
//
PercentageMark = TRUE;
}
+
ContinueCheck:
//
// Clone character to the new string and advance FormatStrIndex
@@ -847,7 +1005,8 @@ ContinueCheck: //
*(TempFormatBuffer + FormatStrIndex) = *(FormatString + FormatStrIndex);
FormatStrIndex++;
- };
+ }
+
return TempFormatBuffer;
}
@@ -870,14 +1029,14 @@ ContinueCheck: UINTN
EFIAPI
RedfishAsciiVSPrint (
- OUT CHAR8 *StartOfBuffer,
- IN UINTN BufferSize,
- IN CONST CHAR8 *FormatString,
- IN VA_LIST Marker
+ OUT CHAR8 *StartOfBuffer,
+ IN UINTN BufferSize,
+ IN CONST CHAR8 *FormatString,
+ IN VA_LIST Marker
)
{
- CHAR8 *TempFormatBuffer;
- UINTN LenStrProduced;
+ CHAR8 *TempFormatBuffer;
+ UINTN LenStrProduced;
//
// Looking for "%s" in the format string and replace it
@@ -888,6 +1047,7 @@ RedfishAsciiVSPrint ( if (TempFormatBuffer == NULL) {
return 0;
}
+
LenStrProduced = AsciiVSPrint (StartOfBuffer, BufferSize, (CONST CHAR8 *)TempFormatBuffer, Marker);
FreePool (TempFormatBuffer);
return LenStrProduced;
@@ -919,11 +1079,10 @@ RedfishAsciiSPrint ( ...
)
{
- VA_LIST Marker;
- UINTN LenStrProduced;
+ VA_LIST Marker;
+ UINTN LenStrProduced;
- VA_START(Marker, FormatString);
+ VA_START (Marker, FormatString);
LenStrProduced = RedfishAsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
return LenStrProduced;
}
-
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c index 18aa4646e8..9f9d37790e 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c @@ -27,7 +27,7 @@ REDFISH_SERVICE
EFIAPI
RedfishCreateService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
)
{
REDFISH_SERVICE RedfishService;
@@ -69,7 +69,8 @@ ON_EXIT: if (UserId != NULL) {
FreePool (UserId);
}
- if (Password!= NULL) {
+
+ if (Password != NULL) {
FreePool (Password);
}
@@ -85,7 +86,7 @@ ON_EXIT: VOID
EFIAPI
RedfishCleanupService (
- IN REDFISH_SERVICE RedfishService
+ IN REDFISH_SERVICE RedfishService
)
{
if (RedfishService == NULL) {
@@ -94,6 +95,7 @@ RedfishCleanupService ( cleanupServiceEnumerator (RedfishService);
}
+
/**
Create REDFISH_PAYLOAD instance in local with JSON represented resource value and
the Redfish Service.
@@ -112,11 +114,11 @@ RedfishCleanupService ( REDFISH_PAYLOAD
EFIAPI
RedfishCreatePayload (
- IN EDKII_JSON_VALUE Value,
- IN REDFISH_SERVICE RedfishService
+ IN EDKII_JSON_VALUE Value,
+ IN REDFISH_SERVICE RedfishService
)
{
- EDKII_JSON_VALUE CopyValue;
+ EDKII_JSON_VALUE CopyValue;
CopyValue = JsonValueClone (Value);
return createRedfishPayload (CopyValue, RedfishService);
@@ -131,14 +133,14 @@ RedfishCreatePayload ( VOID
EFIAPI
RedfishCleanupPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
if (Payload == NULL) {
return;
}
- cleanupPayload ((redfishPayload *) Payload);
+ cleanupPayload ((redfishPayload *)Payload);
}
/**
@@ -155,14 +157,14 @@ RedfishCleanupPayload ( EDKII_JSON_VALUE
EFIAPI
RedfishJsonInPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
if (Payload == NULL) {
return NULL;
}
- return ((redfishPayload*)Payload)->json;
+ return ((redfishPayload *)Payload)->json;
}
/**
@@ -187,15 +189,15 @@ RedfishJsonInPayload ( CHAR8 *
EFIAPI
RedfishBuildPathWithSystemUuid (
- IN CONST CHAR8 *RedPath,
- IN BOOLEAN FromSmbios,
- IN CHAR8 *IdString OPTIONAL
+ IN CONST CHAR8 *RedPath,
+ IN BOOLEAN FromSmbios,
+ IN CHAR8 *IdString OPTIONAL
)
{
- UINTN BufSize;
- CHAR8* RetRedPath;
- EFI_GUID SystemUuid;
- EFI_STATUS Status;
+ UINTN BufSize;
+ CHAR8 *RetRedPath;
+ EFI_GUID SystemUuid;
+ EFI_STATUS Status;
if (RedPath == NULL) {
return NULL;
@@ -205,10 +207,11 @@ RedfishBuildPathWithSystemUuid ( // Find system UUID from SMBIOS table.
//
if (FromSmbios) {
- Status = NetLibGetSystemGuid(&SystemUuid);
+ Status = NetLibGetSystemGuid (&SystemUuid);
if (EFI_ERROR (Status)) {
return NULL;
}
+
// AsciiStrLen ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") = 36
BufSize = AsciiStrSize (RedPath) + AsciiStrLen ("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
} else {
@@ -219,13 +222,16 @@ RedfishBuildPathWithSystemUuid ( if (RetRedPath == NULL) {
return NULL;
}
+
if (FromSmbios) {
AsciiSPrint (RetRedPath, BufSize, RedPath, &SystemUuid);
} else {
AsciiSPrint (RetRedPath, BufSize, RedPath, IdString);
}
+
return RetRedPath;
}
+
/**
Get a redfish response addressed by a RedPath string, including HTTP StatusCode, Headers
and Payload which record any HTTP response messages.
@@ -252,24 +258,24 @@ RedfishBuildPathWithSystemUuid ( EFI_STATUS
EFIAPI
RedfishGetByService (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (RedfishService == NULL || RedPath == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) getPayloadByPath (RedfishService, RedPath, &(RedResponse->StatusCode));
+ RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadByPath (RedfishService, RedPath, &(RedResponse->StatusCode));
//
// 1. If the returned Payload is NULL, indicates any error happen.
// 2. If the returned StatusCode is NULL, indicates any error happen.
//
- if (RedResponse->Payload == NULL || RedResponse->StatusCode == NULL) {
+ if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
return EFI_DEVICE_ERROR;
}
@@ -278,13 +284,15 @@ RedfishGetByService ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Get a redfish response addressed by URI, including HTTP StatusCode, Headers
and Payload which record any HTTP response messages.
@@ -310,27 +318,27 @@ RedfishGetByService ( EFI_STATUS
EFIAPI
RedfishGetByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EDKII_JSON_VALUE JsonValue;
+ EDKII_JSON_VALUE JsonValue;
- if (RedfishService == NULL || Uri == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = getUriFromService (RedfishService, Uri, &RedResponse->StatusCode);
- RedResponse->Payload = createRedfishPayload(JsonValue, RedfishService);
+ JsonValue = getUriFromService (RedfishService, Uri, &RedResponse->StatusCode);
+ RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
//
// 1. If the returned Payload is NULL, indicates any error happen.
// 2. If the returned StatusCode is NULL, indicates any error happen.
//
- if (RedResponse->Payload == NULL || RedResponse->StatusCode == NULL) {
+ if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
return EFI_DEVICE_ERROR;
}
@@ -339,12 +347,15 @@ RedfishGetByUri ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
+
return EFI_SUCCESS;
}
+
/**
Get a redfish response addressed by the input Payload and relative RedPath string,
including HTTP StatusCode, Headers and Payload which record any HTTP response messages.
@@ -374,18 +385,18 @@ RedfishGetByUri ( EFI_STATUS
EFIAPI
RedfishGetByPayload (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *RedPath,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *RedPath,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Payload == NULL || RedPath == NULL || RedResponse == NULL) {
+ if ((Payload == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) getPayloadForPathString (Payload, RedPath, &(RedResponse->StatusCode));
+ RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadForPathString (Payload, RedPath, &(RedResponse->StatusCode));
//
// 1. If the returned Payload is NULL, indicates any error happen.
@@ -400,15 +411,17 @@ RedfishGetByPayload ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (RedResponse->StatusCode != NULL && \
- (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT
- )) {
+ if ((RedResponse->StatusCode != NULL) && \
+ ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)
+ ))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP PATCH to perform updates on pre-existing Redfish resource.
@@ -442,30 +455,30 @@ RedfishGetByPayload ( EFI_STATUS
EFIAPI
RedfishPatchToUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- IN CONST CHAR8 *Content,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ IN CONST CHAR8 *Content,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EFI_STATUS Status;
- EDKII_JSON_VALUE JsonValue;
+ EFI_STATUS Status;
+ EDKII_JSON_VALUE JsonValue;
Status = EFI_SUCCESS;
JsonValue = NULL;
- if (RedfishService == NULL || Uri == NULL || Content == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = (EDKII_JSON_VALUE) patchUriFromService (
- RedfishService,
- Uri,
- Content,
- &(RedResponse->StatusCode)
- );
+ JsonValue = (EDKII_JSON_VALUE)patchUriFromService (
+ RedfishService,
+ Uri,
+ Content,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -480,8 +493,9 @@ RedfishPatchToUri ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
Status = EFI_DEVICE_ERROR;
}
@@ -499,6 +513,7 @@ ON_EXIT: return Status;
}
+
/**
Use HTTP PATCH to perform updates on target payload. Patch to odata.id in Payload directly.
@@ -530,22 +545,22 @@ ON_EXIT: EFI_STATUS
EFIAPI
RedfishPatchToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Target == NULL || Payload == NULL || RedResponse == NULL) {
+ if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) patchPayload (
- Target,
- Payload,
- &(RedResponse->StatusCode)
- );
+ RedResponse->Payload = (REDFISH_PAYLOAD)patchPayload (
+ Target,
+ Payload,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -559,13 +574,15 @@ RedfishPatchToPayload ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP POST to create a new resource in target payload.
@@ -596,22 +613,22 @@ RedfishPatchToPayload ( EFI_STATUS
EFIAPI
RedfishPostToPayload (
- IN REDFISH_PAYLOAD Target,
- IN REDFISH_PAYLOAD Payload,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_PAYLOAD Target,
+ IN REDFISH_PAYLOAD Payload,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- if (Target == NULL || Payload == NULL || RedResponse == NULL) {
+ if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- RedResponse->Payload = (REDFISH_PAYLOAD) postPayload (
- Target,
- Payload,
- &(RedResponse->StatusCode)
- );
+ RedResponse->Payload = (REDFISH_PAYLOAD)postPayload (
+ Target,
+ Payload,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -625,13 +642,15 @@ RedfishPostToPayload ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
+
/**
Use HTTP DELETE to remove a resource.
@@ -662,28 +681,28 @@ RedfishPostToPayload ( EFI_STATUS
EFIAPI
RedfishDeleteByUri (
- IN REDFISH_SERVICE RedfishService,
- IN CONST CHAR8 *Uri,
- OUT REDFISH_RESPONSE *RedResponse
+ IN REDFISH_SERVICE RedfishService,
+ IN CONST CHAR8 *Uri,
+ OUT REDFISH_RESPONSE *RedResponse
)
{
- EFI_STATUS Status;
- EDKII_JSON_VALUE JsonValue;
+ EFI_STATUS Status;
+ EDKII_JSON_VALUE JsonValue;
Status = EFI_SUCCESS;
JsonValue = NULL;
- if (RedfishService == NULL || Uri == NULL || RedResponse == NULL) {
+ if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
- JsonValue = (EDKII_JSON_VALUE) deleteUriFromService (
- RedfishService,
- Uri,
- &(RedResponse->StatusCode)
- );
+ JsonValue = (EDKII_JSON_VALUE)deleteUriFromService (
+ RedfishService,
+ Uri,
+ &(RedResponse->StatusCode)
+ );
//
// 1. If the returned StatusCode is NULL, indicates any error happen.
@@ -698,8 +717,9 @@ RedfishDeleteByUri ( // NOTE: If there is any error message returned from server, it will be returned in
// Payload within RedResponse.
//
- if (*(RedResponse->StatusCode) < HTTP_STATUS_200_OK || \
- *(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT) {
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
+ {
Status = EFI_DEVICE_ERROR;
}
@@ -717,6 +737,7 @@ ON_EXIT: return Status;
}
+
/**
Dump text in fractions.
@@ -725,37 +746,40 @@ ON_EXIT: **/
VOID
RedfishDumpJsonStringFractions (
- IN CHAR8 *String
+ IN CHAR8 *String
)
{
- CHAR8 *NextFraction;
- UINTN StringFractionSize;
- UINTN StrLen;
- UINTN Count;
- CHAR8 BackupChar;
+ CHAR8 *NextFraction;
+ UINTN StringFractionSize;
+ UINTN StrLen;
+ UINTN Count;
+ CHAR8 BackupChar;
StringFractionSize = 200;
if (String == NULL) {
- return ;
+ return;
}
- DEBUG((DEBUG_INFO, "JSON text:\n"));
+ DEBUG ((DEBUG_INFO, "JSON text:\n"));
NextFraction = String;
- StrLen = AsciiStrLen (String);
+ StrLen = AsciiStrLen (String);
if (StrLen == 0) {
return;
}
+
for (Count = 0; Count < (StrLen / StringFractionSize); Count++) {
- BackupChar = *(NextFraction + StringFractionSize);
+ BackupChar = *(NextFraction + StringFractionSize);
*(NextFraction + StringFractionSize) = 0;
- DEBUG((DEBUG_INFO, "%a", NextFraction));
+ DEBUG ((DEBUG_INFO, "%a", NextFraction));
*(NextFraction + StringFractionSize) = BackupChar;
- NextFraction += StringFractionSize;
+ NextFraction += StringFractionSize;
}
+
if ((StrLen % StringFractionSize) != 0) {
- DEBUG((DEBUG_INFO, "%a\n\n", NextFraction));
+ DEBUG ((DEBUG_INFO, "%a\n\n", NextFraction));
}
}
+
/**
Dump text in JSON value.
@@ -767,15 +791,17 @@ RedfishDumpJson ( IN EDKII_JSON_VALUE JsonValue
)
{
- CHAR8 *String;
+ CHAR8 *String;
String = JsonDumpString (JsonValue, 0);
if (String == NULL) {
return;
}
+
RedfishDumpJsonStringFractions (String);
- FreePool(String);
+ FreePool (String);
}
+
/**
Extract the JSON text content from REDFISH_PAYLOAD and dump to debug console.
@@ -784,14 +810,14 @@ RedfishDumpJson ( **/
VOID
RedfishDumpPayload (
- IN REDFISH_PAYLOAD Payload
+ IN REDFISH_PAYLOAD Payload
)
{
- EDKII_JSON_VALUE JsonValue;
- CHAR8 *String;
+ EDKII_JSON_VALUE JsonValue;
+ CHAR8 *String;
JsonValue = NULL;
- String = NULL;
+ String = NULL;
if (Payload == NULL) {
return;
@@ -808,8 +834,9 @@ RedfishDumpPayload ( }
RedfishDumpJsonStringFractions (String);
- FreePool(String);
+ FreePool (String);
}
+
/**
This function will cleanup the HTTP header and Redfish payload resources.
@@ -832,8 +859,8 @@ RedfishFreeResponse ( StatusCode = NULL;
}
- if (HeaderCount != 0 && Headers != NULL) {
- HttpFreeHeaderFields(Headers, HeaderCount);
+ if ((HeaderCount != 0) && (Headers != NULL)) {
+ HttpFreeHeaderFields (Headers, HeaderCount);
Headers = NULL;
}
@@ -842,6 +869,7 @@ RedfishFreeResponse ( Payload = NULL;
}
}
+
/**
Check if the "@odata.type" in Payload is valid or not.
@@ -855,17 +883,17 @@ RedfishFreeResponse ( **/
BOOLEAN
RedfishIsValidOdataType (
- IN REDFISH_PAYLOAD Payload,
- IN CONST CHAR8 *OdataTypeName,
- IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
- IN UINTN OdataTypeMappingListSize
+ IN REDFISH_PAYLOAD Payload,
+ IN CONST CHAR8 *OdataTypeName,
+ IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
+ IN UINTN OdataTypeMappingListSize
)
{
- UINTN Index;
- EDKII_JSON_VALUE OdataType;
- EDKII_JSON_VALUE JsonValue;
+ UINTN Index;
+ EDKII_JSON_VALUE OdataType;
+ EDKII_JSON_VALUE JsonValue;
- if (Payload == NULL || OdataTypeName == NULL) {
+ if ((Payload == NULL) || (OdataTypeName == NULL)) {
return FALSE;
}
@@ -875,19 +903,22 @@ RedfishIsValidOdataType ( }
OdataType = JsonObjectGetValue (JsonValueGetObject (JsonValue), "@odata.type");
- if (!JsonValueIsString (OdataType) || JsonValueGetAsciiString (OdataType) == NULL) {
+ if (!JsonValueIsString (OdataType) || (JsonValueGetAsciiString (OdataType) == NULL)) {
return FALSE;
}
- for (Index = 0; Index < OdataTypeMappingListSize; Index ++) {
- if (AsciiStrCmp (OdataTypeMappingList[Index].OdataTypeName, OdataTypeName) == 0 &&
- AsciiStrCmp (OdataTypeMappingList[Index].OdataType, JsonValueGetAsciiString (OdataType)) == 0) {
+ for (Index = 0; Index < OdataTypeMappingListSize; Index++) {
+ if ((AsciiStrCmp (OdataTypeMappingList[Index].OdataTypeName, OdataTypeName) == 0) &&
+ (AsciiStrCmp (OdataTypeMappingList[Index].OdataType, JsonValueGetAsciiString (OdataType)) == 0))
+ {
return TRUE;
}
}
+
DEBUG ((DEBUG_INFO, "%a: This Odata type is not in the list.\n", __FUNCTION__));
return FALSE;
}
+
/**
Check if the payload is collection
@@ -898,11 +929,12 @@ RedfishIsValidOdataType ( **/
BOOLEAN
RedfishIsPayloadCollection (
- IN REDFISH_PAYLOAD Payload
-)
+ IN REDFISH_PAYLOAD Payload
+ )
{
return isPayloadCollection (Payload);
}
+
/**
Get collection size.
@@ -913,21 +945,23 @@ RedfishIsPayloadCollection ( @return EFI_INVALID_PARAMETER The payload is not a collection.
**/
EFI_STATUS
-RedfishGetCollectionSize(
- IN REDFISH_PAYLOAD Payload,
- IN UINTN *CollectionSize
+RedfishGetCollectionSize (
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN *CollectionSize
)
{
- if (Payload == NULL || CollectionSize == NULL) {
+ if ((Payload == NULL) || (CollectionSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
- if (!RedfishIsPayloadCollection(Payload)) {
+
+ if (!RedfishIsPayloadCollection (Payload)) {
return EFI_INVALID_PARAMETER;
}
- *CollectionSize = (UINTN)getCollectionSize(Payload);
+ *CollectionSize = (UINTN)getCollectionSize (Payload);
return EFI_SUCCESS;
}
+
/**
Get Redfish payload of collection member
@@ -939,20 +973,23 @@ RedfishGetCollectionSize( **/
REDFISH_PAYLOAD
RedfishGetPayloadByIndex (
- IN REDFISH_PAYLOAD Payload,
- IN UINTN Index
-)
+ IN REDFISH_PAYLOAD Payload,
+ IN UINTN Index
+ )
{
- REDFISH_RESPONSE RedfishResponse;
- REDFISH_PAYLOAD PayloadReturn;
+ REDFISH_RESPONSE RedfishResponse;
+ REDFISH_PAYLOAD PayloadReturn;
PayloadReturn = (VOID *)getPayloadByIndex (Payload, Index, &RedfishResponse.StatusCode);
- if(PayloadReturn == NULL ||
- (*(RedfishResponse.StatusCode) < HTTP_STATUS_200_OK && *(RedfishResponse.StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)){
+ if ((PayloadReturn == NULL) ||
+ ((*(RedfishResponse.StatusCode) < HTTP_STATUS_200_OK) && (*(RedfishResponse.StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)))
+ {
return NULL;
}
+
return PayloadReturn;
}
+
/**
Check and return Redfish resource of the given Redpath.
@@ -964,30 +1001,33 @@ RedfishGetPayloadByIndex ( **/
EFI_STATUS
RedfishCheckIfRedpathExist (
- IN REDFISH_SERVICE RedfishService,
- IN CHAR8 *Redpath,
- IN REDFISH_RESPONSE *Response OPTIONAL
+ IN REDFISH_SERVICE RedfishService,
+ IN CHAR8 *Redpath,
+ IN REDFISH_RESPONSE *Response OPTIONAL
)
{
- EFI_STATUS Status;
- REDFISH_RESPONSE TempResponse;
+ EFI_STATUS Status;
+ REDFISH_RESPONSE TempResponse;
if (Redpath == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Status = RedfishGetByService (RedfishService, Redpath, &TempResponse);
if (EFI_ERROR (Status)) {
return Status;
}
+
if (Response == NULL) {
- RedfishFreeResponse(
+ RedfishFreeResponse (
TempResponse.StatusCode,
TempResponse.HeaderCount,
TempResponse.Headers,
TempResponse.Payload
- );
+ );
} else {
CopyMem ((VOID *)Response, (VOID *)&TempResponse, sizeof (REDFISH_RESPONSE));
}
+
return EFI_SUCCESS;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c index 7077c37154..0eb23196d2 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c @@ -10,7 +10,7 @@ #include "RedfishMisc.h"
-EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
+EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
/**
This function returns the string of Redfish service version.
@@ -23,25 +23,28 @@ EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL; **/
EFI_STATUS
RedfishGetServiceVersion (
- IN REDFISH_SERVICE RedfishService,
- OUT CHAR8 **ServiceVersionStr
+ IN REDFISH_SERVICE RedfishService,
+ OUT CHAR8 **ServiceVersionStr
)
{
- redfishService *Redfish;
- CHAR8 **KeysArray;
- UINTN KeysNum;
+ redfishService *Redfish;
+ CHAR8 **KeysArray;
+ UINTN KeysNum;
- if (RedfishService == NULL || ServiceVersionStr == NULL) {
+ if ((RedfishService == NULL) || (ServiceVersionStr == NULL)) {
return EFI_INVALID_PARAMETER;
}
+
Redfish = (redfishService *)RedfishService;
if (Redfish->versions == NULL) {
return EFI_INVALID_PARAMETER;
}
+
KeysArray = JsonObjectGetKeys (Redfish->versions, &KeysNum);
- if (KeysNum == 0 || KeysArray == NULL) {
+ if ((KeysNum == 0) || (KeysArray == NULL)) {
return EFI_NOT_FOUND;
}
+
*ServiceVersionStr = *KeysArray;
return EFI_SUCCESS;
}
@@ -65,18 +68,17 @@ RedfishGetServiceVersion ( **/
REDFISH_SERVICE
RedfishCreateLibredfishService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
- IN CHAR8 *UserId,
- IN CHAR8 *Password
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
+ IN CHAR8 *UserId,
+ IN CHAR8 *Password
)
{
+ UINTN Flags;
+ enumeratorAuthentication Auth;
+ redfishService *Redfish;
- UINTN Flags;
- enumeratorAuthentication Auth;
- redfishService* Redfish;
-
- Redfish = NULL;
+ Redfish = NULL;
ZeroMem (&Auth, sizeof (Auth));
if (AuthMethod == AuthMethodHttpBasic) {
@@ -84,25 +86,26 @@ RedfishCreateLibredfishService ( } else if (AuthMethod == AuthMethodRedfishSession) {
Auth.authType = REDFISH_AUTH_SESSION;
}
+
Auth.authCodes.userPass.username = UserId;
Auth.authCodes.userPass.password = Password;
Flags = REDFISH_FLAG_SERVICE_NO_VERSION_DOC;
if (AuthMethod != AuthMethodNone) {
- Redfish = createServiceEnumerator(RedfishConfigServiceInfo, NULL, &Auth, (unsigned int ) Flags);
+ Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, &Auth, (unsigned int)Flags);
} else {
- Redfish = createServiceEnumerator(RedfishConfigServiceInfo, NULL, NULL, (unsigned int) Flags);
+ Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, NULL, (unsigned int)Flags);
}
//
// Zero the Password after use.
//
if (Password != NULL) {
- ZeroMem (Password, AsciiStrLen(Password));
+ ZeroMem (Password, AsciiStrLen (Password));
}
- return (REDFISH_SERVICE) Redfish;
+ return (REDFISH_SERVICE)Redfish;
}
/**
@@ -130,14 +133,14 @@ RedfishCreateLibredfishService ( **/
EFI_STATUS
RedfishGetAuthInfo (
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ OUT CHAR8 **Password
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- if (AuthMethod == NULL || UserId == NULL || Password == NULL) {
+ if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -161,6 +164,7 @@ RedfishGetAuthInfo ( return Status;
}
+
/**
This function returns the string of Redfish service version.
@@ -175,15 +179,15 @@ RedfishGetAuthInfo ( **/
EFI_STATUS
RedfishBuildRedpathUseId (
- IN CHAR8 *ServiceVerisonStr,
- IN CHAR8 *Url,
- IN CHAR8 *Id,
- OUT CHAR8 **Redpath
+ IN CHAR8 *ServiceVerisonStr,
+ IN CHAR8 *Url,
+ IN CHAR8 *Id,
+ OUT CHAR8 **Redpath
)
{
- UINTN RedpathSize;
+ UINTN RedpathSize;
- if (Redpath == NULL || ServiceVerisonStr == NULL || Url == NULL || Id == NULL) {
+ if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -192,10 +196,11 @@ RedfishBuildRedpathUseId ( AsciiStrLen (Url) +
AsciiStrLen ("[Id=]") +
AsciiStrLen (Id) + 1;
- *Redpath = AllocatePool(RedpathSize);
+ *Redpath = AllocatePool (RedpathSize);
if (*Redpath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url, Id);
return EFI_SUCCESS;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h index d01a433d1a..3b066c1172 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.h @@ -22,7 +22,7 @@ #include <Protocol/EdkIIRedfishCredential.h>
#include <redfish.h>
-#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
+#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
/**
Creates a REDFISH_SERVICE which can be later used to access the Redfish resources.
@@ -43,10 +43,10 @@ **/
REDFISH_SERVICE
RedfishCreateLibredfishService (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
- IN CHAR8 *UserId,
- IN CHAR8 *Password
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
+ IN CHAR8 *UserId,
+ IN CHAR8 *Password
);
/**
@@ -74,9 +74,9 @@ RedfishCreateLibredfishService ( **/
EFI_STATUS
RedfishGetAuthInfo (
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ OUT CHAR8 **Password
);
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h index de1feb22fb..e9b9b3fa55 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfish.h @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDFISH_H_
#define LIBREDFISH_REDFISH_H_
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h index 43149f3c89..445153060a 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDFISH_PAYLOAD_H_
#define LIBREDFISH_REDFISH_PAYLOAD_H_
@@ -23,17 +24,83 @@ #include <redfishService.h>
#include <redpath.h>
-redfishPayload* createRedfishPayload(json_t* value, redfishService* service);
-redfishPayload* getPayloadByNodeName(redfishPayload* payload, const char* nodeName, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadByIndex(redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadForPath(redfishPayload* payload, redPathNode* redpath, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadForPathString(redfishPayload* payload, const char* string, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* patchPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* postContentToPayload(redfishPayload* target, const char* data, size_t dataSize, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
-void cleanupPayload(redfishPayload* payload);
-bool isPayloadCollection (redfishPayload *Payload);
-size_t getCollectionSize(redfishPayload* payload);
-redfishPayload* getPayloadByIndex (redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
+redfishPayload *
+createRedfishPayload (
+ json_t *value,
+ redfishService *service
+ );
+
+redfishPayload *
+getPayloadByNodeName (
+ redfishPayload *payload,
+ const char *nodeName,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadForPath (
+ redfishPayload *payload,
+ redPathNode *redpath,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadForPathString (
+ redfishPayload *payload,
+ const char *string,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+patchPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+postContentToPayload (
+ redfishPayload *target,
+ const char *data,
+ size_t dataSize,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+postPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+void
+cleanupPayload (
+ redfishPayload *payload
+ );
+
+bool
+isPayloadCollection (
+ redfishPayload *Payload
+ );
+
+size_t
+getCollectionSize (
+ redfishPayload *payload
+ );
+
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h index 0215caccfc..5c13b682a3 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h @@ -38,64 +38,114 @@ #include <jansson.h>
typedef struct {
- char* host;
- json_t* versions;
- unsigned int flags;
- char* sessionToken;
- char* basicAuthStr;
- //
- // point to the <HOST> part in above "host" field, which will be put into
- // the "Host" header of HTTP request message.
- //
- char* HostHeaderValue;
- EFI_REST_EX_PROTOCOL *RestEx;
+ char *host;
+ json_t *versions;
+ unsigned int flags;
+ char *sessionToken;
+ char *basicAuthStr;
+ //
+ // point to the <HOST> part in above "host" field, which will be put into
+ // the "Host" header of HTTP request message.
+ //
+ char *HostHeaderValue;
+ EFI_REST_EX_PROTOCOL *RestEx;
} redfishService;
typedef struct {
- json_t* json;
- redfishService* service;
+ json_t *json;
+ redfishService *service;
} redfishPayload;
-#define REDFISH_AUTH_BASIC 0
-#define REDFISH_AUTH_BEARER_TOKEN 1
-#define REDFISH_AUTH_SESSION 2
+#define REDFISH_AUTH_BASIC 0
+#define REDFISH_AUTH_BEARER_TOKEN 1
+#define REDFISH_AUTH_SESSION 2
-#define REDFISH_HTTP_RESPONSE_TIMEOUT 5000 /// 5 seconds in uints of millisecond.
+#define REDFISH_HTTP_RESPONSE_TIMEOUT 5000 /// 5 seconds in uints of millisecond.
///
/// Library class public defines
///
-#define HTTP_FLAG L"http://"
-#define HTTPS_FLAG L"https://"
+#define HTTP_FLAG L"http://"
+#define HTTPS_FLAG L"https://"
///
/// The redfish first URL should be "/redfish/v1/", while we use "/redfish/v1" here without "/"
/// in the end is to avoid the 301 Perment redirect response from Redfish profile simulator.
///
-#define REDFISH_FIRST_URL L"/redfish/v1"
+#define REDFISH_FIRST_URL L"/redfish/v1"
typedef struct {
- unsigned int authType;
- union {
- struct {
- char* username;
- char* password;
- } userPass;
- struct {
- char* token;
- } authToken;
- } authCodes;
+ unsigned int authType;
+ union {
+ struct {
+ char *username;
+ char *password;
+ } userPass;
+ struct {
+ char *token;
+ } authToken;
+ } authCodes;
} enumeratorAuthentication;
-//Values for flags
-#define REDFISH_FLAG_SERVICE_NO_VERSION_DOC 0x00000001 //The Redfish Service lacks the version document (in violation of the Redfish spec)
-redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, const char* rootUri, enumeratorAuthentication* auth, unsigned int flags);
-json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* patchUriFromService(redfishService* service, const char* uri, const char* content, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* postUriFromService(redfishService* service, const char* uri, const char* content, size_t contentLength, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
-json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getRedfishServiceRoot(redfishService* service, const char* version, EFI_HTTP_STATUS_CODE** StatusCode);
-redfishPayload* getPayloadByPath(redfishService* service, const char* path, EFI_HTTP_STATUS_CODE** StatusCode);
-void cleanupServiceEnumerator(redfishService* service);
+// Values for flags
+#define REDFISH_FLAG_SERVICE_NO_VERSION_DOC 0x00000001// The Redfish Service lacks the version document (in violation of the Redfish spec)
+redfishService *
+createServiceEnumerator (
+ REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ const char *rootUri,
+ enumeratorAuthentication *auth,
+ unsigned int flags
+ );
+
+json_t *
+getUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+patchUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+postUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ size_t contentLength,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+json_t *
+deleteUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getRedfishServiceRoot (
+ redfishService *service,
+ const char *version,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+redfishPayload *
+getPayloadByPath (
+ redfishService *service,
+ const char *path,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+void
+cleanupServiceEnumerator (
+ redfishService *service
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h index 24413a648a..c1a1568bf0 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef LIBREDFISH_REDPATH_H_
#define LIBREDFISH_REDPATH_H_
@@ -21,22 +22,28 @@ #include <jansson.h>
-typedef struct _redPathNode
-{
- bool isRoot;
- bool isIndex;
+typedef struct _redPathNode {
+ bool isRoot;
+ bool isIndex;
- char* version;
- char* nodeName;
- size_t index;
- char* op;
- char* propName;
- char* value;
+ char *version;
+ char *nodeName;
+ size_t index;
+ char *op;
+ char *propName;
+ char *value;
- struct _redPathNode* next;
+ struct _redPathNode *next;
} redPathNode;
-redPathNode* parseRedPath(const char* path);
-void cleanupRedPath(redPathNode* node);
+redPathNode *
+parseRedPath (
+ const char *path
+ );
+
+void
+cleanupRedPath (
+ redPathNode *node
+ );
#endif
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c index 3d60acd926..3f2b83e834 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c @@ -16,717 +16,797 @@ **/
#include <redfishPayload.h>
-static redfishPayload* getOpResult(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* collectionEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* arrayEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode);
-static redfishPayload* createCollection(redfishService* service, size_t count, redfishPayload** payloads);
-static json_t* json_object_get_by_index(json_t* json, size_t index);
-
-bool isPayloadCollection(redfishPayload* payload)
+static redfishPayload *
+getOpResult (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+collectionEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+arrayEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ );
+
+static redfishPayload *
+createCollection (
+ redfishService *service,
+ size_t count,
+ redfishPayload **payloads
+ );
+
+static json_t *
+json_object_get_by_index (
+ json_t *json,
+ size_t index
+ );
+
+bool
+isPayloadCollection (
+ redfishPayload *payload
+ )
{
- json_t* members;
- json_t* count;
+ json_t *members;
+ json_t *count;
- if(!payload || !json_is_object(payload->json))
- {
- return false;
- }
- members = json_object_get(payload->json, "Members");
- count = json_object_get(payload->json, "Members@odata.count");
- return ((members != NULL) && (count != NULL));
+ if (!payload || !json_is_object (payload->json)) {
+ return false;
+ }
+
+ members = json_object_get (payload->json, "Members");
+ count = json_object_get (payload->json, "Members@odata.count");
+ return ((members != NULL) && (count != NULL));
}
-size_t getCollectionSize(redfishPayload* payload)
+size_t
+getCollectionSize (
+ redfishPayload *payload
+ )
{
- json_t* members;
- json_t* count;
+ json_t *members;
+ json_t *count;
- if(!payload || !json_is_object(payload->json))
- {
- return 0;
- }
- members = json_object_get(payload->json, "Members");
- count = json_object_get(payload->json, "Members@odata.count");
- if(!members || !count)
- {
- return 0;
- }
- return (size_t)json_integer_value(count);
+ if (!payload || !json_is_object (payload->json)) {
+ return 0;
+ }
+
+ members = json_object_get (payload->json, "Members");
+ count = json_object_get (payload->json, "Members@odata.count");
+ if (!members || !count) {
+ return 0;
+ }
+
+ return (size_t)json_integer_value (count);
}
-bool isPayloadArray(redfishPayload* payload)
+bool
+isPayloadArray (
+ redfishPayload *payload
+ )
{
- if(!payload || !json_is_array(payload->json))
- {
- return false;
- }
- return true;
+ if (!payload || !json_is_array (payload->json)) {
+ return false;
+ }
+
+ return true;
}
-char* payloadToString(redfishPayload* payload, bool prettyPrint)
+char *
+payloadToString (
+ redfishPayload *payload,
+ bool prettyPrint
+ )
{
- size_t flags = 0;
- if(!payload)
- {
- return NULL;
- }
- if(prettyPrint)
- {
- flags = JSON_INDENT(2);
- }
- return json_dumps(payload->json, flags);
+ size_t flags = 0;
+
+ if (!payload) {
+ return NULL;
+ }
+
+ if (prettyPrint) {
+ flags = JSON_INDENT (2);
+ }
+
+ return json_dumps (payload->json, flags);
}
-redfishPayload* createRedfishPayload(json_t* value, redfishService* service)
+redfishPayload *
+createRedfishPayload (
+ json_t *value,
+ redfishService *service
+ )
{
- redfishPayload* payload;
- payload = (redfishPayload*)malloc(sizeof(redfishPayload));
- if(payload != NULL)
- {
- payload->json = value;
- payload->service = service;
- }
- return payload;
+ redfishPayload *payload;
+
+ payload = (redfishPayload *)malloc (sizeof (redfishPayload));
+ if (payload != NULL) {
+ payload->json = value;
+ payload->service = service;
+ }
+
+ return payload;
}
-redfishPayload* getPayloadByNodeName(redfishPayload* payload, const char* nodeName, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByNodeName (
+ redfishPayload *payload,
+ const char *nodeName,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value;
- json_t* odataId;
- const char* uri;
+ json_t *value;
+ json_t *odataId;
+ const char *uri;
- if(!payload || !nodeName || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!payload || !nodeName || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- value = json_object_get(payload->json, nodeName);
- if(value == NULL)
- {
+ value = json_object_get (payload->json, nodeName);
+ if (value == NULL) {
+ return NULL;
+ }
+
+ json_incref (value);
+ if (json_object_size (value) == 1) {
+ odataId = json_object_get (value, "@odata.id");
+ if (odataId != NULL) {
+ json_incref (odataId);
+ uri = json_string_value (odataId);
+ json_decref (value);
+ value = getUriFromService (payload->service, uri, StatusCode);
+ json_decref (odataId);
+ if ((value == NULL) || (*StatusCode == NULL)) {
return NULL;
- }
- json_incref(value);
- if(json_object_size(value) == 1)
- {
- odataId = json_object_get(value, "@odata.id");
- if(odataId != NULL)
- {
- json_incref(odataId);
- uri = json_string_value(odataId);
- json_decref(value);
- value = getUriFromService(payload->service, uri, StatusCode);
- json_decref(odataId);
- if(value == NULL || *StatusCode == NULL)
- {
- return NULL;
- }
- }
- }
- if (*StatusCode == NULL || (**StatusCode >= HTTP_STATUS_200_OK && **StatusCode <= HTTP_STATUS_206_PARTIAL_CONTENT)) {
- if(json_is_string(value))
- {
- odataId = json_object();
- json_object_set(odataId, nodeName, value);
- json_decref(value);
- value = odataId;
}
}
+ }
+
+ if ((*StatusCode == NULL) || ((**StatusCode >= HTTP_STATUS_200_OK) && (**StatusCode <= HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ if (json_is_string (value)) {
+ odataId = json_object ();
+ json_object_set (odataId, nodeName, value);
+ json_decref (value);
+ value = odataId;
+ }
+ }
- return createRedfishPayload(value, payload->service);
+ return createRedfishPayload (value, payload->service);
}
-redfishPayload* getPayloadByIndex(redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByIndex (
+ redfishPayload *payload,
+ size_t index,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value = NULL;
- json_t* odataId;
- const char* uri;
- BOOLEAN FromServerFlag = FALSE;
+ json_t *value = NULL;
+ json_t *odataId;
+ const char *uri;
+ BOOLEAN FromServerFlag = FALSE;
- if(!payload || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!payload || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- if(isPayloadCollection(payload))
+ if (isPayloadCollection (payload)) {
+ redfishPayload *members = getPayloadByNodeName (payload, "Members", StatusCode);
+ if (((*StatusCode == NULL) && (members == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- redfishPayload* members = getPayloadByNodeName(payload, "Members", StatusCode);
- if ((*StatusCode == NULL && members == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return members;
- }
+ return members;
+ }
- if (*StatusCode != NULL) {
- //
- // The Payload (members) are retrived from server.
- //
- FreePool (*StatusCode);
- *StatusCode = NULL;
- FromServerFlag = TRUE;
- }
+ if (*StatusCode != NULL) {
+ //
+ // The Payload (members) are retrived from server.
+ //
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ FromServerFlag = TRUE;
+ }
+
+ redfishPayload *ret = getPayloadByIndex (members, index, StatusCode);
+ if ((*StatusCode == NULL) && (ret != NULL) && FromServerFlag) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (members) directly.
+ // Since the members are retrived from server, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ ret = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
+ }
+ }
- redfishPayload* ret = getPayloadByIndex(members, index, StatusCode);
- if (*StatusCode == NULL && ret != NULL && FromServerFlag) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (members) directly.
- // Since the members are retrived from server, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- ret = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
- }
+ cleanupPayload (members);
+ return ret;
+ }
- cleanupPayload(members);
- return ret;
- }
+ if (json_is_array (payload->json)) {
+ //
+ // The valid range for index is from 0 to the return value of json_array_size() minus 1
+ //
+ value = json_array_get (payload->json, index);
+ } else if (json_is_object (payload->json)) {
+ value = json_object_get_by_index (payload->json, index);
+ }
- if(json_is_array(payload->json))
- {
- //
- // The valid range for index is from 0 to the return value of json_array_size() minus 1
- //
- value = json_array_get(payload->json, index);
- }
- else if(json_is_object(payload->json))
- {
- value = json_object_get_by_index(payload->json, index);
- }
+ if (value == NULL) {
+ return NULL;
+ }
- if(value == NULL)
- {
+ json_incref (value);
+ if (json_object_size (value) == 1) {
+ odataId = json_object_get (value, "@odata.id");
+ if (odataId != NULL) {
+ uri = json_string_value (odataId);
+ json_decref (value);
+ value = getUriFromService (payload->service, uri, StatusCode);
+ if (value == NULL) {
return NULL;
+ }
}
+ }
- json_incref(value);
- if(json_object_size(value) == 1)
- {
- odataId = json_object_get(value, "@odata.id");
- if(odataId != NULL)
- {
- uri = json_string_value(odataId);
- json_decref(value);
- value = getUriFromService(payload->service, uri, StatusCode);
- if(value == NULL)
- {
- return NULL;
- }
- }
- }
- return createRedfishPayload(value, payload->service);
+ return createRedfishPayload (value, payload->service);
}
-redfishPayload* getPayloadForPath(redfishPayload* payload, redPathNode* redpath, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadForPath (
+ redfishPayload *payload,
+ redPathNode *redpath,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret = NULL;
- redfishPayload* tmp;
+ redfishPayload *ret = NULL;
+ redfishPayload *tmp;
- if(!payload || !redpath || StatusCode == NULL)
- {
- return NULL;
- }
-
- *StatusCode = NULL;
- BOOLEAN FromServerFlag = FALSE;
+ if (!payload || !redpath || (StatusCode == NULL)) {
+ return NULL;
+ }
- if(redpath->nodeName)
- {
- ret = getPayloadByNodeName(payload, redpath->nodeName, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else if(redpath->isIndex)
- {
- ASSERT (redpath->index >= 1);
- ret = getPayloadByIndex(payload, redpath->index - 1, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else if(redpath->op)
- {
- ret = getOpResult(payload, redpath->propName, redpath->op, redpath->value, StatusCode);
- if ((*StatusCode == NULL && ret == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- //
- // Any error happen, return directly.
- //
- return ret;
- }
- }
- else
- {
- return NULL;
- }
+ *StatusCode = NULL;
+ BOOLEAN FromServerFlag = FALSE;
+
+ if (redpath->nodeName) {
+ ret = getPayloadByNodeName (payload, redpath->nodeName, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else if (redpath->isIndex) {
+ ASSERT (redpath->index >= 1);
+ ret = getPayloadByIndex (payload, redpath->index - 1, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else if (redpath->op) {
+ ret = getOpResult (payload, redpath->propName, redpath->op, redpath->value, StatusCode);
+ if (((*StatusCode == NULL) && (ret == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ //
+ // Any error happen, return directly.
+ //
+ return ret;
+ }
+ } else {
+ return NULL;
+ }
- if(redpath->next == NULL || ret == NULL)
- {
- return ret;
+ if ((redpath->next == NULL) || (ret == NULL)) {
+ return ret;
+ } else {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ FromServerFlag = TRUE;
+ }
+
+ tmp = getPayloadForPath (ret, redpath->next, StatusCode);
+ if ((*StatusCode == NULL) && (tmp != NULL) && FromServerFlag) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (ret) directly.
+ // Since the ret are retrived from server, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ tmp = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
+ }
}
- else
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- FromServerFlag = TRUE;
- }
- tmp = getPayloadForPath(ret, redpath->next, StatusCode);
- if (*StatusCode == NULL && tmp != NULL && FromServerFlag) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (ret) directly.
- // Since the ret are retrived from server, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- tmp = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
- }
-
- cleanupPayload(ret);
- return tmp;
- }
+ cleanupPayload (ret);
+ return tmp;
+ }
}
-redfishPayload* getPayloadForPathString(redfishPayload* payload, const char* string, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadForPathString (
+ redfishPayload *payload,
+ const char *string,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redPathNode* redpath;
- redfishPayload* ret;
+ redPathNode *redpath;
+ redfishPayload *ret;
- if(!string || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!string || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- redpath = parseRedPath(string);
- if(redpath == NULL)
- {
- return NULL;
- }
- ret = getPayloadForPath(payload, redpath, StatusCode);
- cleanupRedPath(redpath);
- return ret;
+ redpath = parseRedPath (string);
+ if (redpath == NULL) {
+ return NULL;
+ }
+
+ ret = getPayloadForPath (payload, redpath, StatusCode);
+ cleanupRedPath (redpath);
+ return ret;
}
-redfishPayload* patchPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+patchPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* json;
- char* content;
- char* uri;
+ json_t *json;
+ char *content;
+ char *uri;
- if(!target || !payload || StatusCode == NULL)
- {
+ if (!target || !payload || (StatusCode == NULL)) {
return NULL;
}
*StatusCode = NULL;
- json = json_object_get(target->json, "@odata.id");
- if(json == NULL)
- {
+ json = json_object_get (target->json, "@odata.id");
+ if (json == NULL) {
return NULL;
}
- uri = strdup(json_string_value(json));
- content = json_dumps(payload->json, 0);
- json_decref(json);
+ uri = strdup (json_string_value (json));
- json = patchUriFromService(target->service, uri, content, StatusCode);
- free(uri);
- free(content);
- if(json == NULL)
- {
+ content = json_dumps (payload->json, 0);
+ json_decref (json);
+
+ json = patchUriFromService (target->service, uri, content, StatusCode);
+ free (uri);
+ free (content);
+ if (json == NULL) {
return NULL;
}
- return createRedfishPayload(json, target->service);
+ return createRedfishPayload (json, target->service);
}
-redfishPayload* postContentToPayload(redfishPayload* target, const char* data, size_t dataSize, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+postContentToPayload (
+ redfishPayload *target,
+ const char *data,
+ size_t dataSize,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* json;
- char* uri;
+ json_t *json;
+ char *uri;
- if(!target || !data || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!target || !data || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- json = json_object_get(target->json, "@odata.id");
- if(json == NULL)
- {
- json = json_object_get(target->json, "target");
- if(json == NULL)
- {
- return NULL;
- }
- }
- uri = strdup(json_string_value(json));
- json = postUriFromService(target->service, uri, data, dataSize, contentType, StatusCode);
- free(uri);
- if(json == NULL)
- {
- return NULL;
+ json = json_object_get (target->json, "@odata.id");
+ if (json == NULL) {
+ json = json_object_get (target->json, "target");
+ if (json == NULL) {
+ return NULL;
}
+ }
+
+ uri = strdup (json_string_value (json));
+ json = postUriFromService (target->service, uri, data, dataSize, contentType, StatusCode);
+ free (uri);
+ if (json == NULL) {
+ return NULL;
+ }
- return createRedfishPayload(json, target->service);
+ return createRedfishPayload (json, target->service);
}
-redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+postPayload (
+ redfishPayload *target,
+ redfishPayload *payload,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* content;
- redfishPayload* ret;
+ char *content;
+ redfishPayload *ret;
- if(!target || !payload || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!target || !payload || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- if(!json_is_object(payload->json))
- {
- return NULL;
- }
- content = payloadToString(payload, false);
- ret = postContentToPayload(target, content, strlen(content), NULL, StatusCode);
- free(content);
- return ret;
-}
+ if (!json_is_object (payload->json)) {
+ return NULL;
+ }
-void cleanupPayload(redfishPayload* payload)
-{
- if(!payload)
- {
- return;
- }
- json_decref(payload->json);
- //Don't free payload->service, let the caller handle cleaning up the service
- free(payload);
+ content = payloadToString (payload, false);
+ ret = postContentToPayload (target, content, strlen (content), NULL, StatusCode);
+ free (content);
+ return ret;
}
-static redfishPayload* getOpResult(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+void
+cleanupPayload (
+ redfishPayload *payload
+ )
{
- const char* propStr;
- json_t* stringProp;
- bool ret = false;
- redfishPayload* prop;
- long long intVal, intPropVal;
- json_type jsonType;
-
- if(isPayloadCollection(payload))
- {
- return collectionEvalOp(payload, propName, op, value, StatusCode);
- }
- if(isPayloadArray(payload))
- {
- return arrayEvalOp(payload, propName, op, value, StatusCode);
- }
+ if (!payload) {
+ return;
+ }
- prop = getPayloadByNodeName(payload, propName, StatusCode);
- if ((*StatusCode == NULL && prop == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return prop;
- }
- stringProp = prop->json;
- jsonType = prop->json->type;
- switch(jsonType)
- {
- case JSON_OBJECT:
- stringProp = json_object_get(prop->json, propName);
- case JSON_STRING:
- if(strcmp(op, "=") == 0)
- {
- propStr = json_string_value(stringProp);
- if(propStr == NULL)
- {
- cleanupPayload(prop);
- return NULL;
- }
- ret = (strcmp(propStr, value) == 0);
- } else if(strcmp(op, "~") == 0)
- {
- propStr = json_string_value(stringProp);
- if(propStr == NULL)
- {
- cleanupPayload(prop);
- return NULL;
- }
- ret = (strcasecmp(propStr, value) == 0);
- }
- break;
- case JSON_TRUE:
- if(strcmp(op, "=") == 0)
- {
- ret = (strcmp(value, "true") == 0);
- }
- break;
- case JSON_FALSE:
- if(strcmp(op, "=") == 0)
- {
- ret = (strcmp(value, "false") == 0);
- }
- break;
- case JSON_INTEGER:
- intPropVal = json_integer_value(prop->json);
- intVal = strtoll(value, NULL, 0);
- if(strcmp(op, "=") == 0)
- {
- ret = (intPropVal == intVal);
- }
- else if(strcmp(op, "<") == 0)
- {
- ret = (intPropVal < intVal);
- }
- else if(strcmp(op, ">") == 0)
- {
- ret = (intPropVal > intVal);
- }
- else if(strcmp(op, "<=") == 0)
- {
- ret = (intPropVal <= intVal);
- }
- else if(strcmp(op, ">=") == 0)
- {
- ret = (intPropVal >= intVal);
- }
- break;
- default:
- break;
- }
- cleanupPayload(prop);
- if(ret)
- {
- return payload;
- }
- else
- {
- return NULL;
- }
+ json_decref (payload->json);
+ // Don't free payload->service, let the caller handle cleaning up the service
+ free (payload);
}
-static redfishPayload* collectionEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+static redfishPayload *
+getOpResult (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- redfishPayload* tmp;
- redfishPayload* members;
- redfishPayload** valid;
- size_t validMax;
- size_t validCount = 0;
- size_t i;
-
- validMax = getCollectionSize(payload);
- if(validMax == 0)
- {
- return NULL;
- }
+ const char *propStr;
+ json_t *stringProp;
+ bool ret = false;
+ redfishPayload *prop;
+ long long intVal, intPropVal;
+ json_type jsonType;
+
+ if (isPayloadCollection (payload)) {
+ return collectionEvalOp (payload, propName, op, value, StatusCode);
+ }
- valid = (redfishPayload**)calloc(validMax, sizeof(redfishPayload*));
- if(valid == NULL)
- {
- return NULL;
- }
- /*Technically getPayloadByIndex would do this, but this optimizes things*/
- members = getPayloadByNodeName(payload, "Members", StatusCode);
- if ((*StatusCode == NULL && members == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return members;
- }
+ if (isPayloadArray (payload)) {
+ return arrayEvalOp (payload, propName, op, value, StatusCode);
+ }
- for(i = 0; i < validMax; i++)
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
+ prop = getPayloadByNodeName (payload, propName, StatusCode);
+ if (((*StatusCode == NULL) && (prop == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ return prop;
+ }
- tmp = getPayloadByIndex(members, i, StatusCode);
- if ((*StatusCode == NULL && tmp == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return tmp;
+ stringProp = prop->json;
+ jsonType = prop->json->type;
+ switch (jsonType) {
+ case JSON_OBJECT:
+ stringProp = json_object_get (prop->json, propName);
+ case JSON_STRING:
+ if (strcmp (op, "=") == 0) {
+ propStr = json_string_value (stringProp);
+ if (propStr == NULL) {
+ cleanupPayload (prop);
+ return NULL;
}
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
+ ret = (strcmp (propStr, value) == 0);
+ } else if (strcmp (op, "~") == 0) {
+ propStr = json_string_value (stringProp);
+ if (propStr == NULL) {
+ cleanupPayload (prop);
+ return NULL;
}
- valid[validCount] = getOpResult(tmp, propName, op, value, StatusCode);
- /*
- if ((*StatusCode == NULL && valid[validCount] == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return valid[validCount];
- }
- */
- if(valid[validCount] != NULL)
- {
- validCount++;
- }
- else
- {
- cleanupPayload(tmp);
- }
- }
- cleanupPayload(members);
- if(validCount == 0)
- {
- free(valid);
- return NULL;
- }
- if(validCount == 1)
- {
- ret = valid[0];
- free(valid);
- return ret;
- }
- else
- {
- ret = createCollection(payload->service, validCount, valid);
- free(valid);
- return ret;
- }
+ ret = (strcasecmp (propStr, value) == 0);
+ }
+
+ break;
+ case JSON_TRUE:
+ if (strcmp (op, "=") == 0) {
+ ret = (strcmp (value, "true") == 0);
+ }
+
+ break;
+ case JSON_FALSE:
+ if (strcmp (op, "=") == 0) {
+ ret = (strcmp (value, "false") == 0);
+ }
+
+ break;
+ case JSON_INTEGER:
+ intPropVal = json_integer_value (prop->json);
+ intVal = strtoll (value, NULL, 0);
+ if (strcmp (op, "=") == 0) {
+ ret = (intPropVal == intVal);
+ } else if (strcmp (op, "<") == 0) {
+ ret = (intPropVal < intVal);
+ } else if (strcmp (op, ">") == 0) {
+ ret = (intPropVal > intVal);
+ } else if (strcmp (op, "<=") == 0) {
+ ret = (intPropVal <= intVal);
+ } else if (strcmp (op, ">=") == 0) {
+ ret = (intPropVal >= intVal);
+ }
+
+ break;
+ default:
+ break;
+ }
+
+ cleanupPayload (prop);
+ if (ret) {
+ return payload;
+ } else {
+ return NULL;
+ }
}
-static redfishPayload* arrayEvalOp(redfishPayload* payload, const char* propName, const char* op, const char* value, EFI_HTTP_STATUS_CODE** StatusCode)
+static redfishPayload *
+collectionEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- redfishPayload* tmp;
- redfishPayload** valid;
- size_t validMax;
- size_t validCount = 0;
- size_t i;
-
- validMax = json_array_size(payload->json);
- if(validMax == 0)
- {
- return NULL;
+ redfishPayload *ret;
+ redfishPayload *tmp;
+ redfishPayload *members;
+ redfishPayload **valid;
+ size_t validMax;
+ size_t validCount = 0;
+ size_t i;
+
+ validMax = getCollectionSize (payload);
+ if (validMax == 0) {
+ return NULL;
+ }
+
+ valid = (redfishPayload **)calloc (validMax, sizeof (redfishPayload *));
+ if (valid == NULL) {
+ return NULL;
+ }
+
+ /*Technically getPayloadByIndex would do this, but this optimizes things*/
+ members = getPayloadByNodeName (payload, "Members", StatusCode);
+ if (((*StatusCode == NULL) && (members == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
+ {
+ return members;
+ }
+
+ for (i = 0; i < validMax; i++) {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
}
- valid = (redfishPayload**)calloc(validMax, sizeof(redfishPayload*));
- if(valid == NULL)
+ tmp = getPayloadByIndex (members, i, StatusCode);
+ if (((*StatusCode == NULL) && (tmp == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- return NULL;
+ return tmp;
}
- for(i = 0; i < validMax; i++)
- {
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
- tmp = getPayloadByIndex(payload, i, StatusCode);
- if ((*StatusCode == NULL && tmp == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return tmp;
- }
-
- if (*StatusCode != NULL) {
- FreePool (*StatusCode);
- *StatusCode = NULL;
- }
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ }
- valid[validCount] = getOpResult(tmp, propName, op, value, StatusCode);
- /*
- if ((*StatusCode == NULL && valid[validCount] == NULL) ||
- (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
- return valid[validCount];
- }
- */
+ valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
- if(valid[validCount] != NULL)
- {
- validCount++;
- }
- else
- {
- cleanupPayload(tmp);
- }
- }
- if(validCount == 0)
- {
- free(valid);
- return NULL;
- }
- if(validCount == 1)
- {
- ret = valid[0];
- free(valid);
- return ret;
+ /*
+ if ((*StatusCode == NULL && valid[validCount] == NULL) ||
+ (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ return valid[validCount];
}
- else
- {
- ret = createCollection(payload->service, validCount, valid);
- free(valid);
- return ret;
+ */
+ if (valid[validCount] != NULL) {
+ validCount++;
+ } else {
+ cleanupPayload (tmp);
}
+ }
+
+ cleanupPayload (members);
+ if (validCount == 0) {
+ free (valid);
+ return NULL;
+ }
+
+ if (validCount == 1) {
+ ret = valid[0];
+ free (valid);
+ return ret;
+ } else {
+ ret = createCollection (payload->service, validCount, valid);
+ free (valid);
+ return ret;
+ }
}
-static redfishPayload* createCollection(redfishService* service, size_t count, redfishPayload** payloads)
+static redfishPayload *
+arrayEvalOp (
+ redfishPayload *payload,
+ const char *propName,
+ const char *op,
+ const char *value,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redfishPayload* ret;
- json_t* collectionJson = json_object();
- json_t* jcount = json_integer((json_int_t)count);
- json_t* members = json_array();
- size_t i;
+ redfishPayload *ret;
+ redfishPayload *tmp;
+ redfishPayload **valid;
+ size_t validMax;
+ size_t validCount = 0;
+ size_t i;
+
+ validMax = json_array_size (payload->json);
+ if (validMax == 0) {
+ return NULL;
+ }
- if(!collectionJson)
- {
- return NULL;
+ valid = (redfishPayload **)calloc (validMax, sizeof (redfishPayload *));
+ if (valid == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < validMax; i++) {
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
}
- if(!members)
+
+ tmp = getPayloadByIndex (payload, i, StatusCode);
+ if (((*StatusCode == NULL) && (tmp == NULL)) ||
+ ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
{
- json_decref(collectionJson);
- return NULL;
+ return tmp;
}
- json_object_set(collectionJson, "Members@odata.count", jcount);
- json_decref(jcount);
- for(i = 0; i < count; i++)
- {
- json_array_append(members, payloads[i]->json);
- cleanupPayload(payloads[i]);
+
+ if (*StatusCode != NULL) {
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+ }
+
+ valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
+
+ /*
+ if ((*StatusCode == NULL && valid[validCount] == NULL) ||
+ (*StatusCode != NULL && (**StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))) {
+ return valid[validCount];
}
- json_object_set(collectionJson, "Members", members);
- json_decref(members);
+ */
+
+ if (valid[validCount] != NULL) {
+ validCount++;
+ } else {
+ cleanupPayload (tmp);
+ }
+ }
+
+ if (validCount == 0) {
+ free (valid);
+ return NULL;
+ }
- ret = createRedfishPayload(collectionJson, service);
+ if (validCount == 1) {
+ ret = valid[0];
+ free (valid);
+ return ret;
+ } else {
+ ret = createCollection (payload->service, validCount, valid);
+ free (valid);
return ret;
+ }
}
-static json_t* json_object_get_by_index(json_t* json, size_t index)
+static redfishPayload *
+createCollection (
+ redfishService *service,
+ size_t count,
+ redfishPayload **payloads
+ )
{
- void* iter;
- size_t i;
+ redfishPayload *ret;
+ json_t *collectionJson = json_object ();
+ json_t *jcount = json_integer ((json_int_t)count);
+ json_t *members = json_array ();
+ size_t i;
- iter = json_object_iter(json);
- for(i = 0; i < index; i++)
- {
- iter = json_object_iter_next(json, iter);
- if(iter == NULL) break;
- }
- if(iter == NULL)
- {
- return NULL;
+ if (!collectionJson) {
+ return NULL;
+ }
+
+ if (!members) {
+ json_decref (collectionJson);
+ return NULL;
+ }
+
+ json_object_set (collectionJson, "Members@odata.count", jcount);
+ json_decref (jcount);
+ for (i = 0; i < count; i++) {
+ json_array_append (members, payloads[i]->json);
+ cleanupPayload (payloads[i]);
+ }
+
+ json_object_set (collectionJson, "Members", members);
+ json_decref (members);
+
+ ret = createRedfishPayload (collectionJson, service);
+ return ret;
+}
+
+static json_t *
+json_object_get_by_index (
+ json_t *json,
+ size_t index
+ )
+{
+ void *iter;
+ size_t i;
+
+ iter = json_object_iter (json);
+ for (i = 0; i < index; i++) {
+ iter = json_object_iter_next (json, iter);
+ if (iter == NULL) {
+ break;
}
- return json_object_iter_value(iter);
+ }
+
+ if (iter == NULL) {
+ return NULL;
+ }
+
+ return json_object_iter_value (iter);
}
+
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c index 1fb4346c2b..cf5ab85165 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c @@ -16,177 +16,209 @@ **/
#include <redpath.h>
-static char* getVersion(const char* path, char** end);
-static void parseNode(const char* path, redPathNode* node, redPathNode** end);
+static char *
+getVersion (
+ const char *path,
+ char **end
+ );
+
+static void
+parseNode (
+ const char *path,
+ redPathNode *node,
+ redPathNode **end
+ );
+
+static char *
+getStringTill (
+ const char *string,
+ const char *terminator,
+ char **retEnd
+ );
+
+redPathNode *
+parseRedPath (
+ const char *path
+ )
+{
+ redPathNode *node;
+ redPathNode *endNode;
+ char *curPath;
+ char *end;
+
+ if (!path || (strlen (path) == 0)) {
+ return NULL;
+ }
+
+ node = (redPathNode *)calloc (1, sizeof (redPathNode));
+ if (!node) {
+ return NULL;
+ }
+
+ if (path[0] == '/') {
+ node->isRoot = true;
+ if (path[1] == 'v') {
+ node->version = getVersion (path+1, &curPath);
+ if (curPath == NULL) {
+ return node;
+ }
-static char* getStringTill(const char* string, const char* terminator, char** retEnd);
+ if (curPath[0] == '/') {
+ curPath++;
+ }
-redPathNode* parseRedPath(const char* path)
-{
- redPathNode* node;
- redPathNode* endNode;
- char* curPath;
- char* end;
-
- if(!path || strlen(path) == 0)
- {
- return NULL;
+ node->next = parseRedPath (curPath);
+ } else {
+ node->next = parseRedPath (path+1);
}
- node = (redPathNode*)calloc(1, sizeof(redPathNode));
- if(!node)
- {
- return NULL;
- }
- if(path[0] == '/')
- {
- node->isRoot = true;
- if(path[1] == 'v')
- {
- node->version = getVersion(path+1, &curPath);
- if(curPath == NULL)
- {
- return node;
- }
- if(curPath[0] == '/')
- {
- curPath++;
- }
- node->next = parseRedPath(curPath);
- }
- else
- {
- node->next = parseRedPath(path+1);
- }
- return node;
- }
- node->isRoot = false;
- curPath = getStringTill(path, "/", &end);
- endNode = node;
- parseNode(curPath, node, &endNode);
- free(curPath);
- if(end != NULL)
- {
- endNode->next = parseRedPath(end+1);
- }
return node;
+ }
+
+ node->isRoot = false;
+ curPath = getStringTill (path, "/", &end);
+ endNode = node;
+ parseNode (curPath, node, &endNode);
+ free (curPath);
+ if (end != NULL) {
+ endNode->next = parseRedPath (end+1);
+ }
+
+ return node;
}
-void cleanupRedPath(redPathNode* node)
+void
+cleanupRedPath (
+ redPathNode *node
+ )
{
- if(!node)
- {
- return;
- }
- cleanupRedPath(node->next);
- node->next = NULL;
- if(node->version)
- {
- free(node->version);
- }
- if(node->nodeName)
- {
- free(node->nodeName);
- }
- if(node->op)
- {
- free(node->op);
- }
- if(node->propName)
- {
- free(node->propName);
- }
- if(node->value)
- {
- free(node->value);
- }
- free(node);
+ if (!node) {
+ return;
+ }
+
+ cleanupRedPath (node->next);
+ node->next = NULL;
+ if (node->version) {
+ free (node->version);
+ }
+
+ if (node->nodeName) {
+ free (node->nodeName);
+ }
+
+ if (node->op) {
+ free (node->op);
+ }
+
+ if (node->propName) {
+ free (node->propName);
+ }
+
+ if (node->value) {
+ free (node->value);
+ }
+
+ free (node);
}
-static char* getVersion(const char* path, char** end)
+static char *
+getVersion (
+ const char *path,
+ char **end
+ )
{
- return getStringTill(path, "/", end);
+ return getStringTill (path, "/", end);
}
-static void parseNode(const char* path, redPathNode* node, redPathNode** end)
+static void
+parseNode (
+ const char *path,
+ redPathNode *node,
+ redPathNode **end
+ )
{
- char* indexStart;
- char* index;
- char* indexEnd;
- char* nodeName = getStringTill(path, "[", &indexStart);
- size_t tmpIndex;
- char* opChars;
-
- node->nodeName = nodeName;
- if(indexStart == NULL)
- {
- *end = node;
- return;
- }
- node->next = (redPathNode*)calloc(1, sizeof(redPathNode));
- if(!node->next)
- {
- return;
- }
- //Skip past [
- indexStart++;
- *end = node->next;
- index = getStringTill(indexStart, "]", NULL);
- tmpIndex = (size_t)strtoull(index, &indexEnd, 0);
- if(indexEnd != index)
- {
- free(index);
- node->next->index = tmpIndex;
- node->next->isIndex = true;
- return;
- }
- opChars = strpbrk(index, "<>=~");
- if(opChars == NULL)
- {
- //TODO handle last() and position()
- node->next->op = strdup("exists");
- node->next->propName = index;
- return;
- }
- node->next->propName = (char*)malloc((opChars - index)+1);
- memcpy(node->next->propName, index, (opChars - index));
- node->next->propName[(opChars - index)] = 0;
-
- tmpIndex = 1;
- while(1)
- {
- if(opChars[tmpIndex] == '=' || opChars[tmpIndex] == '<' || opChars[tmpIndex] == '>' || opChars[tmpIndex] == '~')
- {
- tmpIndex++;
- continue;
- }
- break;
- }
-
- node->next->op = (char*)malloc(tmpIndex+1);
- memcpy(node->next->op, opChars, tmpIndex);
- node->next->op[tmpIndex] = 0;
-
- node->next->value = strdup(opChars+tmpIndex);
- free(index);
+ char *indexStart;
+ char *index;
+ char *indexEnd;
+ char *nodeName = getStringTill (path, "[", &indexStart);
+ size_t tmpIndex;
+ char *opChars;
+
+ node->nodeName = nodeName;
+ if (indexStart == NULL) {
+ *end = node;
+ return;
+ }
+
+ node->next = (redPathNode *)calloc (1, sizeof (redPathNode));
+ if (!node->next) {
+ return;
+ }
+
+ // Skip past [
+ indexStart++;
+ *end = node->next;
+ index = getStringTill (indexStart, "]", NULL);
+ tmpIndex = (size_t)strtoull (index, &indexEnd, 0);
+ if (indexEnd != index) {
+ free (index);
+ node->next->index = tmpIndex;
+ node->next->isIndex = true;
+ return;
+ }
+
+ opChars = strpbrk (index, "<>=~");
+ if (opChars == NULL) {
+ // TODO handle last() and position()
+ node->next->op = strdup ("exists");
+ node->next->propName = index;
+ return;
+ }
+
+ node->next->propName = (char *)malloc ((opChars - index)+1);
+ memcpy (node->next->propName, index, (opChars - index));
+ node->next->propName[(opChars - index)] = 0;
+
+ tmpIndex = 1;
+ while (1) {
+ if ((opChars[tmpIndex] == '=') || (opChars[tmpIndex] == '<') || (opChars[tmpIndex] == '>') || (opChars[tmpIndex] == '~')) {
+ tmpIndex++;
+ continue;
+ }
+
+ break;
+ }
+
+ node->next->op = (char *)malloc (tmpIndex+1);
+ memcpy (node->next->op, opChars, tmpIndex);
+ node->next->op[tmpIndex] = 0;
+
+ node->next->value = strdup (opChars+tmpIndex);
+ free (index);
}
-static char* getStringTill(const char* string, const char* terminator, char** retEnd)
+static char *
+getStringTill (
+ const char *string,
+ const char *terminator,
+ char **retEnd
+ )
{
- char* ret;
- char* end;
- end = strstr((char*)string, terminator);
- if(retEnd)
- {
- *retEnd = end;
- }
- if(end == NULL)
- {
- //No terminator
- return strdup(string);
- }
- ret = (char*)malloc((end-string)+1);
- memcpy(ret, string, (end-string));
- ret[(end-string)] = 0;
- return ret;
+ char *ret;
+ char *end;
+
+ end = strstr ((char *)string, terminator);
+ if (retEnd) {
+ *retEnd = end;
+ }
+
+ if (end == NULL) {
+ // No terminator
+ return strdup (string);
+ }
+
+ ret = (char *)malloc ((end-string)+1);
+ memcpy (ret, string, (end-string));
+ ret[(end-string)] = 0;
+ return ret;
}
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c index edfd4fc6f9..afa172b531 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c @@ -19,22 +19,70 @@ #include <redfishPayload.h>
#include <redpath.h>
-static int initRest(redfishService* service, void * restProtocol);
-static redfishService* createServiceEnumeratorNoAuth(const char* host, const char* rootUri, bool enumerate, unsigned int flags, void * restProtocol);
-static redfishService* createServiceEnumeratorBasicAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol);
-static redfishService* createServiceEnumeratorSessionAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol);
-static char* makeUrlForService(redfishService* service, const char* uri);
-static json_t* getVersions(redfishService* service, const char* rootUri);
-static void addStringToJsonObject(json_t* object, const char* key, const char* value);
-
-CHAR16*
-C8ToC16 (CHAR8 *AsciiStr)
+static int
+initRest (
+ redfishService *service,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorNoAuth (
+ const char *host,
+ const char *rootUri,
+ bool enumerate,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorBasicAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static redfishService *
+createServiceEnumeratorSessionAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ );
+
+static char *
+makeUrlForService (
+ redfishService *service,
+ const char *uri
+ );
+
+static json_t *
+getVersions (
+ redfishService *service,
+ const char *rootUri
+ );
+
+static void
+addStringToJsonObject (
+ json_t *object,
+ const char *key,
+ const char *value
+ );
+
+CHAR16 *
+C8ToC16 (
+ CHAR8 *AsciiStr
+ )
{
- CHAR16 *Str;
+ CHAR16 *Str;
UINTN BufLen;
BufLen = (AsciiStrLen (AsciiStr) + 1) * 2;
- Str = AllocatePool (BufLen);
+ Str = AllocatePool (BufLen);
ASSERT (Str != NULL);
AsciiStrToUnicodeStrS (AsciiStr, Str, AsciiStrLen (AsciiStr) + 1);
@@ -44,11 +92,11 @@ C8ToC16 (CHAR8 *AsciiStr) VOID
RestConfigFreeHttpRequestData (
- IN EFI_HTTP_REQUEST_DATA *RequestData
+ IN EFI_HTTP_REQUEST_DATA *RequestData
)
{
if (RequestData == NULL) {
- return ;
+ return;
}
if (RequestData->Url != NULL) {
@@ -60,12 +108,12 @@ RestConfigFreeHttpRequestData ( VOID
RestConfigFreeHttpMessage (
- IN EFI_HTTP_MESSAGE *Message,
- IN BOOLEAN IsRequest
+ IN EFI_HTTP_MESSAGE *Message,
+ IN BOOLEAN IsRequest
)
{
if (Message == NULL) {
- return ;
+ return;
}
if (IsRequest) {
@@ -82,6 +130,7 @@ RestConfigFreeHttpMessage ( FreePool (Message->Headers);
Message->Headers = NULL;
}
+
if (Message->Body != NULL) {
FreePool (Message->Body);
Message->Body = NULL;
@@ -96,17 +145,16 @@ RestConfigFreeHttpMessage ( @return Buffer points to ASCII string, or NULL if error happens.
**/
-
CHAR8 *
UnicodeStrDupToAsciiStr (
- CONST CHAR16 *String
+ CONST CHAR16 *String
)
{
- CHAR8 *AsciiStr;
- UINTN BufLen;
- EFI_STATUS Status;
+ CHAR8 *AsciiStr;
+ UINTN BufLen;
+ EFI_STATUS Status;
- BufLen = StrLen (String) + 1;
+ BufLen = StrLen (String) + 1;
AsciiStr = AllocatePool (BufLen);
if (AsciiStr == NULL) {
return NULL;
@@ -119,6 +167,7 @@ UnicodeStrDupToAsciiStr ( return AsciiStr;
}
+
/**
This function encodes the content.
@@ -134,31 +183,33 @@ UnicodeStrDupToAsciiStr ( **/
EFI_STATUS
EncodeRequestContent (
- IN CHAR8 *ContentEncodedValue,
- IN CHAR8 *OriginalContent,
- OUT VOID **EncodedContent,
- OUT UINTN *EncodedContentLength
-)
+ IN CHAR8 *ContentEncodedValue,
+ IN CHAR8 *OriginalContent,
+ OUT VOID **EncodedContent,
+ OUT UINTN *EncodedContentLength
+ )
{
- EFI_STATUS Status;
- VOID *EncodedPointer;
- UINTN EncodedLength;
+ EFI_STATUS Status;
+ VOID *EncodedPointer;
+ UINTN EncodedLength;
- if (OriginalContent == NULL || EncodedContent == NULL || EncodedContentLength == NULL) {
+ if ((OriginalContent == NULL) || (EncodedContent == NULL) || (EncodedContentLength == NULL)) {
return EFI_INVALID_PARAMETER;
}
- Status = RedfishContentEncode (
+
+ Status = RedfishContentEncode (
ContentEncodedValue,
OriginalContent,
AsciiStrLen (OriginalContent),
&EncodedPointer,
&EncodedLength
- );
+ );
if (Status == EFI_SUCCESS) {
- *EncodedContent = EncodedPointer;
+ *EncodedContent = EncodedPointer;
*EncodedContentLength = EncodedLength;
return EFI_SUCCESS;
}
+
return Status;
}
@@ -180,30 +231,32 @@ EncodeRequestContent ( **/
EFI_STATUS
DecodeResponseContent (
- IN CHAR8 *ContentEncodedValue,
- IN OUT VOID **ContentPointer,
- IN OUT UINTN *ContentLength
-)
+ IN CHAR8 *ContentEncodedValue,
+ IN OUT VOID **ContentPointer,
+ IN OUT UINTN *ContentLength
+ )
{
- EFI_STATUS Status;
- VOID *DecodedPointer;
- UINTN DecodedLength;
+ EFI_STATUS Status;
+ VOID *DecodedPointer;
+ UINTN DecodedLength;
if (ContentEncodedValue == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Status = RedfishContentDecode (
- ContentEncodedValue,
- *ContentPointer,
- *ContentLength,
- &DecodedPointer,
- &DecodedLength
- );
+ ContentEncodedValue,
+ *ContentPointer,
+ *ContentLength,
+ &DecodedPointer,
+ &DecodedLength
+ );
if (Status == EFI_SUCCESS) {
FreePool (*ContentPointer);
*ContentPointer = DecodedPointer;
- *ContentLength = DecodedLength;
+ *ContentLength = DecodedLength;
}
+
return Status;
}
@@ -226,15 +279,15 @@ DecodeResponseContent ( **/
EFI_STATUS
RedfishBuildUrl (
- IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
- IN CHAR16 *RelativePath OPTIONAL,
- OUT CHAR16 **HttpUrl
+ IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ IN CHAR16 *RelativePath OPTIONAL,
+ OUT CHAR16 **HttpUrl
)
{
- CHAR16 *Url;
- CHAR16 *UrlHead;
- UINTN UrlLength;
- UINTN PathLen;
+ CHAR16 *Url;
+ CHAR16 *UrlHead;
+ UINTN UrlLength;
+ UINTN PathLen;
if ((RedfishConfigServiceInfo == NULL) || (HttpUrl == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -248,8 +301,9 @@ RedfishBuildUrl ( } else {
PathLen = StrLen (RelativePath);
}
- UrlLength = StrLen (HTTPS_FLAG) + StrLen (REDFISH_FIRST_URL) + 1 + StrLen(RedfishConfigServiceInfo->RedfishServiceLocation) + PathLen;
- Url = AllocateZeroPool (UrlLength * sizeof (CHAR16));
+
+ UrlLength = StrLen (HTTPS_FLAG) + StrLen (REDFISH_FIRST_URL) + 1 + StrLen (RedfishConfigServiceInfo->RedfishServiceLocation) + PathLen;
+ Url = AllocateZeroPool (UrlLength * sizeof (CHAR16));
if (Url == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -272,30 +326,38 @@ RedfishBuildUrl ( //
// Copy abs_path
//
- if (RelativePath != NULL && PathLen != 0 ) {
+ if ((RelativePath != NULL) && (PathLen != 0)) {
StrnCpyS (Url, UrlLength, RelativePath, PathLen);
}
+
*HttpUrl = UrlHead;
return EFI_SUCCESS;
}
-redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, const char* rootUri, enumeratorAuthentication* auth, unsigned int flags)
+redfishService *
+createServiceEnumerator (
+ REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
+ const char *rootUri,
+ enumeratorAuthentication *auth,
+ unsigned int flags
+ )
{
- EFI_STATUS Status;
- CHAR16 *HttpUrl;
- CHAR8 *AsciiHost;
- EFI_REST_EX_PROTOCOL *RestEx;
- redfishService *ret;
+ EFI_STATUS Status;
+ CHAR16 *HttpUrl;
+ CHAR8 *AsciiHost;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ redfishService *ret;
- HttpUrl = NULL;
+ HttpUrl = NULL;
AsciiHost = NULL;
- RestEx = NULL;
- ret = NULL;
+ RestEx = NULL;
+ ret = NULL;
if (RedfishConfigServiceInfo->RedfishServiceRestExHandle == NULL) {
goto ON_EXIT;
}
- Status = RedfishBuildUrl(RedfishConfigServiceInfo, NULL, &HttpUrl);
+
+ Status = RedfishBuildUrl (RedfishConfigServiceInfo, NULL, &HttpUrl);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
@@ -308,19 +370,20 @@ redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *Redf }
Status = gBS->HandleProtocol (
- RedfishConfigServiceInfo->RedfishServiceRestExHandle,
- &gEfiRestExProtocolGuid,
- (VOID **)&RestEx
- );
+ RedfishConfigServiceInfo->RedfishServiceRestExHandle,
+ &gEfiRestExProtocolGuid,
+ (VOID **)&RestEx
+ );
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
- if(auth == NULL) {
- ret = createServiceEnumeratorNoAuth(AsciiHost, rootUri, true, flags, RestEx);
- } else if(auth->authType == REDFISH_AUTH_BASIC) {
- ret = createServiceEnumeratorBasicAuth(AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
- } else if(auth->authType == REDFISH_AUTH_SESSION) {
- ret = createServiceEnumeratorSessionAuth(AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
+
+ if (auth == NULL) {
+ ret = createServiceEnumeratorNoAuth (AsciiHost, rootUri, true, flags, RestEx);
+ } else if (auth->authType == REDFISH_AUTH_BASIC) {
+ ret = createServiceEnumeratorBasicAuth (AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
+ } else if (auth->authType == REDFISH_AUTH_SESSION) {
+ ret = createServiceEnumeratorSessionAuth (AsciiHost, rootUri, auth->authCodes.userPass.username, auth->authCodes.userPass.password, flags, RestEx);
} else {
goto ON_EXIT;
}
@@ -338,31 +401,34 @@ ON_EXIT: return ret;
}
-json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+getUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- EFI_HTTP_HEADER *ContentEncodedHeader;
-
- if(service == NULL || uri == NULL || StatusCode == NULL)
- {
- return NULL;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ EFI_HTTP_HEADER *ContentEncodedHeader;
+
+ if ((service == NULL) || (uri == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: getUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: getUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -373,8 +439,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -403,7 +468,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA }
RequestData->Method = HttpMethodGet;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -445,7 +510,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA **StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
//
// Check if data is encoded.
//
@@ -461,6 +526,7 @@ json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STA goto ON_EXIT;
}
}
+
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
} else {
//
@@ -491,33 +557,37 @@ ON_EXIT: return ret;
}
-json_t* patchUriFromService(redfishService* service, const char* uri, const char* content, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+patchUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- CHAR8 ContentLengthStr[80];
- CHAR8 *EncodedContent;
- UINTN EncodedContentLen;
-
- if(service == NULL || uri == NULL || content == NULL || StatusCode == NULL)
- {
- return NULL;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ CHAR8 ContentLengthStr[80];
+ CHAR8 *EncodedContent;
+ UINTN EncodedContentLen;
+
+ if ((service == NULL) || (uri == NULL) || (content == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: patchUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: patchUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -528,8 +598,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -548,11 +617,11 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");
ASSERT_EFI_ERROR (Status);
- AsciiSPrint(
+ AsciiSPrint (
ContentLengthStr,
sizeof (ContentLengthStr),
"%lu",
- (UINT64) strlen(content)
+ (UINT64)strlen (content)
);
Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);
ASSERT_EFI_ERROR (Status);
@@ -569,7 +638,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char }
RequestData->Method = HttpMethodPatch;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -580,18 +649,18 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char goto ON_EXIT;
}
- EncodedContent = (CHAR8 *)content;
- EncodedContentLen = strlen(content);
+ EncodedContent = (CHAR8 *)content;
+ EncodedContentLen = strlen (content);
//
// We currently only support gzip Content-Encoding.
//
Status = EncodeRequestContent ((CHAR8 *)HTTP_CONTENT_ENCODING_GZIP, (CHAR8 *)content, (VOID **)&EncodedContent, &EncodedContentLen);
if (Status == EFI_INVALID_PARAMETER) {
- DEBUG((DEBUG_ERROR, "%a: Error to encode content.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a: Error to encode content.\n", __FUNCTION__));
ret = NULL;
goto ON_EXIT;
} else if (Status == EFI_UNSUPPORTED) {
- DEBUG((DEBUG_INFO, "No content coding for %a! Use raw data instead.\n", HTTP_CONTENT_ENCODING_GZIP));
+ DEBUG ((DEBUG_INFO, "No content coding for %a! Use raw data instead.\n", HTTP_CONTENT_ENCODING_GZIP));
Status = HttpIoSetHeader (HttpIoHeader, "Content-Encoding", HTTP_CONTENT_ENCODING_IDENTITY);
ASSERT_EFI_ERROR (Status);
} else {
@@ -603,7 +672,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char RequestMsg->HeaderCount = HttpIoHeader->HeaderCount;
RequestMsg->Headers = HttpIoHeader->Headers;
RequestMsg->BodyLength = EncodedContentLen;
- RequestMsg->Body = (VOID*) EncodedContent;
+ RequestMsg->Body = (VOID *)EncodedContent;
ZeroMem (&ResponseMsg, sizeof (ResponseMsg));
@@ -636,8 +705,7 @@ json_t* patchUriFromService(redfishService* service, const char* uri, const char FreePool (EncodedContent);
}
-
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
} else {
//
@@ -668,38 +736,43 @@ ON_EXIT: return ret;
}
-json_t* postUriFromService(redfishService* service, const char* uri, const char* content, size_t contentLength, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+postUriFromService (
+ redfishService *service,
+ const char *uri,
+ const char *content,
+ size_t contentLength,
+ const char *contentType,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url = NULL;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
- CHAR8 ContentLengthStr[80];
- EFI_HTTP_HEADER *HttpHeader = NULL;
+ char *url = NULL;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
+ CHAR8 ContentLengthStr[80];
+ EFI_HTTP_HEADER *HttpHeader = NULL;
ret = NULL;
- if(service == NULL || uri == NULL || content == NULL || StatusCode == NULL)
- {
- return NULL;
+ if ((service == NULL) || (uri == NULL) || (content == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: postUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: postUriFromService(): %a\n", url));
- if(contentLength == 0)
- {
- contentLength = strlen(content);
+ if (contentLength == 0) {
+ contentLength = strlen (content);
}
//
@@ -710,8 +783,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
@@ -719,13 +791,14 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* ASSERT_EFI_ERROR (Status);
}
- if(contentType == NULL) {
+ if (contentType == NULL) {
Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/json");
ASSERT_EFI_ERROR (Status);
} else {
- Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 *) contentType);
+ Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 *)contentType);
ASSERT_EFI_ERROR (Status);
}
+
Status = HttpIoSetHeader (HttpIoHeader, "Host", service->HostHeaderValue);
ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "Accept", "application/json");
@@ -734,11 +807,11 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");
ASSERT_EFI_ERROR (Status);
- AsciiSPrint(
+ AsciiSPrint (
ContentLengthStr,
sizeof (ContentLengthStr),
"%lu",
- (UINT64) contentLength
+ (UINT64)contentLength
);
Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);
ASSERT_EFI_ERROR (Status);
@@ -754,7 +827,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* }
RequestData->Method = HttpMethodPost;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -768,7 +841,7 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* RequestMsg->HeaderCount = HttpIoHeader->HeaderCount;
RequestMsg->Headers = HttpIoHeader->Headers;
RequestMsg->BodyLength = contentLength;
- RequestMsg->Body = (VOID*) content;
+ RequestMsg->Body = (VOID *)content;
ZeroMem (&ResponseMsg, sizeof (ResponseMsg));
@@ -795,21 +868,22 @@ json_t* postUriFromService(redfishService* service, const char* uri, const char* **StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
}
//
// Step 6: Parsing the HttpHeader to retrive the X-Auth-Token if the HTTP StatusCode is correct.
//
- if (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK ||
- ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT) {
+ if ((ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK) ||
+ (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT))
+ {
HttpHeader = HttpFindHeader (ResponseMsg.HeaderCount, ResponseMsg.Headers, "X-Auth-Token");
if (HttpHeader != NULL) {
- if(service->sessionToken)
- {
- free(service->sessionToken);
+ if (service->sessionToken) {
+ free (service->sessionToken);
}
+
service->sessionToken = AllocateCopyPool (AsciiStrSize (HttpHeader->FieldValue), HttpHeader->FieldValue);
}
@@ -849,32 +923,35 @@ ON_EXIT: return ret;
}
-json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode)
+json_t *
+deleteUriFromService (
+ redfishService *service,
+ const char *uri,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- char* url;
- json_t* ret;
- HTTP_IO_HEADER *HttpIoHeader = NULL;
- EFI_STATUS Status;
- EFI_HTTP_REQUEST_DATA *RequestData = NULL;
- EFI_HTTP_MESSAGE *RequestMsg = NULL;
- EFI_HTTP_MESSAGE ResponseMsg;
+ char *url;
+ json_t *ret;
+ HTTP_IO_HEADER *HttpIoHeader = NULL;
+ EFI_STATUS Status;
+ EFI_HTTP_REQUEST_DATA *RequestData = NULL;
+ EFI_HTTP_MESSAGE *RequestMsg = NULL;
+ EFI_HTTP_MESSAGE ResponseMsg;
ret = NULL;
- if(service == NULL || uri == NULL || StatusCode == NULL)
- {
- return NULL;
+ if ((service == NULL) || (uri == NULL) || (StatusCode == NULL)) {
+ return NULL;
}
*StatusCode = NULL;
- url = makeUrlForService(service, uri);
- if(!url)
- {
- return NULL;
+ url = makeUrlForService (service, uri);
+ if (!url) {
+ return NULL;
}
- DEBUG((DEBUG_INFO, "libredfish: deleteUriFromService(): %a\n", url));
+ DEBUG ((DEBUG_INFO, "libredfish: deleteUriFromService(): %a\n", url));
//
// Step 1: Create HTTP request message with 4 headers:
@@ -885,14 +962,14 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_ goto ON_EXIT;
}
- if(service->sessionToken)
- {
+ if (service->sessionToken) {
Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
ASSERT_EFI_ERROR (Status);
} else if (service->basicAuthStr) {
Status = HttpIoSetHeader (HttpIoHeader, "Authorization", service->basicAuthStr);
ASSERT_EFI_ERROR (Status);
}
+
Status = HttpIoSetHeader (HttpIoHeader, "Host", service->HostHeaderValue);
ASSERT_EFI_ERROR (Status);
Status = HttpIoSetHeader (HttpIoHeader, "User-Agent", "libredfish");
@@ -912,7 +989,7 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_ }
RequestData->Method = HttpMethodDelete;
- RequestData->Url = C8ToC16 (url);
+ RequestData->Url = C8ToC16 (url);
//
// Step 3: fill in EFI_HTTP_MESSAGE
@@ -954,7 +1031,7 @@ json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_ **StatusCode = ResponseMsg.Data.Response->StatusCode;
}
- if (ResponseMsg.BodyLength != 0 && ResponseMsg.Body != NULL) {
+ if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
}
@@ -980,169 +1057,191 @@ ON_EXIT: return ret;
}
-redfishPayload* getRedfishServiceRoot(redfishService* service, const char* version, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getRedfishServiceRoot (
+ redfishService *service,
+ const char *version,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- json_t* value;
- json_t* versionNode;
- const char* verUrl;
+ json_t *value;
+ json_t *versionNode;
+ const char *verUrl;
- if(version == NULL)
- {
- versionNode = json_object_get(service->versions, "v1");
- }
- else
- {
- versionNode = json_object_get(service->versions, version);
- }
- if(versionNode == NULL)
- {
- return NULL;
- }
- verUrl = json_string_value(versionNode);
- if(verUrl == NULL)
- {
- return NULL;
- }
- value = getUriFromService(service, verUrl, StatusCode);
- if(value == NULL)
- {
- if((service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) == 0)
- {
- json_decref(versionNode);
- }
- return NULL;
+ if (version == NULL) {
+ versionNode = json_object_get (service->versions, "v1");
+ } else {
+ versionNode = json_object_get (service->versions, version);
+ }
+
+ if (versionNode == NULL) {
+ return NULL;
+ }
+
+ verUrl = json_string_value (versionNode);
+ if (verUrl == NULL) {
+ return NULL;
+ }
+
+ value = getUriFromService (service, verUrl, StatusCode);
+ if (value == NULL) {
+ if ((service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) == 0) {
+ json_decref (versionNode);
}
- return createRedfishPayload(value, service);
+
+ return NULL;
+ }
+
+ return createRedfishPayload (value, service);
}
-redfishPayload* getPayloadByPath(redfishService* service, const char* path, EFI_HTTP_STATUS_CODE** StatusCode)
+redfishPayload *
+getPayloadByPath (
+ redfishService *service,
+ const char *path,
+ EFI_HTTP_STATUS_CODE **StatusCode
+ )
{
- redPathNode* redpath;
- redfishPayload* root;
- redfishPayload* ret;
+ redPathNode *redpath;
+ redfishPayload *root;
+ redfishPayload *ret;
- if(!service || !path || StatusCode == NULL)
- {
- return NULL;
- }
+ if (!service || !path || (StatusCode == NULL)) {
+ return NULL;
+ }
- *StatusCode = NULL;
+ *StatusCode = NULL;
- redpath = parseRedPath(path);
- if(!redpath)
- {
- return NULL;
- }
- if(!redpath->isRoot)
- {
- cleanupRedPath(redpath);
- return NULL;
- }
- root = getRedfishServiceRoot(service, redpath->version, StatusCode);
- if (*StatusCode == NULL || **StatusCode < HTTP_STATUS_200_OK || **StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT) {
- cleanupRedPath(redpath);
- return root;
- }
+ redpath = parseRedPath (path);
+ if (!redpath) {
+ return NULL;
+ }
- if(redpath->next == NULL)
- {
- cleanupRedPath(redpath);
- return root;
- }
+ if (!redpath->isRoot) {
+ cleanupRedPath (redpath);
+ return NULL;
+ }
- FreePool (*StatusCode);
- *StatusCode = NULL;
+ root = getRedfishServiceRoot (service, redpath->version, StatusCode);
+ if ((*StatusCode == NULL) || (**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ cleanupRedPath (redpath);
+ return root;
+ }
- ret = getPayloadForPath(root, redpath->next, StatusCode);
- if (*StatusCode == NULL && ret != NULL) {
- //
- // In such a case, the Redfish resource is parsed from the input payload (root) directly.
- // So, we still return HTTP_STATUS_200_OK.
- //
- *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
- if (*StatusCode == NULL) {
- ret = NULL;
- } else {
- **StatusCode = HTTP_STATUS_200_OK;
- }
+ if (redpath->next == NULL) {
+ cleanupRedPath (redpath);
+ return root;
+ }
+
+ FreePool (*StatusCode);
+ *StatusCode = NULL;
+
+ ret = getPayloadForPath (root, redpath->next, StatusCode);
+ if ((*StatusCode == NULL) && (ret != NULL)) {
+ //
+ // In such a case, the Redfish resource is parsed from the input payload (root) directly.
+ // So, we still return HTTP_STATUS_200_OK.
+ //
+ *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
+ if (*StatusCode == NULL) {
+ ret = NULL;
+ } else {
+ **StatusCode = HTTP_STATUS_200_OK;
}
- cleanupPayload(root);
- cleanupRedPath(redpath);
- return ret;
+ }
+
+ cleanupPayload (root);
+ cleanupRedPath (redpath);
+ return ret;
}
-void cleanupServiceEnumerator(redfishService* service)
+void
+cleanupServiceEnumerator (
+ redfishService *service
+ )
{
- if(!service)
- {
- return;
+ if (!service) {
+ return;
}
- free(service->host);
- json_decref(service->versions);
- if(service->sessionToken != NULL)
- {
- ZeroMem (service->sessionToken, (UINTN)strlen(service->sessionToken));
- FreePool(service->sessionToken);
+
+ free (service->host);
+ json_decref (service->versions);
+ if (service->sessionToken != NULL) {
+ ZeroMem (service->sessionToken, (UINTN)strlen (service->sessionToken));
+ FreePool (service->sessionToken);
}
+
if (service->basicAuthStr != NULL) {
- ZeroMem (service->basicAuthStr, (UINTN)strlen(service->basicAuthStr));
- FreePool (service->basicAuthStr);
+ ZeroMem (service->basicAuthStr, (UINTN)strlen (service->basicAuthStr));
+ FreePool (service->basicAuthStr);
}
- free(service);
+
+ free (service);
}
-static int initRest(redfishService* service, void * restProtocol)
+static int
+initRest (
+ redfishService *service,
+ void *restProtocol
+ )
{
service->RestEx = restProtocol;
return 0;
}
-static redfishService* createServiceEnumeratorNoAuth(const char* host, const char* rootUri, bool enumerate, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorNoAuth (
+ const char *host,
+ const char *rootUri,
+ bool enumerate,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- char *HostStart;
-
- ret = (redfishService*)calloc(1, sizeof(redfishService));
- ZeroMem (ret, sizeof(redfishService));
- if(initRest(ret, restProtocol) != 0)
- {
- free(ret);
- return NULL;
- }
- ret->host = AllocateCopyPool(AsciiStrSize(host), host);
- ret->flags = flags;
- if(enumerate)
- {
- ret->versions = getVersions(ret, rootUri);
- }
- HostStart = strstr (ret->host, "//");
- if (HostStart != NULL && (*(HostStart + 2) != '\0')) {
- ret->HostHeaderValue = HostStart + 2;
- }
+ redfishService *ret;
+ char *HostStart;
+
+ ret = (redfishService *)calloc (1, sizeof (redfishService));
+ ZeroMem (ret, sizeof (redfishService));
+ if (initRest (ret, restProtocol) != 0) {
+ free (ret);
+ return NULL;
+ }
+
+ ret->host = AllocateCopyPool (AsciiStrSize (host), host);
+ ret->flags = flags;
+ if (enumerate) {
+ ret->versions = getVersions (ret, rootUri);
+ }
- return ret;
+ HostStart = strstr (ret->host, "//");
+ if ((HostStart != NULL) && (*(HostStart + 2) != '\0')) {
+ ret->HostHeaderValue = HostStart + 2;
+ }
+
+ return ret;
}
EFI_STATUS
createBasicAuthStr (
- IN redfishService* service,
- IN CONST CHAR8 *UserId,
- IN CONST CHAR8 *Password
+ IN redfishService *service,
+ IN CONST CHAR8 *UserId,
+ IN CONST CHAR8 *Password
)
{
- EFI_STATUS Status;
- CHAR8 *RawAuthValue;
- UINTN RawAuthBufSize;
- CHAR8 *EnAuthValue;
- UINTN EnAuthValueSize;
- CHAR8 *BasicWithEnAuthValue;
- UINTN BasicBufSize;
+ EFI_STATUS Status;
+ CHAR8 *RawAuthValue;
+ UINTN RawAuthBufSize;
+ CHAR8 *EnAuthValue;
+ UINTN EnAuthValueSize;
+ CHAR8 *BasicWithEnAuthValue;
+ UINTN BasicBufSize;
EnAuthValue = NULL;
EnAuthValueSize = 0;
RawAuthBufSize = AsciiStrLen (UserId) + AsciiStrLen (Password) + 2;
- RawAuthValue = AllocatePool (RawAuthBufSize);
+ RawAuthValue = AllocatePool (RawAuthBufSize);
if (RawAuthValue == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -1162,20 +1261,20 @@ createBasicAuthStr ( // Encoding RawAuthValue into Base64 format.
//
Status = Base64Encode (
- (CONST UINT8 *) RawAuthValue,
+ (CONST UINT8 *)RawAuthValue,
AsciiStrLen (RawAuthValue),
EnAuthValue,
&EnAuthValueSize
);
if (Status == EFI_BUFFER_TOO_SMALL) {
- EnAuthValue = (CHAR8 *) AllocateZeroPool (EnAuthValueSize);
+ EnAuthValue = (CHAR8 *)AllocateZeroPool (EnAuthValueSize);
if (EnAuthValue == NULL) {
Status = EFI_OUT_OF_RESOURCES;
return Status;
}
Status = Base64Encode (
- (CONST UINT8 *) RawAuthValue,
+ (CONST UINT8 *)RawAuthValue,
AsciiStrLen (RawAuthValue),
EnAuthValue,
&EnAuthValueSize
@@ -1186,7 +1285,7 @@ createBasicAuthStr ( goto Exit;
}
- BasicBufSize = AsciiStrLen ("Basic ") + AsciiStrLen(EnAuthValue) + 2;
+ BasicBufSize = AsciiStrLen ("Basic ") + AsciiStrLen (EnAuthValue) + 2;
BasicWithEnAuthValue = AllocatePool (BasicBufSize);
if (BasicWithEnAuthValue == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@@ -1220,177 +1319,205 @@ Exit: return Status;
}
-static redfishService* createServiceEnumeratorBasicAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorBasicAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- EFI_STATUS Status;
+ redfishService *ret;
+ EFI_STATUS Status;
- ret = createServiceEnumeratorNoAuth(host, rootUri, false, flags, restProtocol);
+ ret = createServiceEnumeratorNoAuth (host, rootUri, false, flags, restProtocol);
- // add basic auth str
- Status = createBasicAuthStr (ret, username, password);
- if (EFI_ERROR(Status)) {
- cleanupServiceEnumerator (ret);
- return NULL;
- }
+ // add basic auth str
+ Status = createBasicAuthStr (ret, username, password);
+ if (EFI_ERROR (Status)) {
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- ret->versions = getVersions(ret, rootUri);
- return ret;
+ ret->versions = getVersions (ret, rootUri);
+ return ret;
}
-static redfishService* createServiceEnumeratorSessionAuth(const char* host, const char* rootUri, const char* username, const char* password, unsigned int flags, void * restProtocol)
+static redfishService *
+createServiceEnumeratorSessionAuth (
+ const char *host,
+ const char *rootUri,
+ const char *username,
+ const char *password,
+ unsigned int flags,
+ void *restProtocol
+ )
{
- redfishService* ret;
- redfishPayload* payload;
- redfishPayload* links;
- json_t* sessionPayload;
- json_t* session;
- json_t* odataId;
- const char* uri;
- json_t* post;
- char* content;
- EFI_HTTP_STATUS_CODE *StatusCode;
-
- content = NULL;
- StatusCode = NULL;
-
- ret = createServiceEnumeratorNoAuth(host, rootUri, true, flags, restProtocol);
- if(ret == NULL)
- {
- return NULL;
- }
- payload = getRedfishServiceRoot(ret, NULL, &StatusCode);
- if(StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)
- {
- if (StatusCode != NULL) {
- FreePool (StatusCode);
- }
-
- if (payload != NULL) {
- cleanupPayload(payload);
- }
- cleanupServiceEnumerator(ret);
- return NULL;
- }
+ redfishService *ret;
+ redfishPayload *payload;
+ redfishPayload *links;
+ json_t *sessionPayload;
+ json_t *session;
+ json_t *odataId;
+ const char *uri;
+ json_t *post;
+ char *content;
+ EFI_HTTP_STATUS_CODE *StatusCode;
+
+ content = NULL;
+ StatusCode = NULL;
+
+ ret = createServiceEnumeratorNoAuth (host, rootUri, true, flags, restProtocol);
+ if (ret == NULL) {
+ return NULL;
+ }
+ payload = getRedfishServiceRoot (ret, NULL, &StatusCode);
+ if ((StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
if (StatusCode != NULL) {
FreePool (StatusCode);
- StatusCode = NULL;
}
- links = getPayloadByNodeName(payload, "Links", &StatusCode);
- cleanupPayload(payload);
- if(links == NULL)
- {
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- session = json_object_get(links->json, "Sessions");
- if(session == NULL)
- {
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- odataId = json_object_get(session, "@odata.id");
- if(odataId == NULL)
- {
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
- return NULL;
- }
- uri = json_string_value(odataId);
- post = json_object();
- addStringToJsonObject(post, "UserName", username);
- addStringToJsonObject(post, "Password", password);
- content = json_dumps(post, 0);
- json_decref(post);
- sessionPayload = postUriFromService(ret, uri, content, 0, NULL, &StatusCode);
-
- if (content != NULL) {
- ZeroMem (content, (UINTN)strlen(content));
- free(content);
+ if (payload != NULL) {
+ cleanupPayload (payload);
}
- if(sessionPayload == NULL || StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)
- {
- //Failed to create session!
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
+
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
+ StatusCode = NULL;
+ }
+
+ links = getPayloadByNodeName (payload, "Links", &StatusCode);
+ cleanupPayload (payload);
+ if (links == NULL) {
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- cleanupPayload(links);
- cleanupServiceEnumerator(ret);
+ session = json_object_get (links->json, "Sessions");
+ if (session == NULL) {
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
- if (StatusCode != NULL) {
- FreePool (StatusCode);
- }
+ odataId = json_object_get (session, "@odata.id");
+ if (odataId == NULL) {
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
+ return NULL;
+ }
+
+ uri = json_string_value (odataId);
+ post = json_object ();
+ addStringToJsonObject (post, "UserName", username);
+ addStringToJsonObject (post, "Password", password);
+ content = json_dumps (post, 0);
+ json_decref (post);
+ sessionPayload = postUriFromService (ret, uri, content, 0, NULL, &StatusCode);
+
+ if (content != NULL) {
+ ZeroMem (content, (UINTN)strlen (content));
+ free (content);
+ }
+
+ if ((sessionPayload == NULL) || (StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ // Failed to create session!
- if (sessionPayload != NULL) {
- json_decref(sessionPayload);
- }
+ cleanupPayload (links);
+ cleanupServiceEnumerator (ret);
- return NULL;
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
}
- json_decref(sessionPayload);
- cleanupPayload(links);
- FreePool (StatusCode);
- return ret;
+
+ if (sessionPayload != NULL) {
+ json_decref (sessionPayload);
+ }
+
+ return NULL;
+ }
+
+ json_decref (sessionPayload);
+ cleanupPayload (links);
+ FreePool (StatusCode);
+ return ret;
}
-static char* makeUrlForService(redfishService* service, const char* uri)
+static char *
+makeUrlForService (
+ redfishService *service,
+ const char *uri
+ )
{
- char* url;
- if(service->host == NULL)
- {
- return NULL;
- }
- url = (char*)malloc(strlen(service->host)+strlen(uri)+1);
- strcpy(url, service->host);
- strcat(url, uri);
- return url;
+ char *url;
+
+ if (service->host == NULL) {
+ return NULL;
+ }
+
+ url = (char *)malloc (strlen (service->host)+strlen (uri)+1);
+ strcpy (url, service->host);
+ strcat (url, uri);
+ return url;
}
-static json_t* getVersions(redfishService* service, const char* rootUri)
+static json_t *
+getVersions (
+ redfishService *service,
+ const char *rootUri
+ )
{
- json_t* ret = NULL;
- EFI_HTTP_STATUS_CODE* StatusCode = NULL;
-
- if(service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC)
- {
- service->versions = json_object();
- if(service->versions == NULL)
- {
- return NULL;
- }
- addStringToJsonObject(service->versions, "v1", "/redfish/v1");
- return service->versions;
- }
- if(rootUri != NULL)
- {
- ret = getUriFromService(service, rootUri, &StatusCode);
- }
- else
- {
- ret = getUriFromService(service, "/redfish", &StatusCode);
- }
+ json_t *ret = NULL;
+ EFI_HTTP_STATUS_CODE *StatusCode = NULL;
- if (ret == NULL || StatusCode == NULL || *StatusCode < HTTP_STATUS_200_OK || *StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT) {
- if (ret != NULL) {
- json_decref(ret);
- }
- ret = NULL;
+ if (service->flags & REDFISH_FLAG_SERVICE_NO_VERSION_DOC) {
+ service->versions = json_object ();
+ if (service->versions == NULL) {
+ return NULL;
}
- if (StatusCode != NULL) {
- FreePool (StatusCode);
+ addStringToJsonObject (service->versions, "v1", "/redfish/v1");
+ return service->versions;
+ }
+
+ if (rootUri != NULL) {
+ ret = getUriFromService (service, rootUri, &StatusCode);
+ } else {
+ ret = getUriFromService (service, "/redfish", &StatusCode);
+ }
+
+ if ((ret == NULL) || (StatusCode == NULL) || (*StatusCode < HTTP_STATUS_200_OK) || (*StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)) {
+ if (ret != NULL) {
+ json_decref (ret);
}
- return ret;
+ ret = NULL;
+ }
+
+ if (StatusCode != NULL) {
+ FreePool (StatusCode);
+ }
+
+ return ret;
}
-static void addStringToJsonObject(json_t* object, const char* key, const char* value)
+static void
+addStringToJsonObject (
+ json_t *object,
+ const char *key,
+ const char *value
+ )
{
- json_t* jValue = json_string(value);
+ json_t *jValue = json_string (value);
- json_object_set(object, key, jValue);
+ json_object_set (object, key, jValue);
- json_decref(jValue);
+ json_decref (jValue);
}
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c index ff465d9ff3..c3a7efd796 100644 --- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c @@ -9,12 +9,12 @@ #include "RedfishConfigHandlerCommon.h"
-REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
+REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
// on platform for the BIOS
// Redfish configuration.
-EFI_EVENT gEndOfDxeEvent = NULL;
-EFI_EVENT gExitBootServiceEvent = NULL;
-EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
+EFI_EVENT gEndOfDxeEvent = NULL;
+EFI_EVENT gExitBootServiceEvent = NULL;
+EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
/**
Callback function executed when the EndOfDxe event group is signaled.
@@ -30,10 +30,10 @@ RedfishConfigOnEndOfDxe ( OUT VOID *Context
)
{
- EFI_STATUS Status;
+ 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));
}
@@ -58,10 +58,10 @@ RedfishConfigOnExitBootService ( OUT VOID *Context
)
{
- EFI_STATUS Status;
+ 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));
}
}
@@ -113,16 +113,18 @@ RedfishConfigCommonInit ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ 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,13 +172,13 @@ RedfishConfigCommonInit ( EFI_STATUS
RedfishConfigCommonStop (
VOID
-)
+ )
{
- EFI_STATUS Status;
- EFI_HANDLE *HandleBuffer;
- UINTN NumberOfHandles;
- UINTN Index;
- EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN NumberOfHandles;
+ UINTN Index;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
Status = gBS->LocateHandleBuffer (
ByProtocol,
@@ -182,27 +187,29 @@ RedfishConfigCommonStop ( &NumberOfHandles,
&HandleBuffer
);
- if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
+ if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
return Status;
}
Status = EFI_SUCCESS;
for (Index = 0; Index < NumberOfHandles; Index++) {
Status = gBS->HandleProtocol (
- HandleBuffer[Index],
- &gEdkIIRedfishConfigHandlerProtocolGuid,
- (VOID**) &ConfigHandler
- );
+ HandleBuffer[Index],
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ (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.
@@ -213,12 +220,12 @@ RedfishConfigHandlerInitialization ( VOID
)
{
- EFI_STATUS Status;
- EFI_HANDLE *HandleBuffer;
- UINTN NumberOfHandles;
- EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
- UINTN Index;
- UINT32 Id;
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN NumberOfHandles;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
+ UINTN Index;
+ UINT32 Id;
Status = gBS->LocateHandleBuffer (
ByProtocol,
@@ -233,33 +240,34 @@ 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],
- &gEdkIIRedfishConfigHandlerProtocolGuid,
- (VOID**) &ConfigHandler
- );
+ HandleBuffer[Index],
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ (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],
- &gEfiCallerIdGuid,
- EFI_NATIVE_INTERFACE,
- (VOID *)&gRedfishConfigData.CallerId
- );
+ &HandleBuffer[Index],
+ &gEfiCallerIdGuid,
+ EFI_NATIVE_INTERFACE,
+ (VOID *)&gRedfishConfigData.CallerId
+ );
ASSERT_EFI_ERROR (Status);
}
}
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h index 5e46c42219..460b3d915c 100644 --- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h @@ -40,11 +40,11 @@ /// Internal structure used by Redfish Config DXE driver.
///
typedef struct {
- UINT32 CallerId; ///< Caller ID used to indicate Redfish Config Handler
- ///< has been initiated
- EFI_HANDLE Image; ///< Image handle of Redfish Config Driver
- EFI_EVENT Event; ///< Event for the notification of EFI_REDFISH_CONFIG_HANDLER_PROTOCOL
- REDFISH_CONFIG_SERVICE_INFORMATION RedfishServiceInfo; /// Redfish Service information discovered
+ UINT32 CallerId; ///< Caller ID used to indicate Redfish Config Handler
+ ///< has been initiated
+ EFI_HANDLE Image; ///< Image handle of Redfish Config Driver
+ EFI_EVENT Event; ///< Event for the notification of EFI_REDFISH_CONFIG_HANDLER_PROTOCOL
+ REDFISH_CONFIG_SERVICE_INFORMATION RedfishServiceInfo; /// Redfish Service information discovered
} REDFISH_CONFIG_DRIVER_DATA;
/**
@@ -86,7 +86,7 @@ RedfishConfigCommonInit ( EFI_STATUS
RedfishConfigCommonStop (
VOID
-);
+ );
/**
Callback function executed when a Redfish Config Handler Protocol is installed
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c index 51378dff4f..96ac70f418 100644 --- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c @@ -17,22 +17,22 @@ EFI_EVENT gEfiRedfishDiscoverProtocolEvent = NULL; //
// Variables for using RFI Redfish Discover Protocol
//
-VOID *gEfiRedfishDiscoverRegistration;
-EFI_HANDLE gEfiRedfishDiscoverControllerHandle = NULL;
-EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol = NULL;
-BOOLEAN gRedfishDiscoverActivated = FALSE;
-BOOLEAN gRedfishServiceDiscovered = FALSE;
+VOID *gEfiRedfishDiscoverRegistration;
+EFI_HANDLE gEfiRedfishDiscoverControllerHandle = NULL;
+EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol = NULL;
+BOOLEAN gRedfishDiscoverActivated = FALSE;
+BOOLEAN gRedfishServiceDiscovered = FALSE;
//
// Network interfaces discovered by EFI Redfish Discover Protocol.
//
UINTN gNumberOfNetworkInterfaces;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *gNetworkInterfaceInstances = NULL;
-EFI_REDFISH_DISCOVERED_TOKEN *gRedfishDiscoveredToken = NULL;
+EFI_REDFISH_DISCOVERED_TOKEN *gRedfishDiscoveredToken = NULL;
///
/// Driver Binding Protocol instance
///
-EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding = {
RedfishConfigDriverBindingSupported,
RedfishConfigDriverBindingStart,
RedfishConfigDriverBindingStop,
@@ -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.
//
@@ -65,9 +66,9 @@ RedfishConfigStopRedfishDiscovery ( gNetworkInterfaceInstances
);
gEfiRedfishDiscoverControllerHandle = NULL;
- gEfiRedfishDiscoverProtocol = NULL;
- gRedfishDiscoverActivated = FALSE;
- gRedfishServiceDiscovered = FALSE;
+ gEfiRedfishDiscoverProtocol = NULL;
+ gRedfishDiscoverActivated = FALSE;
+ gRedfishServiceDiscovered = FALSE;
}
}
@@ -138,9 +139,9 @@ RedfishConfigDriverBindingSupported ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
- EFI_REST_EX_PROTOCOL *RestEx;
- EFI_STATUS Status;
- EFI_HANDLE ChildHandle;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ EFI_STATUS Status;
+ EFI_HANDLE ChildHandle;
ChildHandle = NULL;
@@ -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,
@@ -222,19 +224,19 @@ RedfishConfigDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
- VOID *ConfigHandlerRegistration;
+ VOID *ConfigHandlerRegistration;
if (gRedfishConfigData.Event != NULL) {
return EFI_ALREADY_STARTED;
}
gRedfishConfigData.Event = EfiCreateProtocolNotifyEvent (
- &gEdkIIRedfishConfigHandlerProtocolGuid,
- TPL_CALLBACK,
- RedfishConfigHandlerInstalledCallback,
- (VOID *)&gRedfishConfigData,
- &ConfigHandlerRegistration
- );
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ TPL_CALLBACK,
+ RedfishConfigHandlerInstalledCallback,
+ (VOID *)&gRedfishConfigData,
+ &ConfigHandlerRegistration
+ );
return EFI_SUCCESS;
}
@@ -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;
}
@@ -311,8 +315,8 @@ RedfishServiceDiscoveredCallback ( OUT VOID *Context
)
{
- EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken;
- EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance;
+ EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken;
+ EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance;
if (gRedfishServiceDiscovered) {
//
@@ -322,7 +326,7 @@ RedfishServiceDiscoveredCallback ( }
RedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)Context;
- RedfishInstance = RedfishDiscoveredToken->DiscoverList.RedfishInstances;
+ RedfishInstance = RedfishDiscoveredToken->DiscoverList.RedfishInstances;
//
// Only pick up the first found Redfish service.
//
@@ -336,7 +340,7 @@ RedfishServiceDiscoveredCallback ( gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct = RedfishInstance->Information.Product;
gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer = RedfishInstance->Information.ProductVer;
gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps = RedfishInstance->Information.UseHttps;
- gRedfishServiceDiscovered = TRUE;
+ gRedfishServiceDiscovered = TRUE;
}
//
@@ -361,76 +365,79 @@ RedfishDiscoverProtocolInstalled ( OUT VOID *Context
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
- EFI_HANDLE HandleBuffer;
- UINTN NetworkInterfaceIndex;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
- EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
+ EFI_STATUS Status;
+ UINTN BufferSize;
+ EFI_HANDLE HandleBuffer;
+ UINTN NetworkInterfaceIndex;
+ 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 (
- ByRegisterNotify,
- NULL,
- gEfiRedfishDiscoverRegistration,
- &BufferSize,
- &HandleBuffer
- );
+ Status = gBS->LocateHandle (
+ ByRegisterNotify,
+ NULL,
+ gEfiRedfishDiscoverRegistration,
+ &BufferSize,
+ &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;
+ gEfiRedfishDiscoverControllerHandle = HandleBuffer;
//
// First time to open EFI_REDFISH_DISCOVER_PROTOCOL.
//
- Status = gBS->OpenProtocol(
- gEfiRedfishDiscoverControllerHandle,
- &gEfiRedfishDiscoverProtocolGuid,
- (VOID **)&gEfiRedfishDiscoverProtocol,
- gRedfishConfigData.Image,
- gRedfishConfigData.Image,
- EFI_OPEN_PROTOCOL_BY_DRIVER
+ Status = gBS->OpenProtocol (
+ gEfiRedfishDiscoverControllerHandle,
+ &gEfiRedfishDiscoverProtocolGuid,
+ (VOID **)&gEfiRedfishDiscoverProtocol,
+ gRedfishConfigData.Image,
+ gRedfishConfigData.Image,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
gEfiRedfishDiscoverProtocol = NULL;
- gRedfishDiscoverActivated = FALSE;
- DEBUG((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __FUNCTION__));
+ gRedfishDiscoverActivated = FALSE;
+ 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;
}
- ThisNetworkInterface = gNetworkInterfaceInstances;
+ ThisNetworkInterface = gNetworkInterfaceInstances;
ThisRedfishDiscoveredToken = gRedfishDiscoveredToken;
//
// 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
//
@@ -440,37 +447,40 @@ RedfishDiscoverProtocolInstalled ( RedfishServiceDiscoveredCallback,
(VOID *)ThisRedfishDiscoveredToken,
&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->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound = 0;
- ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances = NULL;
+ ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances = NULL;
//
// Acquire for Redfish service which is reported by
// Redfish Host Interface.
//
- Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService(
- gEfiRedfishDiscoverProtocol,
- gRedfishConfigData.Image,
- ThisNetworkInterface,
- EFI_REDFISH_DISCOVER_HOST_INTERFACE,
- ThisRedfishDiscoveredToken
- );
- ThisNetworkInterface ++;
- ThisRedfishDiscoveredToken ++;
+ Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
+ gEfiRedfishDiscoverProtocol,
+ gRedfishConfigData.Image,
+ ThisNetworkInterface,
+ EFI_REDFISH_DISCOVER_HOST_INTERFACE,
+ 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);
}
}
@@ -488,23 +498,26 @@ RedfishConfigHandlerDriverUnload ( IN EFI_HANDLE ImageHandle
)
{
- EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
- UINTN NumberOfNetworkInterfacesIndex;
+ EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
+ UINTN NumberOfNetworkInterfacesIndex;
RedfishConfigDriverCommonUnload (ImageHandle);
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;
}
@@ -526,7 +539,7 @@ RedfishConfigHandlerDriverEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
ZeroMem ((VOID *)&gRedfishConfigData, sizeof (REDFISH_CONFIG_DRIVER_DATA));
gRedfishConfigData.Image = ImageHandle;
@@ -546,11 +559,12 @@ 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,
&gEfiRedfishDiscoverRegistration
- );
+ );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__));
return Status;
@@ -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;
}
-
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h index 58202c41e2..07214875bd 100644 --- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h @@ -26,10 +26,10 @@ //
extern EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding;
-extern REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData;
-extern EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential;
-extern EFI_EVENT gEndOfDxeEvent;
-extern EFI_EVENT gExitBootServiceEvent;
+extern REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData;
+extern EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential;
+extern EFI_EVENT gEndOfDxeEvent;
+extern EFI_EVENT gExitBootServiceEvent;
/**
Tests to see if this driver supports a given controller. If a child device is provided,
@@ -151,9 +151,10 @@ RedfishConfigDriverBindingStart ( EFI_STATUS
EFIAPI
RedfishConfigDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
+
#endif
diff --git a/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.c b/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.c index 0c6891ce9c..91bffa8067 100644 --- a/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.c +++ b/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.c @@ -10,7 +10,7 @@ #include <RedfishCredentialDxe.h>
-EDKII_REDFISH_CREDENTIAL_PROTOCOL mRedfishCredentialProtocol = {
+EDKII_REDFISH_CREDENTIAL_PROTOCOL mRedfishCredentialProtocol = {
RedfishCredentialGetAuthInfo,
RedfishCredentialStopService
};
@@ -79,17 +79,17 @@ RedfishCredentialEndOfDxeEventNotify ( EFI_STATUS
EFIAPI
RedfishCredentialGetAuthInfo (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ 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);
}
/**
@@ -112,8 +112,8 @@ RedfishCredentialGetAuthInfo ( EFI_STATUS
EFIAPI
RedfishCredentialStopService (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
)
{
if (This == NULL) {
@@ -135,8 +135,8 @@ RedfishCredentialStopService ( EFI_STATUS
EFIAPI
RedfishCredentialDxeDriverEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
diff --git a/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.h b/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.h index 6e7e417b33..dc765d5a1f 100644 --- a/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.h +++ b/RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.h @@ -6,6 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+
#ifndef EDKII_REDFISH_CREDENTIAL_DXE_H_
#define EDKII_REDFISH_CREDENTIAL_DXE_H_
@@ -45,10 +46,10 @@ EFI_STATUS
EFIAPI
RedfishCredentialGetAuthInfo (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
- OUT CHAR8 **UserId,
- OUT CHAR8 **Password
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
+ OUT CHAR8 **UserId,
+ OUT CHAR8 **Password
);
/**
@@ -69,7 +70,8 @@ RedfishCredentialGetAuthInfo ( EFI_STATUS
EFIAPI
RedfishCredentialStopService (
- IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
- IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
+ IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
+ IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
);
+
#endif
diff --git a/RedfishPkg/RedfishDiscoverDxe/ComponentName.c b/RedfishPkg/RedfishDiscoverDxe/ComponentName.c index adad2504bc..f34d7ab5d9 100644 --- a/RedfishPkg/RedfishDiscoverDxe/ComponentName.c +++ b/RedfishPkg/RedfishDiscoverDxe/ComponentName.c @@ -13,6 +13,7 @@ //
// EFI Component Name Functions
//
+
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@@ -87,13 +88,12 @@ EFI_STATUS EFIAPI
RedfishDiscoverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ 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"
};
@@ -118,12 +118,12 @@ EFI_COMPONENT_NAME2_PROTOCOL gRedfishDiscoverComponentName2 = { /// Table of driver names
///
GLOBAL_REMOVE_IF_UNREFERENCED
-EFI_UNICODE_STRING_TABLE mRedfishDiscoverDriverNameTable[] = {
+EFI_UNICODE_STRING_TABLE mRedfishDiscoverDriverNameTable[] = {
{ "eng;en", (CHAR16 *)L"Redfish Discover UEFI Driver" },
- { NULL, NULL }
+ { NULL, NULL }
};
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gRedfishDiscoverControllerNameTable = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gRedfishDiscoverControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@@ -208,10 +208,10 @@ EFI_STATUS EFIAPI
RedfishDiscoverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c index 80d70a4679..bf50c78c92 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c @@ -10,36 +10,36 @@ #include "RedfishDiscoverInternal.h"
-LIST_ENTRY mRedfishDiscoverList;
-LIST_ENTRY mRedfishInstanceList;
-EFI_SMBIOS_PROTOCOL *mSmbios = NULL;
+LIST_ENTRY mRedfishDiscoverList;
+LIST_ENTRY mRedfishInstanceList;
+EFI_SMBIOS_PROTOCOL *mSmbios = NULL;
-UINTN mNumNetworkInterface = 0;
-UINTN mNumRestExInstance = 0;
-LIST_ENTRY mEfiRedfishDiscoverNetworkInterface;
-LIST_ENTRY mEfiRedfishDiscoverRestExInstance;
+UINTN mNumNetworkInterface = 0;
+UINTN mNumRestExInstance = 0;
+LIST_ENTRY mEfiRedfishDiscoverNetworkInterface;
+LIST_ENTRY mEfiRedfishDiscoverRestExInstance;
-EFI_GUID mRedfishDiscoverTcp4InstanceGuid = EFI_REDFISH_DISCOVER_TCP4_INSTANCE_GUID;
-EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;
-EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;
+EFI_GUID mRedfishDiscoverTcp4InstanceGuid = EFI_REDFISH_DISCOVER_TCP4_INSTANCE_GUID;
+EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;
+EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;
-EFI_HANDLE EfiRedfishDiscoverProtocolHandle = NULL;
+EFI_HANDLE EfiRedfishDiscoverProtocolHandle = NULL;
EFI_STATUS
EFIAPI
Tcp4GetSubnetInfo (
- IN EFI_HANDLE ImageHandle,
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
-);
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
+ );
EFI_STATUS
EFIAPI
Tcp6GetSubnetInfo (
- IN EFI_HANDLE ImageHandle,
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
-);
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
+ );
-static REDFISH_DISCOVER_REQUIRED_PROTOCOL gRequiredProtocol[] = {
+static REDFISH_DISCOVER_REQUIRED_PROTOCOL gRequiredProtocol[] = {
{
ProtocolTypeTcp4,
L"TCP4 Service Binding Protocol",
@@ -79,19 +79,19 @@ static REDFISH_DISCOVER_REQUIRED_PROTOCOL gRequiredProtocol[] = { **/
EFI_STATUS
CreateRestExInstance (
- IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
- IN EFI_REDFISH_DISCOVERED_TOKEN *Token
+ IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
+ IN EFI_REDFISH_DISCOVERED_TOKEN *Token
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = RestExLibCreateChild (
- Instance->Owner,
- FixedPcdGetBool (PcdRedfishDiscoverAccessModeInBand)? EfiRestExServiceInBandAccess: EfiRestExServiceOutOfBandAccess,
- EfiRestExConfigHttp,
- EfiRestExServiceRedfish,
- &Token->DiscoverList.RedfishInstances->Information.RedfishRestExHandle
- );
+ Instance->Owner,
+ FixedPcdGetBool (PcdRedfishDiscoverAccessModeInBand) ? EfiRestExServiceInBandAccess : EfiRestExServiceOutOfBandAccess,
+ EfiRestExConfigHttp,
+ EfiRestExServiceRedfish,
+ &Token->DiscoverList.RedfishInstances->Information.RedfishRestExHandle
+ );
return Status;
}
@@ -109,30 +109,35 @@ CreateRestExInstance ( **/
EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *
GetInstanceByOwner (
- IN EFI_HANDLE ImageHandle,
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *TargetNetworkInterface,
- IN EFI_REDFISH_DISCOVER_FLAG DiscoverFlags
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *TargetNetworkInterface,
+ IN EFI_REDFISH_DISCOVER_FLAG DiscoverFlags
)
{
- EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *ThisInstance;
+ EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *ThisInstance;
if (IsListEmpty (&mRedfishDiscoverList)) {
return NULL;
}
+
ThisInstance =
(EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)GetFirstNode (&mRedfishDiscoverList);
while (TRUE) {
if ((ThisInstance->Owner == ImageHandle) &&
- (ThisInstance->DiscoverFlags == DiscoverFlags) &&
- (ThisInstance->NetworkInterface == TargetNetworkInterface)) {
+ (ThisInstance->DiscoverFlags == DiscoverFlags) &&
+ (ThisInstance->NetworkInterface == TargetNetworkInterface))
+ {
return ThisInstance;
}
+
if (IsNodeAtEnd (&mRedfishDiscoverList, &ThisInstance->Entry)) {
break;
}
+
ThisInstance =
(EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)GetNextNode (&mRedfishDiscoverList, &ThisInstance->Entry);
- };
+ }
+
return NULL;
}
@@ -147,81 +152,87 @@ GetInstanceByOwner ( EFI_STATUS
EFIAPI
Tcp4GetSubnetInfo (
- IN EFI_HANDLE ImageHandle,
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
-)
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
+ )
{
- EFI_STATUS Status;
- EFI_TCP4_PROTOCOL *Tcp4;
- EFI_TCP4_CONFIG_DATA Tcp4CfgData;
- EFI_TCP4_OPTION Tcp4Option;
- EFI_IP4_MODE_DATA IpModedata;
- UINT8 SubnetMaskIndex;
- UINT8 BitMask;
- UINT8 PrefixLength;
- BOOLEAN GotPrefixLength;
+ EFI_STATUS Status;
+ EFI_TCP4_PROTOCOL *Tcp4;
+ EFI_TCP4_CONFIG_DATA Tcp4CfgData;
+ EFI_TCP4_OPTION Tcp4Option;
+ EFI_IP4_MODE_DATA IpModedata;
+ UINT8 SubnetMaskIndex;
+ UINT8 BitMask;
+ UINT8 PrefixLength;
+ BOOLEAN GotPrefixLength;
if (Instance == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Tcp4 = (EFI_TCP4_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
ZeroMem ((VOID *)&Tcp4CfgData, sizeof (EFI_TCP4_CONFIG_DATA));
ZeroMem ((VOID *)&Tcp4Option, sizeof (EFI_TCP4_OPTION));
// Give a local host IP address just for getting subnet information.
- Tcp4CfgData.AccessPoint.UseDefaultAddress = TRUE;
- Tcp4CfgData.AccessPoint.RemoteAddress.Addr [0] = 127;
- Tcp4CfgData.AccessPoint.RemoteAddress.Addr [1] = 0;
- Tcp4CfgData.AccessPoint.RemoteAddress.Addr [2] = 0;
- Tcp4CfgData.AccessPoint.RemoteAddress.Addr [3] = 1;
- Tcp4CfgData.AccessPoint.RemotePort = 80;
- Tcp4CfgData.AccessPoint.ActiveFlag = TRUE;
-
- Tcp4CfgData.ControlOption = &Tcp4Option;
- Tcp4Option.ReceiveBufferSize = 65535;
- Tcp4Option.SendBufferSize = 65535;
- Tcp4Option.MaxSynBackLog = 5;
- Tcp4Option.ConnectionTimeout = 60;
- Tcp4Option.DataRetries = 12;
- Tcp4Option.FinTimeout = 2;
- Tcp4Option.KeepAliveProbes = 6;
- Tcp4Option.KeepAliveTime = 7200;
- Tcp4Option.KeepAliveInterval = 30;
- Tcp4Option.EnableNagle = TRUE;
- Status = Tcp4->Configure (Tcp4, &Tcp4CfgData);
+ Tcp4CfgData.AccessPoint.UseDefaultAddress = TRUE;
+ Tcp4CfgData.AccessPoint.RemoteAddress.Addr[0] = 127;
+ Tcp4CfgData.AccessPoint.RemoteAddress.Addr[1] = 0;
+ Tcp4CfgData.AccessPoint.RemoteAddress.Addr[2] = 0;
+ Tcp4CfgData.AccessPoint.RemoteAddress.Addr[3] = 1;
+ Tcp4CfgData.AccessPoint.RemotePort = 80;
+ Tcp4CfgData.AccessPoint.ActiveFlag = TRUE;
+
+ Tcp4CfgData.ControlOption = &Tcp4Option;
+ Tcp4Option.ReceiveBufferSize = 65535;
+ Tcp4Option.SendBufferSize = 65535;
+ Tcp4Option.MaxSynBackLog = 5;
+ Tcp4Option.ConnectionTimeout = 60;
+ Tcp4Option.DataRetries = 12;
+ Tcp4Option.FinTimeout = 2;
+ Tcp4Option.KeepAliveProbes = 6;
+ Tcp4Option.KeepAliveTime = 7200;
+ Tcp4Option.KeepAliveInterval = 30;
+ Tcp4Option.EnableNagle = TRUE;
+ Status = Tcp4->Configure (Tcp4, &Tcp4CfgData);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get subnet information\n", __FUNCTION__));
return Status;
}
+
Status = Tcp4->GetModeData (Tcp4, NULL, NULL, &IpModedata, NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __FUNCTION__));
return Status;
}
+
IP4_COPY_ADDRESS (&Instance->SubnetMask, &IpModedata.ConfigData.SubnetMask);
- Instance->SubnetAddr.v4.Addr [0] = IpModedata.ConfigData.StationAddress.Addr [0] & Instance->SubnetMask.v4.Addr [0];
- Instance->SubnetAddr.v4.Addr [1] = IpModedata.ConfigData.StationAddress.Addr [1] & Instance->SubnetMask.v4.Addr [1];
- Instance->SubnetAddr.v4.Addr [2] = IpModedata.ConfigData.StationAddress.Addr [2] & Instance->SubnetMask.v4.Addr [2];
- Instance->SubnetAddr.v4.Addr [3] = IpModedata.ConfigData.StationAddress.Addr [3] & Instance->SubnetMask.v4.Addr [3];
+ Instance->SubnetAddr.v4.Addr[0] = IpModedata.ConfigData.StationAddress.Addr[0] & Instance->SubnetMask.v4.Addr[0];
+ Instance->SubnetAddr.v4.Addr[1] = IpModedata.ConfigData.StationAddress.Addr[1] & Instance->SubnetMask.v4.Addr[1];
+ Instance->SubnetAddr.v4.Addr[2] = IpModedata.ConfigData.StationAddress.Addr[2] & Instance->SubnetMask.v4.Addr[2];
+ Instance->SubnetAddr.v4.Addr[3] = IpModedata.ConfigData.StationAddress.Addr[3] & Instance->SubnetMask.v4.Addr[3];
//
// Calculate the subnet mask prefix.
//
GotPrefixLength = FALSE;
- PrefixLength = 0;
+ PrefixLength = 0;
SubnetMaskIndex = 0;
while (GotPrefixLength == FALSE && SubnetMaskIndex < 4) {
BitMask = 0x80;
while (BitMask != 0) {
- if ((Instance->SubnetMask.v4.Addr [SubnetMaskIndex] & BitMask) != 0) {
- PrefixLength ++;
+ if ((Instance->SubnetMask.v4.Addr[SubnetMaskIndex] & BitMask) != 0) {
+ PrefixLength++;
} else {
GotPrefixLength = TRUE;
break;
}
+
BitMask = BitMask >> 1;
- };
- SubnetMaskIndex ++;
- };
+ }
+
+ SubnetMaskIndex++;
+ }
+
Instance->SubnetPrefixLength = PrefixLength;
return EFI_SUCCESS;
}
@@ -237,17 +248,18 @@ Tcp4GetSubnetInfo ( EFI_STATUS
EFIAPI
Tcp6GetSubnetInfo (
- IN EFI_HANDLE ImageHandle,
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
-)
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
+ )
{
- EFI_STATUS Status;
- EFI_TCP6_PROTOCOL *Tcp6;
- EFI_IP6_MODE_DATA IpModedata;
+ EFI_STATUS Status;
+ EFI_TCP6_PROTOCOL *Tcp6;
+ EFI_IP6_MODE_DATA IpModedata;
if (Instance == NULL) {
return EFI_INVALID_PARAMETER;
}
+
Tcp6 = (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
@@ -255,17 +267,21 @@ Tcp6GetSubnetInfo ( DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n"));
return Status;
}
+
if (IpModedata.AddressCount == 0) {
DEBUG ((DEBUG_INFO, "%a: No IPv6 address configured.\n"));
}
+
if (Instance->SubnetAddrInfoIPv6 != NULL) {
FreePool (Instance->SubnetAddrInfoIPv6);
}
+
Instance->SubnetAddrInfoIPv6 = AllocateZeroPool (IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO));
if (Instance->SubnetAddrInfoIPv6 == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory fir IPv6 subnet address information\n"));
return EFI_OUT_OF_RESOURCES;
}
+
Instance->SubnetAddrInfoIPv6Number = IpModedata.AddressCount;
CopyMem (
(VOID *)Instance->SubnetAddrInfoIPv6,
@@ -291,18 +307,21 @@ GetTargetNetworkInterfaceInternal ( IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface
)
{
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
- if (CompareMem((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
+ if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
return ThisNetworkInterface;
}
+
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
return NULL;
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
- };
+
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
+ }
+
return NULL;
}
@@ -320,63 +339,74 @@ GetTargetNetworkInterfaceInternal ( EFI_STATUS
ValidateTargetNetworkInterface (
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface,
- IN EFI_REDFISH_DISCOVER_FLAG Flags
+ IN EFI_REDFISH_DISCOVER_FLAG Flags
)
{
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
- if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface) && TargetNetworkInterface == NULL) {
+ if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface) && (TargetNetworkInterface == NULL)) {
return EFI_UNSUPPORTED;
}
+
if (TargetNetworkInterface == NULL) {
return EFI_SUCCESS; // Return EFI_SUCCESS if no network interface is specified.
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode(&mEfiRedfishDiscoverNetworkInterface);
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
- if (CompareMem((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
+ if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
break;
}
+
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
return EFI_UNSUPPORTED;
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
- };
+
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
+ }
+
if ((Flags & EFI_REDFISH_DISCOVER_SSDP) != 0) {
// Validate if UDP4/6 is supported on the given network interface.
// SSDP is not supported.
return EFI_SUCCESS;
}
+
if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == NULL) {
return EFI_UNSUPPORTED; // The required protocol on this network interface is not found.
}
+
return EFI_SUCCESS;
}
+
/**
This function returns number of network interface instance.
@retval UINTN Number of network interface instances.
**/
UINTN
-NumberOfNetworkInterface (VOID)
+NumberOfNetworkInterface (
+ VOID
+ )
{
- UINTN Num;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ UINTN Num;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
return 0;
}
- Num = 1;
+ Num = 1;
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
break;
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
- Num ++;
- };
+
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
+ Num++;
+ }
+
return Num;
}
@@ -391,12 +421,13 @@ NumberOfNetworkInterface (VOID) **/
BOOLEAN
CheckIsIpVersion6 (
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface
-)
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface
+ )
{
if (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6) {
return TRUE;
}
+
return FALSE;
}
@@ -410,41 +441,45 @@ CheckIsIpVersion6 ( **/
EFI_STATUS
-DiscoverRedfishHostInterface (IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance)
+DiscoverRedfishHostInterface (
+ IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance
+ )
{
- EFI_STATUS Status;
- REDFISH_OVER_IP_PROTOCOL_DATA *Data;
- REDFISH_INTERFACE_DATA *DeviceDescriptor;
- CHAR8 UuidStr[sizeof"00000000-0000-0000-0000-000000000000" + 1];
- CHAR16 Ipv6Str [sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
- CHAR8 RedfishServiceLocateStr [sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
- UINTN StrSize;
- UINTN MacCompareStstus;
- BOOLEAN IsHttps;
-
- Data = NULL;
+ EFI_STATUS Status;
+ REDFISH_OVER_IP_PROTOCOL_DATA *Data;
+ REDFISH_INTERFACE_DATA *DeviceDescriptor;
+ CHAR8 UuidStr[sizeof "00000000-0000-0000-0000-000000000000" + 1];
+ CHAR16 Ipv6Str[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
+ CHAR8 RedfishServiceLocateStr[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
+ UINTN StrSize;
+ UINTN MacCompareStstus;
+ BOOLEAN IsHttps;
+
+ Data = NULL;
DeviceDescriptor = NULL;
if (mSmbios == NULL) {
- Status = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID **)&mSmbios);
+ Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&mSmbios);
if (EFI_ERROR (Status)) {
return Status;
}
}
+
Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
- if (!EFI_ERROR (Status) && Data != NULL && DeviceDescriptor != NULL) {
+ if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
//
// Chceck if we can reach out Redfish service using this network interface.
// Check with MAC address using Device Descroptor Data Device Type 04 and Type 05.
// Those two types of Redfish host interface device has MAC information.
//
if (DeviceDescriptor->DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
- MacCompareStstus = CompareMem(&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.MacAddress, 6);
- } else if (DeviceDescriptor->DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2){
- MacCompareStstus = CompareMem(&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress, 6);
+ MacCompareStstus = CompareMem (&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.MacAddress, 6);
+ } else if (DeviceDescriptor->DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) {
+ MacCompareStstus = CompareMem (&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress, 6);
} else {
return EFI_UNSUPPORTED;
}
+
if (MacCompareStstus != 0) {
return EFI_UNSUPPORTED;
}
@@ -456,7 +491,7 @@ DiscoverRedfishHostInterface (IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Insta }
if (Instance->HostIntfValidation) {
- DEBUG ((DEBUG_ERROR,"%a:Send UPnP unicast SSDP to validate this Redfish Host Interface is not supported.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:Send UPnP unicast SSDP to validate this Redfish Host Interface is not supported.\n", __FUNCTION__));
Status = EFI_UNSUPPORTED;
} else {
//
@@ -467,66 +502,69 @@ DiscoverRedfishHostInterface (IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Insta if (Data->RedfishServiceIpPort == 443) {
IsHttps = TRUE;
}
- StrSize = sizeof(UuidStr);
- AsciiSPrint(UuidStr, StrSize, "%g", &Data->ServiceUuid);
+
+ StrSize = sizeof (UuidStr);
+ AsciiSPrint (UuidStr, StrSize, "%g", &Data->ServiceUuid);
//
// Generate Redfish service location string.
//
if (Data->RedfishServiceIpAddressFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6) {
- NetLibIp6ToStr((IPv6_ADDRESS *)&Data->RedfishServiceIpAddress, Ipv6Str, sizeof (Ipv6Str));
- if (Data->RedfishServiceIpPort == 0 || IsHttps == TRUE) {
- AsciiSPrintUnicodeFormat (
- RedfishServiceLocateStr,
- sizeof (RedfishServiceLocateStr),
- L"%s",
- Ipv6Str
+ NetLibIp6ToStr ((IPv6_ADDRESS *)&Data->RedfishServiceIpAddress, Ipv6Str, sizeof (Ipv6Str));
+ if ((Data->RedfishServiceIpPort == 0) || (IsHttps == TRUE)) {
+ AsciiSPrintUnicodeFormat (
+ RedfishServiceLocateStr,
+ sizeof (RedfishServiceLocateStr),
+ L"%s",
+ Ipv6Str
);
} else {
- AsciiSPrintUnicodeFormat(
- RedfishServiceLocateStr,
- sizeof (RedfishServiceLocateStr),
- L"[%s]:%d",
- Ipv6Str,
- Data->RedfishServiceIpPort
+ AsciiSPrintUnicodeFormat (
+ RedfishServiceLocateStr,
+ sizeof (RedfishServiceLocateStr),
+ L"[%s]:%d",
+ Ipv6Str,
+ Data->RedfishServiceIpPort
);
}
} else {
- if (Data->RedfishServiceIpPort == 0 || IsHttps == TRUE) {
- AsciiSPrint(
+ if ((Data->RedfishServiceIpPort == 0) || (IsHttps == TRUE)) {
+ AsciiSPrint (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
"%d.%d.%d.%d",
- Data->RedfishServiceIpAddress [0],
- Data->RedfishServiceIpAddress [1],
- Data->RedfishServiceIpAddress [2],
- Data->RedfishServiceIpAddress [3]
+ Data->RedfishServiceIpAddress[0],
+ Data->RedfishServiceIpAddress[1],
+ Data->RedfishServiceIpAddress[2],
+ Data->RedfishServiceIpAddress[3]
);
} else {
- AsciiSPrint(
+ AsciiSPrint (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
"%d.%d.%d.%d:%d",
- Data->RedfishServiceIpAddress [0],
- Data->RedfishServiceIpAddress [1],
- Data->RedfishServiceIpAddress [2],
- Data->RedfishServiceIpAddress [3],
+ Data->RedfishServiceIpAddress[0],
+ Data->RedfishServiceIpAddress[1],
+ Data->RedfishServiceIpAddress[2],
+ Data->RedfishServiceIpAddress[3],
Data->RedfishServiceIpPort
);
}
- }
+ }
+
Status = AddAndSignalNewRedfishService (
- Instance,
- NULL,
- RedfishServiceLocateStr,
- UuidStr,
- NULL,
- NULL,
- NULL,
- NULL,
- IsHttps
- );
+ Instance,
+ NULL,
+ RedfishServiceLocateStr,
+ UuidStr,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ IsHttps
+ );
}
}
+
return Status;
}
@@ -548,43 +586,44 @@ DiscoverRedfishHostInterface (IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Insta **/
EFI_STATUS
AddAndSignalNewRedfishService (
- IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
- IN UINTN *RedfishVersion OPTIONAL,
- IN CHAR8 *RedfishLocation OPTIONAL,
- IN CHAR8 *Uuid OPTIONAL,
- IN CHAR8 *Os OPTIONAL,
- IN CHAR8 *OsVer OPTIONAL,
- IN CHAR8 *Product OPTIONAL,
- IN CHAR8 *ProductVer OPTIONAL,
- IN BOOLEAN UseHttps
+ IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
+ IN UINTN *RedfishVersion OPTIONAL,
+ IN CHAR8 *RedfishLocation OPTIONAL,
+ IN CHAR8 *Uuid OPTIONAL,
+ IN CHAR8 *Os OPTIONAL,
+ IN CHAR8 *OsVer OPTIONAL,
+ IN CHAR8 *Product OPTIONAL,
+ IN CHAR8 *ProductVer OPTIONAL,
+ IN BOOLEAN UseHttps
)
{
- BOOLEAN NewFound;
- BOOLEAN InfoRefresh;
- BOOLEAN RestExOpened;
- BOOLEAN DeleteRestEx;
- EFI_STATUS Status;
- EFI_REDFISH_DISCOVERED_INTERNAL_LIST *DiscoveredList;
- EFI_REDFISH_DISCOVERED_INSTANCE *DiscoveredInstance;
- CHAR16 *Char16Uuid;
- EFI_REST_EX_PROTOCOL *RestEx;
- EFI_REST_EX_HTTP_CONFIG_DATA *RestExHttpConfigData;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface;
-
- NewFound = TRUE;
- InfoRefresh = FALSE;
- Char16Uuid = NULL;
+ BOOLEAN NewFound;
+ BOOLEAN InfoRefresh;
+ BOOLEAN RestExOpened;
+ BOOLEAN DeleteRestEx;
+ EFI_STATUS Status;
+ EFI_REDFISH_DISCOVERED_INTERNAL_LIST *DiscoveredList;
+ EFI_REDFISH_DISCOVERED_INSTANCE *DiscoveredInstance;
+ CHAR16 *Char16Uuid;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ EFI_REST_EX_HTTP_CONFIG_DATA *RestExHttpConfigData;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface;
+
+ NewFound = TRUE;
+ InfoRefresh = FALSE;
+ Char16Uuid = NULL;
RestExOpened = FALSE;
DeleteRestEx = FALSE;
- DEBUG ((DEBUG_INFO,"%a:Add this instance to Redfish instance list.\n", __FUNCTION__));
+ DEBUG ((DEBUG_INFO, "%a:Add this instance to Redfish instance list.\n", __FUNCTION__));
if (Uuid != NULL) {
- Char16Uuid = (CHAR16 *)AllocateZeroPool(AsciiStrSize((const CHAR8 *)Uuid) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, Char16Uuid, AsciiStrSize((const CHAR8 *)Uuid) * sizeof(CHAR16));
+ Char16Uuid = (CHAR16 *)AllocateZeroPool (AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, Char16Uuid, AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
}
- DiscoveredList = NULL;
- DiscoveredInstance = NULL;
+
+ DiscoveredList = NULL;
+ DiscoveredInstance = NULL;
RestExHttpConfigData = NULL;
NetworkInterface = Instance->NetworkInterface;
@@ -593,32 +632,36 @@ AddAndSignalNewRedfishService ( // Is this a duplicate redfish service.
//
DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetFirstNode (&mRedfishInstanceList);
- NewFound = FALSE;
+ NewFound = FALSE;
do {
- if (Char16Uuid == NULL || DiscoveredList->Instance->Information.Uuid == NULL) {
+ if ((Char16Uuid == NULL) || (DiscoveredList->Instance->Information.Uuid == NULL)) {
//
// Check if this Redfish instance already found using IP addrress.
//
- if (!CheckIsIpVersion6(NetworkInterface)) {
- if (CompareMem ((VOID *)&Instance->TargetIpAddress.v4,
- (VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v4,
- sizeof (EFI_IPv4_ADDRESS)
- ) == 0)
+ if (!CheckIsIpVersion6 (NetworkInterface)) {
+ if (CompareMem (
+ (VOID *)&Instance->TargetIpAddress.v4,
+ (VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v4,
+ sizeof (EFI_IPv4_ADDRESS)
+ ) == 0)
{
DiscoveredInstance = DiscoveredList->Instance;
- if (DiscoveredList->Instance->Information.Uuid == NULL &&
- Char16Uuid != NULL) {
- InfoRefresh = TRUE;
+ if ((DiscoveredList->Instance->Information.Uuid == NULL) &&
+ (Char16Uuid != NULL))
+ {
+ InfoRefresh = TRUE;
DiscoveredInstance = DiscoveredList->Instance;
- DEBUG((DEBUG_INFO,"*** This Redfish Service information refresh ***\n"));
+ DEBUG ((DEBUG_INFO, "*** This Redfish Service information refresh ***\n"));
}
+
break;
}
} else {
- if (CompareMem ((VOID *)&Instance->TargetIpAddress.v6,
- (VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v6,
- sizeof (EFI_IPv6_ADDRESS)
- ) == 0)
+ if (CompareMem (
+ (VOID *)&Instance->TargetIpAddress.v6,
+ (VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v6,
+ sizeof (EFI_IPv6_ADDRESS)
+ ) == 0)
{
DiscoveredInstance = DiscoveredList->Instance;
break;
@@ -628,88 +671,101 @@ AddAndSignalNewRedfishService ( //
// Check if this Redfish instance already found using UUID.
//
- if (StrCmp((const CHAR16 *)Char16Uuid, (const CHAR16 *)DiscoveredList->Instance->Information.Uuid) == 0) {
+ if (StrCmp ((const CHAR16 *)Char16Uuid, (const CHAR16 *)DiscoveredList->Instance->Information.Uuid) == 0) {
DiscoveredInstance = DiscoveredList->Instance;
break;
}
}
+
if (IsNodeAtEnd (&mRedfishInstanceList, &DiscoveredList->NextInstance)) {
NewFound = TRUE;
break;
}
+
DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetNextNode (&mRedfishInstanceList, &DiscoveredList->NextInstance);
} while (TRUE);
}
+
if (NewFound || InfoRefresh) {
if (!InfoRefresh) {
- DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)AllocateZeroPool(sizeof(EFI_REDFISH_DISCOVERED_INTERNAL_LIST));
+ DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_INTERNAL_LIST));
if (DiscoveredList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
InitializeListHead (&DiscoveredList->NextInstance);
- DiscoveredInstance = (EFI_REDFISH_DISCOVERED_INSTANCE *)AllocateZeroPool(sizeof(EFI_REDFISH_DISCOVERED_INSTANCE));
+ DiscoveredInstance = (EFI_REDFISH_DISCOVERED_INSTANCE *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_INSTANCE));
if (DiscoveredInstance == NULL) {
FreePool ((VOID *)DiscoveredList);
return EFI_OUT_OF_RESOURCES;
}
}
- DEBUG ((DEBUG_INFO,"*** Redfish Service Information ***\n"));
+
+ DEBUG ((DEBUG_INFO, "*** Redfish Service Information ***\n"));
DiscoveredInstance->Information.UseHttps = UseHttps;
if (RedfishVersion != NULL) {
DiscoveredInstance->Information.RedfishVersion = *RedfishVersion;
- DEBUG ((DEBUG_INFO,"Redfish service version: %d.\n", DiscoveredInstance->Information.RedfishVersion));
+ DEBUG ((DEBUG_INFO, "Redfish service version: %d.\n", DiscoveredInstance->Information.RedfishVersion));
}
+
if (RedfishLocation != NULL) {
- DiscoveredInstance->Information.Location = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)RedfishLocation) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)RedfishLocation, DiscoveredInstance->Information.Location, AsciiStrSize((const CHAR8 *)RedfishLocation) * sizeof(CHAR16));
- DEBUG ((DEBUG_INFO,"Redfish service location: %s.\n", DiscoveredInstance->Information.Location));
+ DiscoveredInstance->Information.Location = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)RedfishLocation, DiscoveredInstance->Information.Location, AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
+ DEBUG ((DEBUG_INFO, "Redfish service location: %s.\n", DiscoveredInstance->Information.Location));
}
+
if (Uuid != NULL) {
- DiscoveredInstance->Information.Uuid = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)Uuid) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, DiscoveredInstance->Information.Uuid, AsciiStrSize((const CHAR8 *)Uuid) * sizeof(CHAR16));
- DEBUG ((DEBUG_INFO,"Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
+ DiscoveredInstance->Information.Uuid = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, DiscoveredInstance->Information.Uuid, AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
+ DEBUG ((DEBUG_INFO, "Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
}
+
if (Os != NULL) {
- DiscoveredInstance->Information.Os = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)Os) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)Os, DiscoveredInstance->Information.Os, AsciiStrSize((const CHAR8 *)Os) * sizeof(CHAR16));
- DEBUG ((DEBUG_INFO,"Redfish service OS: %s, Version:%s.\n", DiscoveredInstance->Information.Os, DiscoveredInstance->Information.OsVersion));
+ DiscoveredInstance->Information.Os = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)Os, DiscoveredInstance->Information.Os, AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
+ DEBUG ((DEBUG_INFO, "Redfish service OS: %s, Version:%s.\n", DiscoveredInstance->Information.Os, DiscoveredInstance->Information.OsVersion));
}
+
if (OsVer != NULL) {
- DiscoveredInstance->Information.OsVersion = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)OsVer) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)OsVer, DiscoveredInstance->Information.OsVersion, AsciiStrSize((const CHAR8 *)OsVer) * sizeof(CHAR16));
+ DiscoveredInstance->Information.OsVersion = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)OsVer, DiscoveredInstance->Information.OsVersion, AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
}
- if (Product != NULL && ProductVer != NULL) {
- DiscoveredInstance->Information.Product = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)Product) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)Product, DiscoveredInstance->Information.Product, AsciiStrSize((const CHAR8 *)Product) * sizeof(CHAR16));
- DiscoveredInstance->Information.ProductVer = (CHAR16 *)AllocatePool(AsciiStrSize((const CHAR8 *)ProductVer) * sizeof(CHAR16));
- AsciiStrToUnicodeStrS ((const CHAR8 *)ProductVer, DiscoveredInstance->Information.ProductVer, AsciiStrSize((const CHAR8 *)ProductVer) * sizeof(CHAR16));
- DEBUG ((DEBUG_INFO,"Redfish service product: %s, Version:%s.\n", DiscoveredInstance->Information.Product, DiscoveredInstance->Information.ProductVer));
+
+ if ((Product != NULL) && (ProductVer != NULL)) {
+ DiscoveredInstance->Information.Product = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)Product, DiscoveredInstance->Information.Product, AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
+ DiscoveredInstance->Information.ProductVer = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
+ AsciiStrToUnicodeStrS ((const CHAR8 *)ProductVer, DiscoveredInstance->Information.ProductVer, AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
+ DEBUG ((DEBUG_INFO, "Redfish service product: %s, Version:%s.\n", DiscoveredInstance->Information.Product, DiscoveredInstance->Information.ProductVer));
}
if (RedfishLocation == NULL) {
// This is the Redfish reported from SMBIOS 42h
// without validation.
- IP4_COPY_ADDRESS((VOID *)&DiscoveredInstance->Information.RedfishHostIpAddress.v4, (VOID *)&Instance->TargetIpAddress.v4);
+ IP4_COPY_ADDRESS ((VOID *)&DiscoveredInstance->Information.RedfishHostIpAddress.v4, (VOID *)&Instance->TargetIpAddress.v4);
}
+
if (!InfoRefresh) {
DiscoveredList->Instance = DiscoveredInstance;
- InsertTailList(&mRedfishInstanceList, &DiscoveredList->NextInstance);
+ InsertTailList (&mRedfishInstanceList, &DiscoveredList->NextInstance);
}
+
DiscoveredInstance->Status = EFI_SUCCESS;
} else {
if (DiscoveredList != NULL) {
- DEBUG((DEBUG_INFO,"*** This Redfish Service was already found ***\n"));
+ DEBUG ((DEBUG_INFO, "*** This Redfish Service was already found ***\n"));
if (DiscoveredInstance->Information.Uuid != NULL) {
- DEBUG((DEBUG_INFO,"Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
+ DEBUG ((DEBUG_INFO, "Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
} else {
- DEBUG((DEBUG_INFO,"Service UUID: unknown.\n"));
+ DEBUG ((DEBUG_INFO, "Service UUID: unknown.\n"));
}
}
}
+
if (Char16Uuid != NULL) {
- FreePool((VOID *)Char16Uuid);
+ FreePool ((VOID *)Char16Uuid);
}
Status = EFI_SUCCESS;
@@ -718,36 +774,40 @@ AddAndSignalNewRedfishService ( // Build up EFI_REDFISH_DISCOVERED_LIST in token.
//
Instance->DiscoverToken->DiscoverList.NumberOfServiceFound = 1;
- Instance->DiscoverToken->DiscoverList.RedfishInstances = DiscoveredInstance;
- DiscoveredInstance->Status = EFI_SUCCESS;
+ Instance->DiscoverToken->DiscoverList.RedfishInstances = DiscoveredInstance;
+ DiscoveredInstance->Status = EFI_SUCCESS;
if (!InfoRefresh) {
Status = CreateRestExInstance (Instance, Instance->DiscoverToken); // Create REST EX child.
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a:Can't create REST EX child instance.\n",__FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:Can't create REST EX child instance.\n", __FUNCTION__));
goto ON_EXIT;
}
- Status = gBS->OpenProtocol ( // Configure local host information.
- Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
- &gEfiRestExProtocolGuid,
- (VOID **)&RestEx,
- Instance->NetworkInterface->OpenDriverAgentHandle,
- Instance->NetworkInterface->OpenDriverControllerHandle,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
+
+ Status = gBS->OpenProtocol (
+ // Configure local host information.
+ Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
+ &gEfiRestExProtocolGuid,
+ (VOID **)&RestEx,
+ Instance->NetworkInterface->OpenDriverAgentHandle,
+ Instance->NetworkInterface->OpenDriverControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
if (EFI_ERROR (Status)) {
DeleteRestEx = TRUE;
goto ERROR_EXIT;
}
- RestExOpened = TRUE;
+
+ RestExOpened = TRUE;
RestExHttpConfigData = AllocateZeroPool (sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
if (RestExHttpConfigData == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ Status = EFI_OUT_OF_RESOURCES;
DeleteRestEx = TRUE;
goto EXIT_FREE_CONFIG_DATA;
}
- RestExHttpConfigData->SendReceiveTimeout = 5000;
- RestExHttpConfigData->HttpConfigData.HttpVersion = HttpVersion11;
- RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6 = CheckIsIpVersion6(NetworkInterface);
+
+ RestExHttpConfigData->SendReceiveTimeout = 5000;
+ RestExHttpConfigData->HttpConfigData.HttpVersion = HttpVersion11;
+ RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6 = CheckIsIpVersion6 (NetworkInterface);
if (RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6) {
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv6Node = AllocateZeroPool (sizeof (EFI_HTTPv6_ACCESS_POINT));
if (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv6Node == NULL) {
@@ -760,62 +820,69 @@ AddAndSignalNewRedfishService ( Status = EFI_OUT_OF_RESOURCES;
goto EXIT_FREE_CONFIG_DATA;
}
+
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node->UseDefaultAddress = TRUE;
}
+
Status = RestEx->Configure (
- RestEx,
- (EFI_REST_EX_CONFIG_DATA)(UINT8 *)RestExHttpConfigData
- );
+ RestEx,
+ (EFI_REST_EX_CONFIG_DATA)(UINT8 *)RestExHttpConfigData
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR,"%a:REST EX configured..\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:REST EX configured..\n", __FUNCTION__));
DeleteRestEx = TRUE;
goto EXIT_FREE_ALL;
}
+
//
// Signal client, close REST EX before signaling client.
//
if (RestExOpened) {
- gBS->CloseProtocol(
- Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
- &gEfiRestExProtocolGuid,
- Instance->NetworkInterface->OpenDriverAgentHandle,
- Instance->NetworkInterface->OpenDriverControllerHandle
- );
+ gBS->CloseProtocol (
+ Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
+ &gEfiRestExProtocolGuid,
+ Instance->NetworkInterface->OpenDriverAgentHandle,
+ Instance->NetworkInterface->OpenDriverControllerHandle
+ );
RestExOpened = FALSE;
}
}
- Status = gBS->SignalEvent(Instance->DiscoverToken->Event);
+
+ Status = gBS->SignalEvent (Instance->DiscoverToken->Event);
if (!EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR,"%a:No event to signal!\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:No event to signal!\n", __FUNCTION__));
}
}
EXIT_FREE_ALL:;
- if (RestExHttpConfigData != NULL && RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node != NULL) {
+ if ((RestExHttpConfigData != NULL) && (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node != NULL)) {
FreePool (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node);
}
EXIT_FREE_CONFIG_DATA:;
if (RestExHttpConfigData != NULL) {
- FreePool((VOID *)RestExHttpConfigData);
+ FreePool ((VOID *)RestExHttpConfigData);
}
+
if (RestExOpened) {
- gBS->CloseProtocol(
+ gBS->CloseProtocol (
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle
- );
+ );
}
+
ERROR_EXIT:;
- if (DeleteRestEx && RestExOpened) {
- gBS->CloseProtocol(
+ if (DeleteRestEx && RestExOpened) {
+ gBS->CloseProtocol (
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle
- );
- }
+ );
+ }
+
ON_EXIT:;
return Status;
}
@@ -832,48 +899,52 @@ ON_EXIT:; **/
EFI_STATUS
NetworkInterfaceGetSubnetInfo (
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance,
- IN EFI_HANDLE ImageHandle
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance,
+ IN EFI_HANDLE ImageHandle
)
{
- EFI_STATUS Status;
- UINT32 ProtocolType;
- UINT32 IPv6InfoIndex;
- EFI_IP6_ADDRESS_INFO *ThisSubnetAddrInfoIPv6;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NewNetworkInterface;
+ EFI_STATUS Status;
+ UINT32 ProtocolType;
+ UINT32 IPv6InfoIndex;
+ EFI_IP6_ADDRESS_INFO *ThisSubnetAddrInfoIPv6;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NewNetworkInterface;
if (Instance->GotSubnetInfo) {
return EFI_SUCCESS;
}
ProtocolType = Instance->NetworkProtocolType;
- if (gRequiredProtocol [ProtocolType].GetSubnetInfo != NULL && Instance->GotSubnetInfo == FALSE) {
- Status = gRequiredProtocol [ProtocolType].GetSubnetInfo (
- ImageHandle,
- Instance
- );
+ if ((gRequiredProtocol[ProtocolType].GetSubnetInfo != NULL) && (Instance->GotSubnetInfo == FALSE)) {
+ Status = gRequiredProtocol[ProtocolType].GetSubnetInfo (
+ ImageHandle,
+ Instance
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR,"%a:Faile to get Subnet infomation.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:Faile to get Subnet infomation.\n", __FUNCTION__));
return Status;
} else {
- DEBUG ((DEBUG_INFO,"%a:MAC address: %s\n", __FUNCTION__, Instance->StrMacAddr));
+ DEBUG ((DEBUG_INFO, "%a:MAC address: %s\n", __FUNCTION__, Instance->StrMacAddr));
if (CheckIsIpVersion6 (Instance)) {
if (Instance->SubnetAddrInfoIPv6Number == 0) {
- DEBUG ((DEBUG_ERROR,"%a: There is no Subnet infomation for IPv6 network interface.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a: There is no Subnet infomation for IPv6 network interface.\n", __FUNCTION__));
return EFI_NOT_FOUND;
}
+
ThisSubnetAddrInfoIPv6 = Instance->SubnetAddrInfoIPv6; // First IPv6 address information.
IP6_COPY_ADDRESS (&Instance->SubnetAddr.v6, &ThisSubnetAddrInfoIPv6->Address);
Instance->SubnetPrefixLength = ThisSubnetAddrInfoIPv6->PrefixLength;
- DEBUG((DEBUG_INFO," IPv6 Subnet ID:%d, Prefix length: %d.\n",
- ThisSubnetAddrInfoIPv6->Address.Addr [7] + (UINT16)ThisSubnetAddrInfoIPv6->Address.Addr [6] * 256,
- ThisSubnetAddrInfoIPv6->PrefixLength)
- );
+ DEBUG ((
+ DEBUG_INFO,
+ " IPv6 Subnet ID:%d, Prefix length: %d.\n",
+ ThisSubnetAddrInfoIPv6->Address.Addr[7] + (UINT16)ThisSubnetAddrInfoIPv6->Address.Addr[6] * 256,
+ ThisSubnetAddrInfoIPv6->PrefixLength
+ )
+ );
//
// If this is IPv6, then we may have to propagate network interface for IPv6 network scopes
// according to the Ipv6 address information.
//
- ThisSubnetAddrInfoIPv6 ++;
+ ThisSubnetAddrInfoIPv6++;
for (IPv6InfoIndex = 0; IPv6InfoIndex < Instance->SubnetAddrInfoIPv6Number - 1; IPv6InfoIndex++) {
//
// Build up addtional EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instances.
@@ -883,32 +954,38 @@ NetworkInterfaceGetSubnetInfo ( CopyMem ((VOID *)NewNetworkInterface, (VOID *)Instance, sizeof (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL)); // Clone information of first instance.
IP6_COPY_ADDRESS (&NewNetworkInterface->SubnetAddr.v6, &ThisSubnetAddrInfoIPv6->Address);
NewNetworkInterface->SubnetPrefixLength = ThisSubnetAddrInfoIPv6->PrefixLength;
- NewNetworkInterface->GotSubnetInfo = TRUE;
+ NewNetworkInterface->GotSubnetInfo = TRUE;
InsertTailList (&mEfiRedfishDiscoverNetworkInterface, &NewNetworkInterface->Entry);
- ThisSubnetAddrInfoIPv6 ++;
- mNumNetworkInterface ++;
- DEBUG((DEBUG_INFO," IPv6 Subnet ID:%d, Prefix length: %d.\n",
- ThisSubnetAddrInfoIPv6->Address.Addr [7] + (UINT16)ThisSubnetAddrInfoIPv6->Address.Addr [6] * 256,
- ThisSubnetAddrInfoIPv6->PrefixLength)
- );
+ ThisSubnetAddrInfoIPv6++;
+ mNumNetworkInterface++;
+ DEBUG ((
+ DEBUG_INFO,
+ " IPv6 Subnet ID:%d, Prefix length: %d.\n",
+ ThisSubnetAddrInfoIPv6->Address.Addr[7] + (UINT16)ThisSubnetAddrInfoIPv6->Address.Addr[6] * 256,
+ ThisSubnetAddrInfoIPv6->PrefixLength
+ )
+ );
} else {
return EFI_OUT_OF_RESOURCES;
}
}
} else {
- DEBUG ((DEBUG_INFO," IPv4 Subnet:%d.%d.%d.%d Subnet mask: %d.%d.%d.%d.\n",
- Instance->SubnetAddr.v4.Addr [0],
- Instance->SubnetAddr.v4.Addr [1],
- Instance->SubnetAddr.v4.Addr [2],
- Instance->SubnetAddr.v4.Addr [3],
- Instance->SubnetMask.v4.Addr [0],
- Instance->SubnetMask.v4.Addr [1],
- Instance->SubnetMask.v4.Addr [2],
- Instance->SubnetMask.v4.Addr [3]
- ));
+ DEBUG ((
+ DEBUG_INFO,
+ " IPv4 Subnet:%d.%d.%d.%d Subnet mask: %d.%d.%d.%d.\n",
+ Instance->SubnetAddr.v4.Addr[0],
+ Instance->SubnetAddr.v4.Addr[1],
+ Instance->SubnetAddr.v4.Addr[2],
+ Instance->SubnetAddr.v4.Addr[3],
+ Instance->SubnetMask.v4.Addr[0],
+ Instance->SubnetMask.v4.Addr[1],
+ Instance->SubnetMask.v4.Addr[2],
+ Instance->SubnetMask.v4.Addr[3]
+ ));
}
}
}
+
Instance->GotSubnetInfo = TRUE; // Only try to get Subnet Info once.
return EFI_SUCCESS;
}
@@ -933,23 +1010,23 @@ NetworkInterfaceGetSubnetInfo ( EFI_STATUS
EFIAPI
RedfishServiceGetNetworkInterface (
- IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
- IN EFI_HANDLE ImageHandle,
- OUT UINTN *NumberOfNetworkIntfs,
- OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE **NetworkIntfInstances
-)
+ IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
+ IN EFI_HANDLE ImageHandle,
+ OUT UINTN *NumberOfNetworkIntfs,
+ OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE **NetworkIntfInstances
+ )
{
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterfaceIntn;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterfaceIntn;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
- if (NetworkIntfInstances == NULL || NumberOfNetworkIntfs == NULL || ImageHandle == NULL) {
+ if ((NetworkIntfInstances == NULL) || (NumberOfNetworkIntfs == NULL) || (ImageHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
*NumberOfNetworkIntfs = 0;
*NetworkIntfInstances = NULL;
- if (IsListEmpty ((const LIST_ENTRY*)&mEfiRedfishDiscoverNetworkInterface)) {
+ if (IsListEmpty ((const LIST_ENTRY *)&mEfiRedfishDiscoverNetworkInterface)) {
return EFI_NOT_FOUND;
}
@@ -957,31 +1034,37 @@ RedfishServiceGetNetworkInterface ( if (ThisNetworkInterface == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- *NetworkIntfInstances = ThisNetworkInterface;
+
+ *NetworkIntfInstances = ThisNetworkInterface;
ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
ThisNetworkInterface->IsIpv6 = FALSE;
if (CheckIsIpVersion6 (ThisNetworkInterfaceIntn)) {
ThisNetworkInterface->IsIpv6 = TRUE;
}
- CopyMem((VOID *)&ThisNetworkInterface->MacAddress, &ThisNetworkInterfaceIntn->MacAddress, ThisNetworkInterfaceIntn->HwAddressSize);
- NetworkInterfaceGetSubnetInfo(ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info.
+
+ CopyMem ((VOID *)&ThisNetworkInterface->MacAddress, &ThisNetworkInterfaceIntn->MacAddress, ThisNetworkInterfaceIntn->HwAddressSize);
+ NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info.
if (!ThisNetworkInterface->IsIpv6) {
- IP4_COPY_ADDRESS(&ThisNetworkInterface->SubnetId.v4, &ThisNetworkInterfaceIntn->SubnetAddr.v4); // IPv4 subnet information.
+ IP4_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v4, &ThisNetworkInterfaceIntn->SubnetAddr.v4); // IPv4 subnet information.
} else {
IP6_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v6, &ThisNetworkInterfaceIntn->SubnetAddr.v6); // IPv6 subnet information in IPv6 address information.
}
+
ThisNetworkInterface->SubnetPrefixLength = ThisNetworkInterfaceIntn->SubnetPrefixLength;
- ThisNetworkInterface->VlanId = ThisNetworkInterfaceIntn->VlanId;
- (*NumberOfNetworkIntfs) ++;
+ ThisNetworkInterface->VlanId = ThisNetworkInterfaceIntn->VlanId;
+ (*NumberOfNetworkIntfs)++;
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry)) {
break;
}
- ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry);
- ThisNetworkInterface ++;
- };
+
+ ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry);
+ ThisNetworkInterface++;
+ }
+
return EFI_SUCCESS;
}
+
/**
This function acquires Redfish services by discovering static Redfish setting
according to Redfish Host Interface or through SSDP. Returns a list of EFI
@@ -1009,61 +1092,65 @@ RedfishServiceGetNetworkInterface ( EFI_STATUS
EFIAPI
RedfishServiceAcquireService (
- IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
- IN EFI_HANDLE ImageHandle,
+ IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
+ IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface,
- IN EFI_REDFISH_DISCOVER_FLAG Flags,
- IN EFI_REDFISH_DISCOVERED_TOKEN *Token
+ IN EFI_REDFISH_DISCOVER_FLAG Flags,
+ IN EFI_REDFISH_DISCOVERED_TOKEN *Token
)
{
- EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance;
- EFI_STATUS Status1;
- EFI_STATUS Status2;
- BOOLEAN NewInstance;
- UINTN NumNetworkInterfaces;
- UINTN NetworkInterfacesIndex;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *TargetNetworkInterfaceInternal;
+ EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance;
+ EFI_STATUS Status1;
+ EFI_STATUS Status2;
+ BOOLEAN NewInstance;
+ UINTN NumNetworkInterfaces;
+ UINTN NetworkInterfacesIndex;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *TargetNetworkInterfaceInternal;
- DEBUG ((DEBUG_INFO,"%a:Entry.\n", __FUNCTION__));
+ DEBUG ((DEBUG_INFO, "%a:Entry.\n", __FUNCTION__));
//
// Validate parameters.
//
- if (ImageHandle == NULL || Token == NULL || ((Flags & ~EFI_REDFISH_DISCOVER_VALIDATION) == 0)) {
- DEBUG ((DEBUG_ERROR,"%a:Invalid parameters.\n", __FUNCTION__));
+ if ((ImageHandle == NULL) || (Token == NULL) || ((Flags & ~EFI_REDFISH_DISCOVER_VALIDATION) == 0)) {
+ DEBUG ((DEBUG_ERROR, "%a:Invalid parameters.\n", __FUNCTION__));
return EFI_INVALID_PARAMETER;
}
+
//
// Validate target network interface.
//
if (EFI_ERROR (ValidateTargetNetworkInterface (TargetNetworkInterface, Flags))) {
- return EFI_UNSUPPORTED;
+ return EFI_UNSUPPORTED;
}
+
if (TargetNetworkInterface != NULL) {
TargetNetworkInterfaceInternal = GetTargetNetworkInterfaceInternal (TargetNetworkInterface);
- NumNetworkInterfaces = 1;
+ NumNetworkInterfaces = 1;
} else {
TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
- NumNetworkInterfaces = NumberOfNetworkInterface ();
+ NumNetworkInterfaces = NumberOfNetworkInterface ();
if (NumNetworkInterfaces == 0) {
- DEBUG ((DEBUG_ERROR,"%a:No network interface on platform.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:No network interface on platform.\n", __FUNCTION__));
return EFI_UNSUPPORTED;
}
}
- for (NetworkInterfacesIndex = 0; NetworkInterfacesIndex < NumNetworkInterfaces; NetworkInterfacesIndex ++) {
- Status1 = EFI_SUCCESS;
- Status2 = EFI_SUCCESS;
+
+ for (NetworkInterfacesIndex = 0; NetworkInterfacesIndex < NumNetworkInterfaces; NetworkInterfacesIndex++) {
+ Status1 = EFI_SUCCESS;
+ Status2 = EFI_SUCCESS;
NewInstance = FALSE;
- Instance = GetInstanceByOwner (ImageHandle, TargetNetworkInterfaceInternal, Flags & ~EFI_REDFISH_DISCOVER_VALIDATION); // Check if we can re-use previous instance.
+ Instance = GetInstanceByOwner (ImageHandle, TargetNetworkInterfaceInternal, Flags & ~EFI_REDFISH_DISCOVER_VALIDATION); // Check if we can re-use previous instance.
if (Instance == NULL) {
- DEBUG ((DEBUG_INFO,"%a:Create new EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE.\n", __FUNCTION__));
- Instance = (EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)AllocateZeroPool(sizeof(EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE));
+ DEBUG ((DEBUG_INFO, "%a:Create new EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE.\n", __FUNCTION__));
+ Instance = (EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE));
if (Instance == NULL) {
- DEBUG ((DEBUG_ERROR,"%a:Memory allocation fail.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:Memory allocation fail.\n", __FUNCTION__));
}
+
InitializeListHead (&Instance->Entry);
- Instance->Owner = ImageHandle;
- Instance->DiscoverFlags = Flags & ~EFI_REDFISH_DISCOVER_VALIDATION;
+ Instance->Owner = ImageHandle;
+ Instance->DiscoverFlags = Flags & ~EFI_REDFISH_DISCOVER_VALIDATION;
Instance->NetworkInterface = TargetNetworkInterfaceInternal;
//
// Get subnet information in case subnet information is not set because
@@ -1072,41 +1159,46 @@ RedfishServiceAcquireService ( NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal, ImageHandle);
NewInstance = TRUE;
}
+
if (TargetNetworkInterfaceInternal->StrMacAddr != NULL) {
- DEBUG((DEBUG_INFO,"%a:Acquire Redfish service on network interface MAC address:%s.\n", __FUNCTION__, TargetNetworkInterfaceInternal->StrMacAddr));
+ DEBUG ((DEBUG_INFO, "%a:Acquire Redfish service on network interface MAC address:%s.\n", __FUNCTION__, TargetNetworkInterfaceInternal->StrMacAddr));
} else {
- DEBUG((DEBUG_INFO,"%a:WARNING: No MAC address on this network interface.\n", __FUNCTION__));
+ DEBUG ((DEBUG_INFO, "%a:WARNING: No MAC address on this network interface.\n", __FUNCTION__));
}
Instance->DiscoverToken = Token; // Always use the latest Token passed by caller.
if ((Flags & EFI_REDFISH_DISCOVER_HOST_INTERFACE) != 0) {
- DEBUG ((DEBUG_INFO,"%a:Redfish HOST interface discovery.\n", __FUNCTION__));
+ DEBUG ((DEBUG_INFO, "%a:Redfish HOST interface discovery.\n", __FUNCTION__));
Instance->HostIntfValidation = FALSE;
if ((Flags & EFI_REDFISH_DISCOVER_VALIDATION) != 0) {
Instance->HostIntfValidation = TRUE;
}
+
Status1 = DiscoverRedfishHostInterface (Instance); // Discover Redfish service through Redfish Host Interface.
}
+
if ((Flags & EFI_REDFISH_DISCOVER_SSDP) != 0) {
- DEBUG ((DEBUG_ERROR,"%a:Redfish service discovery through SSDP is not supported\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:Redfish service discovery through SSDP is not supported\n", __FUNCTION__));
return EFI_UNSUPPORTED;
} else {
if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) {
FreePool ((VOID *)Instance);
- DEBUG ((DEBUG_ERROR,"%a:Something wrong on Redfish service discovery Status1=%x, Status2=%x.\n", __FUNCTION__, Status1, Status2));
+ DEBUG ((DEBUG_ERROR, "%a:Something wrong on Redfish service discovery Status1=%x, Status2=%x.\n", __FUNCTION__, Status1, Status2));
} else {
if (NewInstance) {
- InsertTailList(&mRedfishDiscoverList, &Instance->Entry);
+ InsertTailList (&mRedfishDiscoverList, &Instance->Entry);
}
}
}
+
if (TargetNetworkInterface == NULL) {
//
// Discover Redfish services on all of network interfaces.
//
- TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &TargetNetworkInterfaceInternal->Entry);
+ TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &TargetNetworkInterfaceInternal->Entry);
}
}
+
return EFI_SUCCESS;
}
@@ -1123,9 +1215,9 @@ RedfishServiceAcquireService ( EFI_STATUS
EFIAPI
RedfishServiceAbortAcquire (
- IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
+ IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface OPTIONAL
-)
+ )
{
// This function is used to abort Redfish service discovery through SSDP
// on the network interface. SSDP is optionally supprted by EFI_REDFISH_DISCOVER_PROTOCOL,
@@ -1147,53 +1239,62 @@ RedfishServiceAbortAcquire ( EFI_STATUS
EFIAPI
RedfishServiceReleaseService (
- IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
- IN EFI_REDFISH_DISCOVERED_LIST *InstanceList
+ IN EFI_REDFISH_DISCOVER_PROTOCOL *This,
+ IN EFI_REDFISH_DISCOVERED_LIST *InstanceList
)
{
- UINTN NumService;
- BOOLEAN AnyFailRelease;
- EFI_REDFISH_DISCOVERED_INSTANCE *ThisRedfishInstance;
- EFI_REDFISH_DISCOVERED_INTERNAL_LIST *DiscoveredRedfishInstance;
+ UINTN NumService;
+ BOOLEAN AnyFailRelease;
+ EFI_REDFISH_DISCOVERED_INSTANCE *ThisRedfishInstance;
+ EFI_REDFISH_DISCOVERED_INTERNAL_LIST *DiscoveredRedfishInstance;
if (IsListEmpty (&mRedfishInstanceList)) {
- DEBUG ((DEBUG_ERROR,"%a:No any discovered Redfish service.\n", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a:No any discovered Redfish service.\n", __FUNCTION__));
return EFI_NOT_FOUND;
}
- AnyFailRelease = FALSE;
+
+ AnyFailRelease = FALSE;
ThisRedfishInstance = InstanceList->RedfishInstances;
- for (NumService = 0; NumService < InstanceList->NumberOfServiceFound; NumService ++) {
- DiscoveredRedfishInstance = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetFirstNode(&mRedfishInstanceList);
+ for (NumService = 0; NumService < InstanceList->NumberOfServiceFound; NumService++) {
+ DiscoveredRedfishInstance = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetFirstNode (&mRedfishInstanceList);
do {
if (DiscoveredRedfishInstance->Instance == ThisRedfishInstance) {
RemoveEntryList (&DiscoveredRedfishInstance->NextInstance);
if (ThisRedfishInstance->Information.Location != NULL) {
FreePool (ThisRedfishInstance->Information.Location);
}
+
if (ThisRedfishInstance->Information.Uuid != NULL) {
FreePool (ThisRedfishInstance->Information.Uuid);
}
+
if (ThisRedfishInstance->Information.Os != NULL) {
FreePool (ThisRedfishInstance->Information.Os);
}
+
if (ThisRedfishInstance->Information.OsVersion != NULL) {
FreePool (ThisRedfishInstance->Information.OsVersion);
}
+
if (ThisRedfishInstance->Information.Product != NULL) {
FreePool (ThisRedfishInstance->Information.Product);
}
+
if (ThisRedfishInstance->Information.ProductVer != NULL) {
FreePool (ThisRedfishInstance->Information.ProductVer);
}
- FreePool((VOID *)ThisRedfishInstance);
+
+ FreePool ((VOID *)ThisRedfishInstance);
goto ReleaseNext;
}
- if (IsNodeAtEnd(&mRedfishInstanceList, &DiscoveredRedfishInstance->NextInstance)) {
+ if (IsNodeAtEnd (&mRedfishInstanceList, &DiscoveredRedfishInstance->NextInstance)) {
break;
}
- DiscoveredRedfishInstance = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetNextNode(&mRedfishInstanceList, &DiscoveredRedfishInstance->NextInstance);
+
+ DiscoveredRedfishInstance = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetNextNode (&mRedfishInstanceList, &DiscoveredRedfishInstance->NextInstance);
} while (TRUE);
+
AnyFailRelease = TRUE;
ReleaseNext:;
//
@@ -1201,6 +1302,7 @@ ReleaseNext:; //
ThisRedfishInstance = (EFI_REDFISH_DISCOVERED_INSTANCE *)((UINT8 *)ThisRedfishInstance + sizeof (EFI_REDFISH_DISCOVERED_INSTANCE));
}
+
if (AnyFailRelease) {
return EFI_NOT_FOUND;
} else {
@@ -1208,7 +1310,7 @@ ReleaseNext:; }
}
-EFI_REDFISH_DISCOVER_PROTOCOL mRedfishDiscover = {
+EFI_REDFISH_DISCOVER_PROTOCOL mRedfishDiscover = {
RedfishServiceGetNetworkInterface,
RedfishServiceAcquireService,
RedfishServiceAbortAcquire,
@@ -1229,21 +1331,21 @@ EFI_REDFISH_DISCOVER_PROTOCOL mRedfishDiscover = { **/
EFI_STATUS
CreateRedfishDiscoverNetworkInterface (
- IN EFI_HANDLE ControllerHandle,
- IN UINT32 NetworkProtocolType,
- OUT BOOLEAN *IsNewInstance,
- OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL **NetworkInterface
+ IN EFI_HANDLE ControllerHandle,
+ IN UINT32 NetworkProtocolType,
+ OUT BOOLEAN *IsNewInstance,
+ OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL **NetworkInterface
)
{
- EFI_MAC_ADDRESS MacAddress;
- UINTN HwAddressSize;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NewNetworkInterface;
+ EFI_MAC_ADDRESS MacAddress;
+ UINTN HwAddressSize;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NewNetworkInterface;
NetLibGetMacAddress (ControllerHandle, &MacAddress, &HwAddressSize);
NewNetworkInterface = NULL;
- *IsNewInstance = TRUE;
- if (!IsListEmpty ((const LIST_ENTRY*)&mEfiRedfishDiscoverNetworkInterface)) {
+ *IsNewInstance = TRUE;
+ if (!IsListEmpty ((const LIST_ENTRY *)&mEfiRedfishDiscoverNetworkInterface)) {
//
// Check if this instance already exist.
//
@@ -1251,19 +1353,23 @@ CreateRedfishDiscoverNetworkInterface ( if (ThisNetworkInterface != NULL) {
while (TRUE) {
if ((CompareMem ((CONST VOID *)&ThisNetworkInterface->MacAddress.Addr, (CONST VOID *)&MacAddress.Addr, HwAddressSize) == 0) &&
- (ThisNetworkInterface->NetworkProtocolType == NetworkProtocolType)){
+ (ThisNetworkInterface->NetworkProtocolType == NetworkProtocolType))
+ {
NewNetworkInterface = ThisNetworkInterface;
- *IsNewInstance = FALSE;
+ *IsNewInstance = FALSE;
break;
}
+
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
NewNetworkInterface = NULL;
break;
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
- };
+
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
+ }
}
}
+
if (NewNetworkInterface == NULL) {
//
// Create a new instance.
@@ -1272,11 +1378,13 @@ CreateRedfishDiscoverNetworkInterface ( if (NewNetworkInterface == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
NewNetworkInterface->HwAddressSize = HwAddressSize;
CopyMem (&NewNetworkInterface->MacAddress.Addr, &MacAddress.Addr, NewNetworkInterface->HwAddressSize);
NetLibGetMacString (ControllerHandle, NULL, &NewNetworkInterface->StrMacAddr);
NewNetworkInterface->VlanId = NetLibGetVlanId (ControllerHandle);
}
+
*NetworkInterface = NewNetworkInterface;
return EFI_SUCCESS;
}
@@ -1291,18 +1399,18 @@ CreateRedfishDiscoverNetworkInterface ( **/
EFI_STATUS
DestroyRedfishNetwrokInterface (
- IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface
+ IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- Status = gBS->UninstallProtocolInterface(
+ Status = gBS->UninstallProtocolInterface (
ThisNetworkInterface->OpenDriverControllerHandle,
- gRequiredProtocol [ThisNetworkInterface->NetworkProtocolType].DiscoveredProtocolGuid,
+ gRequiredProtocol[ThisNetworkInterface->NetworkProtocolType].DiscoveredProtocolGuid,
&ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolDiscoverId
);
RemoveEntryList (&ThisNetworkInterface->Entry);
- mNumNetworkInterface --;
+ mNumNetworkInterface--;
FreePool (ThisNetworkInterface);
return Status;
}
@@ -1321,37 +1429,38 @@ DestroyRedfishNetwrokInterface ( EFI_STATUS
TestForRequiredProtocols (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE ControllerHandle
)
{
- UINT32 Id;
- UINTN Index;
- EFI_STATUS Status;
+ UINT32 Id;
+ UINTN Index;
+ EFI_STATUS Status;
- for (Index = 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index ++) {
+ for (Index = 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index++) {
Status = gBS->OpenProtocol (
- ControllerHandle,
- gRequiredProtocol [Index].RequiredServiceBindingProtocolGuid,
- NULL,
- This->DriverBindingHandle,
- ControllerHandle,
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL
- );
+ ControllerHandle,
+ gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
+ NULL,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+ );
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
ControllerHandle,
- gRequiredProtocol [Index].DiscoveredProtocolGuid,
- (VOID **) &Id,
+ gRequiredProtocol[Index].DiscoveredProtocolGuid,
+ (VOID **)&Id,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
- DEBUG((DEBUG_ERROR, "%a: %s is found on this controller handle.\n", __FUNCTION__, gRequiredProtocol [Index].ProtocolName));
+ DEBUG ((DEBUG_ERROR, "%a: %s is found on this controller handle.\n", __FUNCTION__, gRequiredProtocol[Index].ProtocolName));
return EFI_SUCCESS;
}
}
}
+
return EFI_UNSUPPORTED;
}
@@ -1370,82 +1479,88 @@ TestForRequiredProtocols ( EFI_STATUS
BuildupNetworkInterface (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE ControllerHandle
)
{
- UINT32 Id;
- UINT32 Index;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface;
- BOOLEAN IsNew;
- EFI_STATUS Status;
- VOID *TempInterface;
- VOID **Interface;
- UINT32 *ProtocolDiscoverIdPtr;
- EFI_HANDLE OpenDriverAgentHandle;
- EFI_HANDLE OpenDriverControllerHandle;
- EFI_HANDLE *HandleOfProtocolInterfacePtr;
- EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
- EFI_TPL OldTpl;
- BOOLEAN NewNetworkInterfaceInstalled;
+ UINT32 Id;
+ UINT32 Index;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface;
+ BOOLEAN IsNew;
+ EFI_STATUS Status;
+ VOID *TempInterface;
+ VOID **Interface;
+ UINT32 *ProtocolDiscoverIdPtr;
+ EFI_HANDLE OpenDriverAgentHandle;
+ EFI_HANDLE OpenDriverControllerHandle;
+ EFI_HANDLE *HandleOfProtocolInterfacePtr;
+ EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
+ EFI_TPL OldTpl;
+ BOOLEAN NewNetworkInterfaceInstalled;
NewNetworkInterfaceInstalled = FALSE;
- Index = 0;
+ Index = 0;
do {
- Status = gBS->OpenProtocol ( // Already in list?
+ Status = gBS->OpenProtocol (
+ // Already in list?
ControllerHandle,
- gRequiredProtocol [Index].DiscoveredProtocolGuid,
- (VOID **) &Id,
+ gRequiredProtocol[Index].DiscoveredProtocolGuid,
+ (VOID **)&Id,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
- Index ++;
- if (Index == (sizeof(gRequiredProtocol) / sizeof(REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
+ Index++;
+ if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}
+
continue;
}
Status = gBS->OpenProtocol (
ControllerHandle,
- gRequiredProtocol [Index].RequiredServiceBindingProtocolGuid,
+ gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
&TempInterface,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
- Index ++;
- if (Index == (sizeof(gRequiredProtocol) / sizeof(REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
+ Index++;
+ if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}
+
continue;
}
- if (gRequiredProtocol [Index].ProtocolType != ProtocolTypeRestEx) {
+
+ if (gRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
- Status = CreateRedfishDiscoverNetworkInterface(ControllerHandle, gRequiredProtocol [Index].ProtocolType, &IsNew, &NetworkInterface);
+ Status = CreateRedfishDiscoverNetworkInterface (ControllerHandle, gRequiredProtocol[Index].ProtocolType, &IsNew, &NetworkInterface);
if (EFI_ERROR (Status)) {
gBS->RestoreTPL (OldTpl);
return Status;
}
- NetworkInterface->NetworkProtocolType = gRequiredProtocol [Index].ProtocolType;
- NetworkInterface->OpenDriverAgentHandle = This->DriverBindingHandle;
- NetworkInterface->OpenDriverControllerHandle = ControllerHandle;
+
+ NetworkInterface->NetworkProtocolType = gRequiredProtocol[Index].ProtocolType;
+ NetworkInterface->OpenDriverAgentHandle = This->DriverBindingHandle;
+ NetworkInterface->OpenDriverControllerHandle = ControllerHandle;
NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolGuid = \
- *gRequiredProtocol [Index].RequiredProtocolGuid;
+ *gRequiredProtocol[Index].RequiredProtocolGuid;
NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolServiceGuid = \
- *gRequiredProtocol [Index].RequiredServiceBindingProtocolGuid;
- ProtocolDiscoverIdPtr = &NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolDiscoverId;
- OpenDriverAgentHandle = NetworkInterface->OpenDriverAgentHandle;
- OpenDriverControllerHandle = NetworkInterface->OpenDriverControllerHandle;
+ *gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid;
+ ProtocolDiscoverIdPtr = &NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolDiscoverId;
+ OpenDriverAgentHandle = NetworkInterface->OpenDriverAgentHandle;
+ OpenDriverControllerHandle = NetworkInterface->OpenDriverControllerHandle;
HandleOfProtocolInterfacePtr = &NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle;
- Interface = &NetworkInterface->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
+ Interface = &NetworkInterface->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
NewNetworkInterfaceInstalled = TRUE;
if (IsNew) {
InsertTailList (&mEfiRedfishDiscoverNetworkInterface, &NetworkInterface->Entry);
- mNumNetworkInterface ++;
+ mNumNetworkInterface++;
}
+
gBS->RestoreTPL (OldTpl);
} else {
// Record REST_EX instance. REST_EX is created when clinet asks for Redfish service discovery.
@@ -1456,54 +1571,59 @@ BuildupNetworkInterface ( if (RestExInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- RestExInstance->OpenDriverAgentHandle = This->DriverBindingHandle;
+
+ RestExInstance->OpenDriverAgentHandle = This->DriverBindingHandle;
RestExInstance->OpenDriverControllerHandle = ControllerHandle;
- RestExInstance->RestExControllerHandle = ControllerHandle;
+ RestExInstance->RestExControllerHandle = ControllerHandle;
InitializeListHead (&RestExInstance->Entry);
InsertTailList (&mEfiRedfishDiscoverRestExInstance, &RestExInstance->Entry);
- mNumRestExInstance ++;
- ProtocolDiscoverIdPtr = &RestExInstance->RestExId;
- OpenDriverAgentHandle = RestExInstance->OpenDriverAgentHandle;
- OpenDriverControllerHandle = RestExInstance->OpenDriverControllerHandle;
+ mNumRestExInstance++;
+ ProtocolDiscoverIdPtr = &RestExInstance->RestExId;
+ OpenDriverAgentHandle = RestExInstance->OpenDriverAgentHandle;
+ OpenDriverControllerHandle = RestExInstance->OpenDriverControllerHandle;
HandleOfProtocolInterfacePtr = &RestExInstance->RestExChildHandle;
- Interface = (VOID **)&RestExInstance->RestExProtocolInterface;
+ Interface = (VOID **)&RestExInstance->RestExProtocolInterface;
}
+
Status = gBS->InstallProtocolInterface (
&ControllerHandle,
- gRequiredProtocol [Index].DiscoveredProtocolGuid,
+ gRequiredProtocol[Index].DiscoveredProtocolGuid,
EFI_NATIVE_INTERFACE,
ProtocolDiscoverIdPtr
);
if (EFI_ERROR (Status)) {
- Index ++;
- if (Index == (sizeof(gRequiredProtocol) / sizeof(REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
+ Index++;
+ if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}
+
continue;
}
+
//
// Create service binding child and open it BY_DRIVER.
//
Status = NetLibCreateServiceChild (
- ControllerHandle,
- This->ImageHandle,
- gRequiredProtocol [Index].RequiredServiceBindingProtocolGuid,
- HandleOfProtocolInterfacePtr
- );
+ ControllerHandle,
+ This->ImageHandle,
+ gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
+ HandleOfProtocolInterfacePtr
+ );
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
- *HandleOfProtocolInterfacePtr,
- gRequiredProtocol [Index].RequiredProtocolGuid,
- Interface,
- OpenDriverAgentHandle,
- OpenDriverControllerHandle,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
+ *HandleOfProtocolInterfacePtr,
+ gRequiredProtocol[Index].RequiredProtocolGuid,
+ Interface,
+ OpenDriverAgentHandle,
+ OpenDriverControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
if (!EFI_ERROR (Status)) {
- if (EfiRedfishDiscoverProtocolHandle == NULL &&
- (gRequiredProtocol [Index].ProtocolType == ProtocolTypeRestEx) &&
+ if ((EfiRedfishDiscoverProtocolHandle == NULL) &&
+ (gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx) &&
!IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)
- ) {
+ )
+ {
// Install the fisrt Redfish Discover Protocol when EFI REST EX protcol is discovered.
// This ensures EFI REST EX is ready while EFI_REDFISH_DISCOVER_PROTOCOL consumer acquires
// Redfish serivce over network interface.
@@ -1514,27 +1634,31 @@ BuildupNetworkInterface ( EFI_NATIVE_INTERFACE,
(VOID *)&mRedfishDiscover
);
- } else if (EfiRedfishDiscoverProtocolHandle != NULL && NewNetworkInterfaceInstalled) {
- Status = gBS->ReinstallProtocolInterface (
- EfiRedfishDiscoverProtocolHandle,
- &gEfiRedfishDiscoverProtocolGuid,
- (VOID *)&mRedfishDiscover,
- (VOID *)&mRedfishDiscover
- );
- NewNetworkInterfaceInstalled = FALSE;
+ } else if ((EfiRedfishDiscoverProtocolHandle != NULL) && NewNetworkInterfaceInstalled) {
+ Status = gBS->ReinstallProtocolInterface (
+ EfiRedfishDiscoverProtocolHandle,
+ &gEfiRedfishDiscoverProtocolGuid,
+ (VOID *)&mRedfishDiscover,
+ (VOID *)&mRedfishDiscover
+ );
+ NewNetworkInterfaceInstalled = FALSE;
}
}
+
return Status;
} else {
- Index ++;
- if (Index == (sizeof(gRequiredProtocol) / sizeof(REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
+ Index++;
+ if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}
+
continue;
}
- } while (Index < (sizeof(gRequiredProtocol) / sizeof(REDFISH_DISCOVER_REQUIRED_PROTOCOL)));
+ } while (Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)));
+
return EFI_UNSUPPORTED;
}
+
/**
Close the protocol opened for Redfish discovery. This function also destories
the network services.
@@ -1553,31 +1677,33 @@ BuildupNetworkInterface ( **/
EFI_STATUS
CloseProtocolService (
- IN EFI_DRIVER_BINDING_PROTOCOL *ThisBindingProtocol,
- IN EFI_HANDLE ControllerHandle,
- IN REDFISH_DISCOVER_REQUIRED_PROTOCOL *ThisRequiredProtocol,
- IN EFI_HANDLE DriverAgentHandle,
- IN EFI_HANDLE DriverControllerHandle
-)
+ IN EFI_DRIVER_BINDING_PROTOCOL *ThisBindingProtocol,
+ IN EFI_HANDLE ControllerHandle,
+ IN REDFISH_DISCOVER_REQUIRED_PROTOCOL *ThisRequiredProtocol,
+ IN EFI_HANDLE DriverAgentHandle,
+ IN EFI_HANDLE DriverControllerHandle
+ )
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = gBS->CloseProtocol (
- ControllerHandle,
- ThisRequiredProtocol->RequiredProtocolGuid,
- DriverAgentHandle,
- DriverControllerHandle
- );
+ ControllerHandle,
+ ThisRequiredProtocol->RequiredProtocolGuid,
+ DriverAgentHandle,
+ DriverControllerHandle
+ );
if (!EFI_ERROR (Status)) {
- NetLibDestroyServiceChild(
+ NetLibDestroyServiceChild (
ControllerHandle,
ThisBindingProtocol->ImageHandle,
ThisRequiredProtocol->RequiredServiceBindingProtocolGuid,
ControllerHandle
);
}
+
return Status;
}
+
/**
Stop the services on network interface.
@@ -1591,42 +1717,44 @@ CloseProtocolService ( EFI_STATUS
StopServiceOnNetworkInterface (
IN EFI_DRIVER_BINDING_PROTOCOL *ThisBindingProtocol,
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE ControllerHandle
)
{
- UINT32 Index;
- EFI_STATUS Status;
- VOID *Interface;
- EFI_TPL OldTpl;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
- EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
-
- for (Index = 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index ++) {
+ UINT32 Index;
+ EFI_STATUS Status;
+ VOID *Interface;
+ EFI_TPL OldTpl;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
+
+ for (Index = 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index++) {
Status = gBS->HandleProtocol (
- ControllerHandle,
- gRequiredProtocol [Index].RequiredProtocolGuid,
- (VOID **)&Interface
- );
+ ControllerHandle,
+ gRequiredProtocol[Index].RequiredProtocolGuid,
+ (VOID **)&Interface
+ );
if (!EFI_ERROR (Status)) {
- if (gRequiredProtocol [Index].ProtocolType != ProtocolTypeRestEx) {
+ if (gRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
return EFI_NOT_FOUND;
}
- OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
+
+ OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == ControllerHandle) {
-
- Status = CloseProtocolService ( // Close protocol and destroy service.
+ Status = CloseProtocolService (
+ // Close protocol and destroy service.
ThisBindingProtocol,
ControllerHandle,
- &gRequiredProtocol [Index],
+ &gRequiredProtocol[Index],
ThisNetworkInterface->OpenDriverAgentHandle,
ThisNetworkInterface->OpenDriverControllerHandle
);
if (!EFI_ERROR (Status)) {
Status = DestroyRedfishNetwrokInterface (ThisNetworkInterface);
}
+
gBS->RestoreTPL (OldTpl);
// Reinstall Redfish Discover protocol to notify network
// interface change.
@@ -1638,48 +1766,59 @@ StopServiceOnNetworkInterface ( (VOID *)&mRedfishDiscover
);
if (EFI_ERROR (Status)) {
- DEBUG((DEBUG_ERROR, "%a: Reinstall gEfiRedfishDiscoverProtocolGuid fail.", __FUNCTION__));
+ DEBUG ((DEBUG_ERROR, "%a: Reinstall gEfiRedfishDiscoverProtocolGuid fail.", __FUNCTION__));
}
+
return Status;
}
+
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
break;
}
- ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
- };
+
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
+ }
+
gBS->RestoreTPL (OldTpl);
} else {
if (IsListEmpty (&mEfiRedfishDiscoverRestExInstance)) {
return EFI_NOT_FOUND;
}
- OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
+
+ OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
RestExInstance = (EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverRestExInstance);
while (TRUE) {
if (RestExInstance->RestExChildHandle == ControllerHandle) {
- Status = CloseProtocolService ( // Close REST_EX protocol.
+ Status = CloseProtocolService (
+ // Close REST_EX protocol.
ThisBindingProtocol,
ControllerHandle,
- &gRequiredProtocol [Index],
+ &gRequiredProtocol[Index],
RestExInstance->OpenDriverAgentHandle,
RestExInstance->OpenDriverControllerHandle
);
RemoveEntryList (&RestExInstance->Entry);
FreePool ((VOID *)RestExInstance);
- mNumRestExInstance --;
+ mNumRestExInstance--;
gBS->RestoreTPL (OldTpl);
return Status;
}
+
if (IsNodeAtEnd (&mEfiRedfishDiscoverRestExInstance, &RestExInstance->Entry)) {
break;
}
- RestExInstance = (EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *)GetNextNode(&mEfiRedfishDiscoverRestExInstance, &RestExInstance->Entry);
- };
+
+ RestExInstance = (EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverRestExInstance, &RestExInstance->Entry);
+ }
+
gBS->RestoreTPL (OldTpl);
}
}
}
+
return EFI_NOT_FOUND;
}
+
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
@@ -1817,7 +1956,7 @@ RedfishDiscoverDriverBindingStop ( return StopServiceOnNetworkInterface (This, ControllerHandle);
}
-EFI_DRIVER_BINDING_PROTOCOL gRedfishDiscoverDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL gRedfishDiscoverDriverBinding = {
RedfishDiscoverDriverBindingSupported,
RedfishDiscoverDriverBindingStart,
RedfishDiscoverDriverBindingStop,
@@ -1842,7 +1981,7 @@ RedfishDiscoverEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = EFI_SUCCESS;
InitializeListHead (&mRedfishDiscoverList);
@@ -1878,11 +2017,11 @@ RedfishDiscoverEntryPoint ( EFI_STATUS
EFIAPI
RedfishDiscoverUnload (
- IN EFI_HANDLE ImageHandle
+ IN EFI_HANDLE ImageHandle
)
{
- EFI_STATUS Status;
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
+ EFI_STATUS Status;
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
Status = EFI_SUCCESS;
// Destroy all network interfaces found by EFI Redfish Discover driver and
@@ -1891,7 +2030,8 @@ RedfishDiscoverUnload ( while (!IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
StopServiceOnNetworkInterface (&gRedfishDiscoverDriverBinding, ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle);
- };
+ }
+
// Disconnect EFI Redfish discover driver controller to notify the
// clinet which uses .EFI Redfish discover protocol.
@@ -1900,11 +2040,12 @@ RedfishDiscoverUnload ( // Notify user EFI_REDFISH_DISCOVER_PROTOCOL is unloaded.
//
gBS->DisconnectController (EfiRedfishDiscoverProtocolHandle, NULL, NULL);
- Status = gBS->UninstallProtocolInterface(
+ Status = gBS->UninstallProtocolInterface (
EfiRedfishDiscoverProtocolHandle,
&gEfiRedfishDiscoverProtocolGuid,
(VOID *)&mRedfishDiscover
);
}
+
return Status;
}
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h index cf69d9231a..4d1319b264 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h @@ -33,11 +33,11 @@ #include <IndustryStandard/RedfishHostInterface.h>
-#define REDFISH_DISCOVER_VERSION 0x00010000
-#define EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL TPL_NOTIFY
+#define REDFISH_DISCOVER_VERSION 0x00010000
+#define EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL TPL_NOTIFY
//
-//GUID definitions
+// GUID definitions
//
#define EFI_REDFISH_DISCOVER_TCP4_INSTANCE_GUID \
@@ -75,11 +75,11 @@ typedef enum { // the network interface.
//
typedef struct {
- EFI_GUID ProtocolGuid; ///< Network protocol GUID.
- EFI_GUID ProtocolServiceGuid; ///< Network protocol service GUID.
- UINT32 ProtocolDiscoverId; ///< The identifier installed on network protocol handle.
- EFI_HANDLE ProtocolControllerHandle; ///< The controller handle on network protocol.
- VOID *NetworkProtocolInterface; ///< The protocol interface of network protocol.
+ EFI_GUID ProtocolGuid; ///< Network protocol GUID.
+ EFI_GUID ProtocolServiceGuid; ///< Network protocol service GUID.
+ UINT32 ProtocolDiscoverId; ///< The identifier installed on network protocol handle.
+ EFI_HANDLE ProtocolControllerHandle; ///< The controller handle on network protocol.
+ VOID *NetworkProtocolInterface; ///< The protocol interface of network protocol.
} REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL;
//
@@ -87,39 +87,39 @@ typedef struct { // interface properties.
//
typedef struct {
- LIST_ENTRY Entry; ///< Link list entry.
- EFI_HANDLE OpenDriverAgentHandle; ///< The agent to open network protocol.
- EFI_HANDLE OpenDriverControllerHandle; ///< The controller handle to open network protocol.
- UINTN HwAddressSize; ///< The size of network interface hardware address.
- EFI_MAC_ADDRESS MacAddress; ///< MAC address of network interface.
- CHAR16 *StrMacAddr; ///< String to MAC address of network interface.
- BOOLEAN GotSubnetInfo; ///< Indicates sub net information is retrieved.
- EFI_IP_ADDRESS SubnetAddr; ///< Subnet ID.
- EFI_IP_ADDRESS SubnetMask; ///< Subnet mask (IPv4 only)
- UINT8 SubnetPrefixLength; ///< Subnet prefix.
- UINT16 VlanId; ///< VLAN ID
- UINT32 SubnetAddrInfoIPv6Number; ///< IPv6 address info number.
- EFI_IP6_ADDRESS_INFO *SubnetAddrInfoIPv6; ///< IPv6 address info.
+ LIST_ENTRY Entry; ///< Link list entry.
+ EFI_HANDLE OpenDriverAgentHandle; ///< The agent to open network protocol.
+ EFI_HANDLE OpenDriverControllerHandle; ///< The controller handle to open network protocol.
+ UINTN HwAddressSize; ///< The size of network interface hardware address.
+ EFI_MAC_ADDRESS MacAddress; ///< MAC address of network interface.
+ CHAR16 *StrMacAddr; ///< String to MAC address of network interface.
+ BOOLEAN GotSubnetInfo; ///< Indicates sub net information is retrieved.
+ EFI_IP_ADDRESS SubnetAddr; ///< Subnet ID.
+ EFI_IP_ADDRESS SubnetMask; ///< Subnet mask (IPv4 only)
+ UINT8 SubnetPrefixLength; ///< Subnet prefix.
+ UINT16 VlanId; ///< VLAN ID
+ UINT32 SubnetAddrInfoIPv6Number; ///< IPv6 address info number.
+ EFI_IP6_ADDRESS_INFO *SubnetAddrInfoIPv6; ///< IPv6 address info.
//
// Network interface protocol and REST EX infor.
//
- UINT32 NetworkProtocolType; ///< Network protocol type. Refer to
- ///< NETWORK_INTERFACE_PROTOCOL_TYPE.
- REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL NetworkInterfaceProtocolInfo; ///< Network interface protocol information.
- EFI_HANDLE RestExHandle; ///< REST EX handle associated with this network interface.
+ UINT32 NetworkProtocolType; ///< Network protocol type. Refer to
+ ///< NETWORK_INTERFACE_PROTOCOL_TYPE.
+ REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL NetworkInterfaceProtocolInfo; ///< Network interface protocol information.
+ EFI_HANDLE RestExHandle; ///< REST EX handle associated with this network interface.
} EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL;
//
// Internal structure used to maintain REST EX properties.
//
typedef struct {
- LIST_ENTRY Entry; ///< Link list entry.
- EFI_HANDLE OpenDriverAgentHandle; ///< The agent to open network protocol.
- EFI_HANDLE OpenDriverControllerHandle; ///< The controller handle to open network protocol.
- EFI_HANDLE RestExChildHandle; ///< The child handle created throught REST EX Service Protocol.
- EFI_HANDLE RestExControllerHandle; ///< The controller handle which provide REST EX protocol.
- EFI_REST_EX_PROTOCOL *RestExProtocolInterface; ///< Pointer to EFI_REST_EX_PROTOCOL.
- UINT32 RestExId; ///< The identifier installed on REST EX controller handle.
+ LIST_ENTRY Entry; ///< Link list entry.
+ EFI_HANDLE OpenDriverAgentHandle; ///< The agent to open network protocol.
+ EFI_HANDLE OpenDriverControllerHandle; ///< The controller handle to open network protocol.
+ EFI_HANDLE RestExChildHandle; ///< The child handle created throught REST EX Service Protocol.
+ EFI_HANDLE RestExControllerHandle; ///< The controller handle which provide REST EX protocol.
+ EFI_REST_EX_PROTOCOL *RestExProtocolInterface; ///< Pointer to EFI_REST_EX_PROTOCOL.
+ UINT32 RestExId; ///< The identifier installed on REST EX controller handle.
} EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL;
/**
@@ -135,46 +135,46 @@ 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.
//
typedef struct {
- UINT32 ProtocolType; ///< Network protocol type,
- ///< Refer to NETWORK_INTERFACE_PROTOCOL_TYPE.
- CHAR16 *ProtocolName; ///< Protocol name.
- EFI_GUID *RequiredProtocolGuid; ///< Network protocol interface GUID.
- EFI_GUID *RequiredServiceBindingProtocolGuid; ///< Network protocol service GUID.
- EFI_GUID *DiscoveredProtocolGuid; ///< Protocol interface GUID use to install identifier.
- EFI_REDFISH_DISCOVER_GET_SUBNET_INFO GetSubnetInfo; ///< Function of getting subnet information.
+ UINT32 ProtocolType; ///< Network protocol type,
+ ///< Refer to NETWORK_INTERFACE_PROTOCOL_TYPE.
+ CHAR16 *ProtocolName; ///< Protocol name.
+ EFI_GUID *RequiredProtocolGuid; ///< Network protocol interface GUID.
+ EFI_GUID *RequiredServiceBindingProtocolGuid; ///< Network protocol service GUID.
+ EFI_GUID *DiscoveredProtocolGuid; ///< Protocol interface GUID use to install identifier.
+ EFI_REDFISH_DISCOVER_GET_SUBNET_INFO GetSubnetInfo; ///< Function of getting subnet information.
} REDFISH_DISCOVER_REQUIRED_PROTOCOL;
//
// Link list of Redfish discover instance.
//
typedef struct {
- LIST_ENTRY NextInstance; ///< Next list.
- EFI_REDFISH_DISCOVERED_INSTANCE *Instance; ///< Pointer to EFI_REDFISH_DISCOVERED_INSTANCE.
+ LIST_ENTRY NextInstance; ///< Next list.
+ EFI_REDFISH_DISCOVERED_INSTANCE *Instance; ///< Pointer to EFI_REDFISH_DISCOVERED_INSTANCE.
} EFI_REDFISH_DISCOVERED_INTERNAL_LIST;
//
// Internal structure of Redfish discover instance.
//
typedef struct {
- LIST_ENTRY Entry; ///< Link list entry.
- EFI_HANDLE Owner; ///< The owner owns this Redfish service discovery.
- ///< It's the EFI image handle of driver uses
- ///< EFI Redfish Discover Protocol.
- EFI_REDFISH_DISCOVER_FLAG DiscoverFlags; ///< EFI_REDFISH_DISCOVER_FLAG
- EFI_REDFISH_DISCOVERED_TOKEN *DiscoverToken; ///< Token used to signal when Redfish service is discovered.
- EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface; ///< EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
- ///< instance used to discover Redfish service.
+ LIST_ENTRY Entry; ///< Link list entry.
+ EFI_HANDLE Owner; ///< The owner owns this Redfish service discovery.
+ ///< It's the EFI image handle of driver uses
+ ///< EFI Redfish Discover Protocol.
+ EFI_REDFISH_DISCOVER_FLAG DiscoverFlags; ///< EFI_REDFISH_DISCOVER_FLAG
+ EFI_REDFISH_DISCOVERED_TOKEN *DiscoverToken; ///< Token used to signal when Redfish service is discovered.
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface; ///< EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
+ ///< instance used to discover Redfish service.
//
// Below for Host insterface discovery.
//
- BOOLEAN HostIntfValidation; ///< Indicates whether to validate Redfish Host interface.
- EFI_IP_ADDRESS TargetIpAddress; ///< Target IP address reported in Redfish Host interface.
+ BOOLEAN HostIntfValidation; ///< Indicates whether to validate Redfish Host interface.
+ EFI_IP_ADDRESS TargetIpAddress; ///< Target IP address reported in Redfish Host interface.
} EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE;
/**
@@ -197,15 +197,15 @@ typedef struct { **/
EFI_STATUS
AddAndSignalNewRedfishService (
- IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
- IN UINTN *RedfishVersion OPTIONAL,
- IN CHAR8 *RedfishLocation OPTIONAL,
- IN CHAR8 *Uuid OPTIONAL,
- IN CHAR8 *Os OPTIONAL,
- IN CHAR8 *OsVer OPTIONAL,
- IN CHAR8 *Product OPTIONAL,
- IN CHAR8 *ProductVer OPTIONAL,
- IN BOOLEAN UseHttps
+ IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
+ IN UINTN *RedfishVersion OPTIONAL,
+ IN CHAR8 *RedfishLocation OPTIONAL,
+ IN CHAR8 *Uuid OPTIONAL,
+ IN CHAR8 *Os OPTIONAL,
+ IN CHAR8 *OsVer OPTIONAL,
+ IN CHAR8 *Product OPTIONAL,
+ IN CHAR8 *ProductVer OPTIONAL,
+ IN BOOLEAN UseHttps
);
/**
@@ -223,12 +223,12 @@ AddAndSignalNewRedfishService ( **/
EFI_STATUS
RedfishGetHostInterfaceProtocolData (
- IN EFI_SMBIOS_PROTOCOL *Smbios,
- OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
- OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
+ IN EFI_SMBIOS_PROTOCOL *Smbios,
+ OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
+ OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
);
-extern EFI_GUID gRedfishDiscoverTcp4Instance;
-extern EFI_GUID gRedfishDiscoverTcp6Instance;
-extern EFI_GUID gRedfishDiscoverRestEXInstance;
+extern EFI_GUID gRedfishDiscoverTcp4Instance;
+extern EFI_GUID gRedfishDiscoverTcp6Instance;
+extern EFI_GUID gRedfishDiscoverRestEXInstance;
#endif
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c b/RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c index f3ad36ec3a..d79750baaf 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c @@ -28,41 +28,41 @@ SMBIOS_TABLE_TYPE42 *mType42Record; **/
EFI_STATUS
RedfishGetHostInterfaceProtocolData (
- IN EFI_SMBIOS_PROTOCOL *Smbios,
- OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
- OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
+ IN EFI_SMBIOS_PROTOCOL *Smbios,
+ OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
+ OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
)
{
- EFI_STATUS Status;
- EFI_SMBIOS_HANDLE SmbiosHandle;
- EFI_SMBIOS_TABLE_HEADER *Record;
- UINT16 Offset;
- UINT8 *RecordTmp;
- UINT8 ProtocolLength;
- UINT8 SpecificDataLen;
+ EFI_STATUS Status;
+ EFI_SMBIOS_HANDLE SmbiosHandle;
+ EFI_SMBIOS_TABLE_HEADER *Record;
+ UINT16 Offset;
+ UINT8 *RecordTmp;
+ UINT8 ProtocolLength;
+ UINT8 SpecificDataLen;
if ((Smbios == NULL) || (ProtocolData == NULL)) {
return EFI_INVALID_PARAMETER;
}
SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
- Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
+ Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
while (!EFI_ERROR (Status) && SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED) {
if (Record->Type == SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE) {
//
// 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;
+ Offset = 5;
+ RecordTmp = (UINT8 *)Record + Offset;
//
// Get interface specific data length.
//
SpecificDataLen = *RecordTmp;
- Offset += 1;
- RecordTmp = (UINT8 *) Record + Offset;
+ Offset += 1;
+ RecordTmp = (UINT8 *)Record + Offset;
//
// Check Device Type, only PCI/PCIe Network Interface v2 is supported now.
@@ -70,24 +70,24 @@ RedfishGetHostInterfaceProtocolData ( if (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
*DeviceDescriptor = (REDFISH_INTERFACE_DATA *)RecordTmp;
- Offset = Offset + SpecificDataLen;
- RecordTmp = (UINT8 *) Record + Offset;
+ Offset = Offset + SpecificDataLen;
+ RecordTmp = (UINT8 *)Record + Offset;
//
// Check Protocol count. if > 1, only use the first protocol.
//
ASSERT (*RecordTmp == 1);
- Offset += 1;
- RecordTmp = (UINT8 *) Record + Offset;
+ Offset += 1;
+ RecordTmp = (UINT8 *)Record + Offset;
//
// Check protocol identifier.
//
if (*RecordTmp == MCHostInterfaceProtocolTypeRedfishOverIP) {
- Offset += 1;
- RecordTmp = (UINT8 *) Record + Offset;
+ Offset += 1;
+ RecordTmp = (UINT8 *)Record + Offset;
ProtocolLength = *RecordTmp;
- Offset += 1;
- RecordTmp = (UINT8 *) Record + Offset;
+ Offset += 1;
+ 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);
}
diff --git a/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c b/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c index 531f44ef03..8a05764ac6 100644 --- a/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c +++ b/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c @@ -33,20 +33,20 @@ RedfishCreateSmbiosTable42 ( VOID
)
{
- REDFISH_INTERFACE_DATA *DeviceDescriptor;
- UINT8 DeviceDataLength;
- UINT8 DeviceType;
- EFI_STATUS Status;
- MC_HOST_INTERFACE_PROTOCOL_RECORD *ProtocolRecord;
- VOID *ProtocolRecords;
- VOID *NewProtocolRecords;
- UINT8 ProtocolCount;
- UINT8 CurrentProtocolsDataLength;
- UINT8 NewProtocolsDataLength;
- UINT8 ProtocolDataSize;
- SMBIOS_TABLE_TYPE42 *Type42Record;
- EFI_SMBIOS_PROTOCOL *Smbios;
- EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;
+ REDFISH_INTERFACE_DATA *DeviceDescriptor;
+ UINT8 DeviceDataLength;
+ UINT8 DeviceType;
+ EFI_STATUS Status;
+ MC_HOST_INTERFACE_PROTOCOL_RECORD *ProtocolRecord;
+ VOID *ProtocolRecords;
+ VOID *NewProtocolRecords;
+ UINT8 ProtocolCount;
+ UINT8 CurrentProtocolsDataLength;
+ UINT8 NewProtocolsDataLength;
+ UINT8 ProtocolDataSize;
+ SMBIOS_TABLE_TYPE42 *Type42Record;
+ EFI_SMBIOS_PROTOCOL *Smbios;
+ EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;
//
// Get platform Redfish host interface device type descriptor data.
@@ -57,46 +57,55 @@ 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.
//
- ProtocolRecord = NULL;
- ProtocolRecords = NULL;
- NewProtocolRecords = NULL;
- Type42Record = NULL;
- ProtocolCount = 0;
+ ProtocolRecord = NULL;
+ ProtocolRecords = NULL;
+ NewProtocolRecords = NULL;
+ Type42Record = NULL;
+ ProtocolCount = 0;
CurrentProtocolsDataLength = 0;
- NewProtocolsDataLength = 0;
+ NewProtocolsDataLength = 0;
while (TRUE) {
Status = RedfishPlatformHostInterfaceProtocolData (&ProtocolRecord, ProtocolCount);
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,13 +154,13 @@ 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 (
- sizeof (SMBIOS_TABLE_TYPE42) - 4
- + DeviceDataLength
- + 1 /// For Protocol Record Count
- + CurrentProtocolsDataLength
- + 2 /// Double NULL terminator/
- );
+ Type42Record = (SMBIOS_TABLE_TYPE42 *)AllocateZeroPool (
+ sizeof (SMBIOS_TABLE_TYPE42) - 4
+ + DeviceDataLength
+ + 1 /// For Protocol Record Count
+ + CurrentProtocolsDataLength
+ + 2 /// Double NULL terminator/
+ );
if (Type42Record == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
@@ -154,10 +168,10 @@ RedfishCreateSmbiosTable42 ( Type42Record->Hdr.Type = EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE;
Type42Record->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE42) - 4
- + DeviceDataLength
- + 1
- + CurrentProtocolsDataLength;
- Type42Record->Hdr.Handle = 0;
+ + DeviceDataLength
+ + 1
+ + CurrentProtocolsDataLength;
+ Type42Record->Hdr.Handle = 0;
Type42Record->InterfaceType = MCHostInterfaceTypeNetworkHostInterface; // Network Host Interface
//
@@ -189,34 +203,38 @@ 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;
}
MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
- Status = Smbios->Add (
- Smbios,
- NULL,
- &MemArrayMappedAddrSmbiosHandle,
- (EFI_SMBIOS_TABLE_HEADER*) Type42Record
- );
+ Status = Smbios->Add (
+ Smbios,
+ NULL,
+ &MemArrayMappedAddrSmbiosHandle,
+ (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;
}
@@ -232,8 +250,8 @@ ON_EXIT: EFI_STATUS
EFIAPI
RedfishHostInterfaceDxeEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
//
diff --git a/RedfishPkg/RedfishRestExDxe/ComponentName.c b/RedfishPkg/RedfishRestExDxe/ComponentName.c index 3674178412..de48283690 100644 --- a/RedfishPkg/RedfishRestExDxe/ComponentName.c +++ b/RedfishPkg/RedfishRestExDxe/ComponentName.c @@ -18,6 +18,7 @@ //
// EFI Component Name Functions
//
+
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@@ -92,10 +93,10 @@ EFI_STATUS EFIAPI
RedfishRestExComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
);
///
@@ -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"
};
@@ -122,12 +123,12 @@ EFI_COMPONENT_NAME2_PROTOCOL gRedfishRestExComponentName2 = { /// Table of driver names
///
GLOBAL_REMOVE_IF_UNREFERENCED
-EFI_UNICODE_STRING_TABLE mRedfishRestExDriverNameTable[] = {
+EFI_UNICODE_STRING_TABLE mRedfishRestExDriverNameTable[] = {
{ "eng;en", (CHAR16 *)L"Redfish RestEx Network Service Driver" },
- { NULL, NULL }
+ { NULL, NULL }
};
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gRedfishRestExControllerNameTable = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gRedfishRestExControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@@ -212,10 +213,10 @@ EFI_STATUS EFIAPI
RedfishRestExComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c index 87327a8549..ad65ae213a 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c @@ -11,7 +11,7 @@ #include <Uefi.h>
#include "RedfishRestExDriver.h"
-EFI_DRIVER_BINDING_PROTOCOL gRedfishRestExDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL gRedfishRestExDriverBinding = {
RedfishRestExDriverBindingSupported,
RedfishRestExDriverBindingStart,
RedfishRestExDriverBindingStop,
@@ -20,7 +20,7 @@ EFI_DRIVER_BINDING_PROTOCOL gRedfishRestExDriverBinding = { NULL
};
-EFI_SERVICE_BINDING_PROTOCOL mRedfishRestExServiceBinding = {
+EFI_SERVICE_BINDING_PROTOCOL mRedfishRestExServiceBinding = {
RedfishRestExServiceBindingCreateChild,
RedfishRestExServiceBindingDestroyChild
};
@@ -38,8 +38,8 @@ EFI_SERVICE_BINDING_PROTOCOL mRedfishRestExServiceBinding = { EFI_STATUS
EFIAPI
RestExDestroyChildEntryInHandleBuffer (
- IN LIST_ENTRY *Entry,
- IN VOID *Context
+ IN LIST_ENTRY *Entry,
+ IN VOID *Context
)
{
RESTEX_INSTANCE *Instance;
@@ -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;
+ 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;
if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {
return EFI_SUCCESS;
@@ -71,7 +71,7 @@ RestExDestroyChildEntryInHandleBuffer ( **/
VOID
RestExDestroyInstance (
- IN RESTEX_INSTANCE *Instance
+ IN RESTEX_INSTANCE *Instance
)
{
HttpIoDestroyIo (&(Instance->HttpIo));
@@ -91,12 +91,12 @@ RestExDestroyInstance ( **/
EFI_STATUS
RestExCreateInstance (
- IN RESTEX_SERVICE *Service,
- OUT RESTEX_INSTANCE **Instance
+ IN RESTEX_SERVICE *Service,
+ OUT RESTEX_INSTANCE **Instance
)
{
- RESTEX_INSTANCE *RestExIns;
- EFI_STATUS Status;
+ RESTEX_INSTANCE *RestExIns;
+ EFI_STATUS Status;
*Instance = NULL;
Status = EFI_SUCCESS;
@@ -143,7 +143,7 @@ RestExCreateInstance ( **/
VOID
RestExDestroyService (
- IN RESTEX_SERVICE *RestExSb
+ IN RESTEX_SERVICE *RestExSb
)
{
if (RestExSb->HttpChildHandle != NULL) {
@@ -184,7 +184,7 @@ RestExDestroyService ( **/
EFI_REST_EX_SERVICE_ACCESS_MODE
RestExServiceAccessMode (
- IN EFI_HANDLE Controller
+ IN EFI_HANDLE Controller
)
{
//
@@ -213,18 +213,18 @@ RestExServiceAccessMode ( **/
EFI_STATUS
RestExCreateService (
- IN EFI_HANDLE Controller,
- IN EFI_HANDLE Image,
- OUT RESTEX_SERVICE **Service
+ IN EFI_HANDLE Controller,
+ IN EFI_HANDLE Image,
+ OUT RESTEX_SERVICE **Service
)
{
- EFI_STATUS Status;
- RESTEX_SERVICE *RestExSb;
+ EFI_STATUS Status;
+ RESTEX_SERVICE *RestExSb;
- Status = EFI_SUCCESS;
- RestExSb = NULL;
+ Status = EFI_SUCCESS;
+ RestExSb = NULL;
- *Service = NULL;
+ *Service = NULL;
RestExSb = AllocateZeroPool (sizeof (RESTEX_SERVICE));
if (RestExSb == NULL) {
@@ -241,13 +241,13 @@ RestExCreateService ( RestExSb->ControllerHandle = Controller;
RestExSb->ImageHandle = Image;
- RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.Length = sizeof (EFI_REST_EX_SERVICE_INFO);
+ RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.Length = sizeof (EFI_REST_EX_SERVICE_INFO);
RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.RestServiceInfoVer.Major = 1;
RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.RestServiceInfoVer.Minor = 0;
- RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceType = EfiRestExServiceRedfish;
- RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceAccessMode = RestExServiceAccessMode (Controller);
- RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigType = EfiRestExConfigHttp;
- RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigDataLength = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
+ RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceType = EfiRestExServiceRedfish;
+ RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceAccessMode = RestExServiceAccessMode (Controller);
+ RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigType = EfiRestExConfigHttp;
+ RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigDataLength = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
Status = gBS->InstallProtocolInterface (
&Controller,
@@ -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
);
-
}
/**
@@ -412,15 +410,15 @@ RedfishRestExDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
- RESTEX_SERVICE *RestExSb;
- EFI_STATUS Status;
- UINT32 *Id;
- VOID *Interface;
+ RESTEX_SERVICE *RestExSb;
+ EFI_STATUS Status;
+ UINT32 *Id;
+ VOID *Interface;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiCallerIdGuid,
- (VOID **) &Id,
+ (VOID **)&Id,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -518,12 +516,12 @@ RedfishRestExDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
- EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
- RESTEX_SERVICE *RestExSb;
- EFI_HANDLE NicHandle;
- EFI_STATUS Status;
- LIST_ENTRY *List;
- RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
+ RESTEX_SERVICE *RestExSb;
+ EFI_HANDLE NicHandle;
+ EFI_STATUS Status;
+ LIST_ENTRY *List;
+ RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
//
// RestEx driver opens HTTP child, So, Controller is a HTTP
@@ -538,7 +536,7 @@ RedfishRestExDriverBindingStop ( Status = gBS->OpenProtocol (
NicHandle,
&gEfiRestExServiceBindingProtocolGuid,
- (VOID **) &ServiceBinding,
+ (VOID **)&ServiceBinding,
This->DriverBindingHandle,
NicHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -553,19 +551,19 @@ RedfishRestExDriverBindingStop ( //
// Destroy the RestEx child instance in ChildHandleBuffer.
//
- List = &RestExSb->RestExChildrenList;
+ List = &RestExSb->RestExChildrenList;
Context.ServiceBinding = ServiceBinding;
Context.NumberOfChildren = NumberOfChildren;
Context.ChildHandleBuffer = ChildHandleBuffer;
- Status = NetDestroyLinkList (
- List,
- RestExDestroyChildEntryInHandleBuffer,
- &Context,
- NULL
- );
+ Status = NetDestroyLinkList (
+ List,
+ RestExDestroyChildEntryInHandleBuffer,
+ &Context,
+ NULL
+ );
}
- if (NumberOfChildren == 0 && IsListEmpty (&RestExSb->RestExChildrenList)) {
+ if ((NumberOfChildren == 0) && IsListEmpty (&RestExSb->RestExChildrenList)) {
gBS->UninstallProtocolInterface (
NicHandle,
&gEfiRestExServiceBindingProtocolGuid,
@@ -611,11 +609,11 @@ RedfishRestExServiceBindingCreateChild ( IN EFI_HANDLE *ChildHandle
)
{
- RESTEX_SERVICE *RestExSb;
- RESTEX_INSTANCE *Instance;
- EFI_STATUS Status;
- EFI_TPL OldTpl;
- VOID *Http;
+ RESTEX_SERVICE *RestExSb;
+ RESTEX_INSTANCE *Instance;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+ VOID *Http;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -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
@@ -688,12 +687,12 @@ RedfishRestExServiceBindingCreateChild ( ChildHandle
);
- gBS->UninstallMultipleProtocolInterfaces (
- Instance->ChildHandle,
- &gEfiRestExProtocolGuid,
- &Instance->RestEx,
- NULL
- );
+ gBS->UninstallMultipleProtocolInterfaces (
+ Instance->ChildHandle,
+ &gEfiRestExProtocolGuid,
+ &Instance->RestEx,
+ NULL
+ );
goto ON_ERROR;
}
@@ -741,12 +740,12 @@ RedfishRestExServiceBindingDestroyChild ( IN EFI_HANDLE ChildHandle
)
{
- RESTEX_SERVICE *RestExSb;
- RESTEX_INSTANCE *Instance;
+ RESTEX_SERVICE *RestExSb;
+ RESTEX_INSTANCE *Instance;
- EFI_REST_EX_PROTOCOL *RestEx;
- EFI_STATUS Status;
- EFI_TPL OldTpl;
+ EFI_REST_EX_PROTOCOL *RestEx;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -758,7 +757,7 @@ RedfishRestExServiceBindingDestroyChild ( Status = gBS->OpenProtocol (
ChildHandle,
&gEfiRestExProtocolGuid,
- (VOID **) &RestEx,
+ (VOID **)&RestEx,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -768,8 +767,8 @@ RedfishRestExServiceBindingDestroyChild ( return EFI_UNSUPPORTED;
}
- Instance = RESTEX_INSTANCE_FROM_THIS (RestEx);
- RestExSb = RESTEX_SERVICE_FROM_THIS (This);
+ Instance = RESTEX_INSTANCE_FROM_THIS (RestEx);
+ RestExSb = RESTEX_SERVICE_FROM_THIS (This);
if (Instance->Service != RestExSb) {
return EFI_INVALID_PARAMETER;
@@ -800,7 +799,6 @@ RedfishRestExServiceBindingDestroyChild ( ChildHandle
);
-
gBS->RestoreTPL (OldTpl);
//
@@ -828,4 +826,3 @@ RedfishRestExServiceBindingDestroyChild ( RestExDestroyInstance (Instance);
return EFI_SUCCESS;
}
-
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h index 6743ced23c..4a9e9f7b81 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h @@ -45,7 +45,7 @@ extern EFI_REST_EX_PROTOCOL mRedfishRestExProtocol; ///
/// RestEx service block
///
-typedef struct _RESTEX_SERVICE RESTEX_SERVICE;
+typedef struct _RESTEX_SERVICE RESTEX_SERVICE;
///
/// RestEx instance block
@@ -57,8 +57,8 @@ typedef struct _RESTEX_INSTANCE RESTEX_INSTANCE; ///
#define REDFISH_RESTEX_DRIVER_VERSION 0x0100
-#define RESTEX_SERVICE_SIGNATURE SIGNATURE_32 ('R', 'E', 'S', 'S')
-#define RESTEX_INSTANCE_SIGNATURE SIGNATURE_32 ('R', 'E', 'I', 'S')
+#define RESTEX_SERVICE_SIGNATURE SIGNATURE_32 ('R', 'E', 'S', 'S')
+#define RESTEX_INSTANCE_SIGNATURE SIGNATURE_32 ('R', 'E', 'I', 'S')
#define RESTEX_SERVICE_FROM_THIS(a) \
CR (a, RESTEX_SERVICE, ServiceBinding, RESTEX_SERVICE_SIGNATURE)
@@ -66,59 +66,58 @@ 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
+#define RESTEX_STATE_UNCONFIGED 0
+#define RESTEX_STATE_CONFIGED 1
struct _RESTEX_SERVICE {
- UINT32 Signature;
- EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
+ UINT32 Signature;
+ EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
- UINT16 RestExChildrenNum;
- LIST_ENTRY RestExChildrenList;
+ UINT16 RestExChildrenNum;
+ LIST_ENTRY RestExChildrenList;
- EFI_HANDLE ControllerHandle;
- EFI_HANDLE ImageHandle;
+ EFI_HANDLE ControllerHandle;
+ EFI_HANDLE ImageHandle;
//
// Use to establish the parent-child relationship.
//
- EFI_HANDLE HttpChildHandle;
+ EFI_HANDLE HttpChildHandle;
- UINT32 Id;
+ UINT32 Id;
- EFI_REST_EX_SERVICE_INFO RestExServiceInfo;
+ EFI_REST_EX_SERVICE_INFO RestExServiceInfo;
};
-#define RESTEX_INSTANCE_FLAGS_TLS_RETRY 0x00000001
-#define RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY 0x00000002
+#define RESTEX_INSTANCE_FLAGS_TLS_RETRY 0x00000001
+#define RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY 0x00000002
struct _RESTEX_INSTANCE {
- UINT32 Signature;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ LIST_ENTRY Link;
- EFI_REST_EX_PROTOCOL RestEx;
+ EFI_REST_EX_PROTOCOL RestEx;
- INTN State;
- BOOLEAN InDestroy;
+ INTN State;
+ BOOLEAN InDestroy;
- RESTEX_SERVICE *Service;
- EFI_HANDLE ChildHandle;
+ RESTEX_SERVICE *Service;
+ EFI_HANDLE ChildHandle;
- EFI_REST_EX_CONFIG_DATA ConfigData;
+ EFI_REST_EX_CONFIG_DATA ConfigData;
//
// HTTP_IO to access the HTTP service
//
- HTTP_IO HttpIo;
+ HTTP_IO HttpIo;
- UINT32 Flags;
+ UINT32 Flags;
};
typedef struct {
- EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
- UINTN NumberOfChildren;
- EFI_HANDLE *ChildHandleBuffer;
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
+ UINTN NumberOfChildren;
+ EFI_HANDLE *ChildHandleBuffer;
} RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
/**
@@ -143,9 +142,9 @@ typedef struct { EFI_STATUS
EFIAPI
RedfishRestExSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage,
- OUT EFI_HTTP_MESSAGE *ResponseMessage
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage,
+ OUT EFI_HTTP_MESSAGE *ResponseMessage
);
/**
@@ -173,8 +172,8 @@ RedfishRestExSendReceive ( EFI_STATUS
EFIAPI
RedfishRestExGetServiceTime (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_TIME *Time
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_TIME *Time
);
/**
@@ -244,8 +243,8 @@ RedfishRestExGetService ( EFI_STATUS
EFIAPI
RedfishRestExGetModeData (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
);
/**
@@ -282,8 +281,8 @@ RedfishRestExGetModeData ( EFI_STATUS
EFIAPI
RedfishRestExConfigure (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_REST_EX_CONFIG_DATA RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_REST_EX_CONFIG_DATA RestExConfigData
);
/**
@@ -320,10 +319,10 @@ RedfishRestExConfigure ( EFI_STATUS
EFIAPI
RedfishRestExAyncSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken,
- IN UINTN *TimeOutInMilliSeconds OPTIONAL
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
+ IN EFI_REST_EX_TOKEN *RestExToken,
+ IN UINTN *TimeOutInMilliSeconds OPTIONAL
);
/**
@@ -355,10 +354,11 @@ RedfishRestExAyncSendReceive ( EFI_STATUS
EFIAPI
RedfishRestExEventService (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken
+ IN EFI_REST_EX_PROTOCOL *This,
+ 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.
@@ -388,8 +387,8 @@ ResetHttpTslSession ( EFI_STATUS
EFIAPI
RestExDestroyChildEntryInHandleBuffer (
- IN LIST_ENTRY *Entry,
- IN VOID *Context
+ IN LIST_ENTRY *Entry,
+ IN VOID *Context
);
/**
@@ -400,7 +399,7 @@ RestExDestroyChildEntryInHandleBuffer ( **/
VOID
RestExDestroyInstance (
- IN RESTEX_INSTANCE *Instance
+ IN RESTEX_INSTANCE *Instance
);
/**
@@ -415,11 +414,10 @@ RestExDestroyInstance ( **/
EFI_STATUS
RestExCreateInstance (
- IN RESTEX_SERVICE *Service,
- OUT RESTEX_INSTANCE **Instance
+ IN RESTEX_SERVICE *Service,
+ OUT RESTEX_INSTANCE **Instance
);
-
/**
Release all the resource used the RestEx service binding instance.
@@ -428,7 +426,7 @@ RestExCreateInstance ( **/
VOID
RestExDestroyService (
- IN RESTEX_SERVICE *RestExSb
+ IN RESTEX_SERVICE *RestExSb
);
/**
@@ -446,9 +444,9 @@ RestExDestroyService ( **/
EFI_STATUS
RestExCreateService (
- IN EFI_HANDLE Controller,
- IN EFI_HANDLE Image,
- OUT RESTEX_SERVICE **Service
+ IN EFI_HANDLE Controller,
+ IN EFI_HANDLE Image,
+ OUT RESTEX_SERVICE **Service
);
/**
@@ -647,4 +645,5 @@ RedfishRestExServiceBindingDestroyChild ( IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
+
#endif
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c index 18d8811f69..eb1d8b8fa2 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c @@ -23,9 +23,9 @@ EFI_STATUS
ResetHttpTslSession (
IN RESTEX_INSTANCE *Instance
-)
+ )
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "%a: TCP connection is finished. Could be TSL session closure, reset HTTP instance for the new TLS session.\n", __FUNCTION__));
@@ -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
@@ -55,16 +58,16 @@ ResetHttpTslSession ( **/
EFI_STATUS
RedfishCheckHttpReceiveStatus (
- IN RESTEX_INSTANCE *Instance,
- IN EFI_STATUS HttpIoReceiveStatus
+ IN RESTEX_INSTANCE *Instance,
+ IN EFI_STATUS HttpIoReceiveStatus
)
{
- EFI_STATUS Status;
- EFI_STATUS ReturnStatus;
+ 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;
@@ -80,24 +83,27 @@ RedfishCheckHttpReceiveStatus ( ReturnStatus = EFI_DEVICE_ERROR;
}
} else {
- if (HttpIoReceiveStatus == EFI_CONNECTION_FIN) {
- if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TLS_RETRY) != 0) {
- 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;
+ if (HttpIoReceiveStatus == EFI_CONNECTION_FIN) {
+ if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TLS_RETRY) != 0) {
+ 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;
}
@@ -124,15 +130,15 @@ RedfishCheckHttpReceiveStatus ( **/
EFI_STATUS
RedfishHttpAddExpectation (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage,
- IN EFI_HTTP_HEADER **PreservedRequestHeaders,
- IN BOOLEAN *ItsWrite
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage,
+ IN EFI_HTTP_HEADER **PreservedRequestHeaders,
+ IN BOOLEAN *ItsWrite
)
{
- EFI_HTTP_HEADER *NewHeaders;
+ 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;
}
-
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h b/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h index b91bf39fda..a687c4ddb1 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h @@ -49,8 +49,8 @@ **/
EFI_STATUS
RedfishCheckHttpReceiveStatus (
- IN RESTEX_INSTANCE *Instance,
- IN EFI_STATUS HttpIoReceiveStatus
+ IN RESTEX_INSTANCE *Instance,
+ IN EFI_STATUS HttpIoReceiveStatus
);
/**
@@ -76,10 +76,10 @@ RedfishCheckHttpReceiveStatus ( **/
EFI_STATUS
RedfishHttpAddExpectation (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage,
- IN EFI_HTTP_HEADER **PreservedRequestHeaders,
- IN BOOLEAN *ItsWrite
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage,
+ IN EFI_HTTP_HEADER **PreservedRequestHeaders,
+ IN BOOLEAN *ItsWrite
);
/**
@@ -104,9 +104,9 @@ RedfishHttpAddExpectation ( EFI_STATUS
EFIAPI
RedfishRestExSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage,
- OUT EFI_HTTP_MESSAGE *ResponseMessage
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage,
+ OUT EFI_HTTP_MESSAGE *ResponseMessage
);
/**
@@ -134,8 +134,8 @@ RedfishRestExSendReceive ( EFI_STATUS
EFIAPI
RedfishRestExGetServiceTime (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_TIME *Time
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_TIME *Time
);
/**
@@ -205,8 +205,8 @@ RedfishRestExGetService ( EFI_STATUS
EFIAPI
RedfishRestExGetModeData (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
);
/**
@@ -243,8 +243,8 @@ RedfishRestExGetModeData ( EFI_STATUS
EFIAPI
RedfishRestExConfigure (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_REST_EX_CONFIG_DATA RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_REST_EX_CONFIG_DATA RestExConfigData
);
/**
@@ -281,10 +281,10 @@ RedfishRestExConfigure ( EFI_STATUS
EFIAPI
RedfishRestExAyncSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken,
- IN UINTN *TimeOutInMilliSeconds OPTIONAL
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
+ IN EFI_REST_EX_TOKEN *RestExToken,
+ IN UINTN *TimeOutInMilliSeconds OPTIONAL
);
/**
@@ -316,10 +316,11 @@ RedfishRestExAyncSendReceive ( EFI_STATUS
EFIAPI
RedfishRestExEventService (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken
+ IN EFI_REST_EX_PROTOCOL *This,
+ 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.
@@ -349,8 +349,8 @@ ResetHttpTslSession ( EFI_STATUS
EFIAPI
RestExDestroyChildEntryInHandleBuffer (
- IN LIST_ENTRY *Entry,
- IN VOID *Context
+ IN LIST_ENTRY *Entry,
+ IN VOID *Context
);
/**
@@ -361,7 +361,7 @@ RestExDestroyChildEntryInHandleBuffer ( **/
VOID
RestExDestroyInstance (
- IN RESTEX_INSTANCE *Instance
+ IN RESTEX_INSTANCE *Instance
);
/**
@@ -376,11 +376,10 @@ RestExDestroyInstance ( **/
EFI_STATUS
RestExCreateInstance (
- IN RESTEX_SERVICE *Service,
- OUT RESTEX_INSTANCE **Instance
+ IN RESTEX_SERVICE *Service,
+ OUT RESTEX_INSTANCE **Instance
);
-
/**
Release all the resource used the RestEx service binding instance.
@@ -389,7 +388,7 @@ RestExCreateInstance ( **/
VOID
RestExDestroyService (
- IN RESTEX_SERVICE *RestExSb
+ IN RESTEX_SERVICE *RestExSb
);
/**
@@ -407,9 +406,9 @@ RestExDestroyService ( **/
EFI_STATUS
RestExCreateService (
- IN EFI_HANDLE Controller,
- IN EFI_HANDLE Image,
- OUT RESTEX_SERVICE **Service
+ IN EFI_HANDLE Controller,
+ IN EFI_HANDLE Image,
+ OUT RESTEX_SERVICE **Service
);
/**
@@ -608,4 +607,5 @@ RedfishRestExServiceBindingDestroyChild ( IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
+
#endif
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c index 65a5fe3713..f224104ad6 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c @@ -45,37 +45,37 @@ EFI_REST_EX_PROTOCOL mRedfishRestExProtocol = { EFI_STATUS
EFIAPI
RedfishRestExSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage,
- OUT EFI_HTTP_MESSAGE *ResponseMessage
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage,
+ OUT EFI_HTTP_MESSAGE *ResponseMessage
)
{
- EFI_STATUS Status;
- RESTEX_INSTANCE *Instance;
- HTTP_IO_RESPONSE_DATA *ResponseData;
- UINTN TotalReceivedSize;
- UINTN Index;
- LIST_ENTRY *ChunkListLink;
- HTTP_IO_CHUNKS *ThisChunk;
- BOOLEAN CopyChunkData;
- BOOLEAN MediaPresent;
- EFI_HTTP_HEADER *PreservedRequestHeaders;
- BOOLEAN ItsWrite;
- BOOLEAN IsGetChunkedTransfer;
- HTTP_IO_SEND_CHUNK_PROCESS SendChunkProcess;
- HTTP_IO_SEND_NON_CHUNK_PROCESS SendNonChunkProcess;
- EFI_HTTP_MESSAGE ChunkTransferRequestMessage;
-
- Status = EFI_SUCCESS;
- ResponseData = NULL;
+ EFI_STATUS Status;
+ RESTEX_INSTANCE *Instance;
+ HTTP_IO_RESPONSE_DATA *ResponseData;
+ UINTN TotalReceivedSize;
+ UINTN Index;
+ LIST_ENTRY *ChunkListLink;
+ HTTP_IO_CHUNKS *ThisChunk;
+ BOOLEAN CopyChunkData;
+ BOOLEAN MediaPresent;
+ EFI_HTTP_HEADER *PreservedRequestHeaders;
+ BOOLEAN ItsWrite;
+ BOOLEAN IsGetChunkedTransfer;
+ HTTP_IO_SEND_CHUNK_PROCESS SendChunkProcess;
+ HTTP_IO_SEND_NON_CHUNK_PROCESS SendNonChunkProcess;
+ EFI_HTTP_MESSAGE ChunkTransferRequestMessage;
+
+ Status = EFI_SUCCESS;
+ ResponseData = NULL;
IsGetChunkedTransfer = FALSE;
- SendChunkProcess = HttpIoSendChunkNone;
- SendNonChunkProcess = HttpIoSendNonChunkNone;
+ SendChunkProcess = HttpIoSendChunkNone;
+ SendNonChunkProcess = HttpIoSendNonChunkNone;
//
// 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;
@@ -194,25 +197,26 @@ ReSendRequest:; DEBUG ((DEBUG_INFO, "Receiving HTTP response and headers...\n"));
Status = RedfishCheckHttpReceiveStatus (
- Instance,
- HttpIoRecvResponse (
- &(Instance->HttpIo),
- TRUE,
- ResponseData
- )
+ Instance,
+ HttpIoRecvResponse (
+ &(Instance->HttpIo),
+ TRUE,
+ ResponseData
+ )
);
if (Status == EFI_NOT_READY) {
- goto ReSendRequest;
+ goto 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,
@@ -288,15 +295,15 @@ ReSendRequest:; }
ResponseMessage->Data.Response->StatusCode = ResponseData->Response.StatusCode;
- ResponseMessage->HeaderCount = ResponseData->HeaderCount;
- ResponseMessage->Headers = ResponseData->Headers;
+ ResponseMessage->HeaderCount = ResponseData->HeaderCount;
+ ResponseMessage->Headers = ResponseData->Headers;
//
// Get response message body.
//
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,46 +322,52 @@ 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.
//
- CopyChunkData = TRUE;
+ CopyChunkData = TRUE;
ResponseMessage->Body = AllocateZeroPool (ResponseMessage->BodyLength);
if (ResponseMessage->Body == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ 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;
+ ResponseData->Headers = NULL;
ResponseMessage->Body = AllocateZeroPool (ResponseMessage->BodyLength);
if (ResponseMessage->Body == NULL) {
@@ -368,20 +381,22 @@ ReSendRequest:; TotalReceivedSize = 0;
while (TotalReceivedSize < ResponseMessage->BodyLength) {
ResponseData->BodyLength = ResponseMessage->BodyLength - TotalReceivedSize;
- ResponseData->Body = (CHAR8 *) ResponseMessage->Body + TotalReceivedSize;
- Status = HttpIoRecvResponse (
- &(Instance->HttpIo),
- FALSE,
- ResponseData
- );
+ ResponseData->Body = (CHAR8 *)ResponseMessage->Body + TotalReceivedSize;
+ Status = HttpIoRecvResponse (
+ &(Instance->HttpIo),
+ FALSE,
+ ResponseData
+ );
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
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;
}
@@ -429,8 +445,8 @@ ON_EXIT: EFI_STATUS
EFIAPI
RedfishRestExGetServiceTime (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_TIME *Time
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_TIME *Time
)
{
return EFI_UNSUPPORTED;
@@ -474,17 +490,17 @@ RedfishRestExGetService ( OUT EFI_REST_EX_SERVICE_INFO **RestExServiceInfo
)
{
- EFI_TPL OldTpl;
- RESTEX_INSTANCE *Instance;
- EFI_REST_EX_SERVICE_INFO *ServiceInfo;
+ EFI_TPL OldTpl;
+ RESTEX_INSTANCE *Instance;
+ EFI_REST_EX_SERVICE_INFO *ServiceInfo;
ServiceInfo = NULL;
- if (This == NULL || RestExServiceInfo == NULL) {
+ if ((This == NULL) || (RestExServiceInfo == NULL)) {
return EFI_INVALID_PARAMETER;
}
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Instance = RESTEX_INSTANCE_FROM_THIS (This);
@@ -531,8 +547,8 @@ RedfishRestExGetService ( EFI_STATUS
EFIAPI
RedfishRestExGetModeData (
- IN EFI_REST_EX_PROTOCOL *This,
- OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
)
{
return EFI_UNSUPPORTED;
@@ -572,15 +588,15 @@ RedfishRestExGetModeData ( EFI_STATUS
EFIAPI
RedfishRestExConfigure (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_REST_EX_CONFIG_DATA RestExConfigData
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_REST_EX_CONFIG_DATA RestExConfigData
)
{
- EFI_STATUS Status;
- EFI_TPL OldTpl;
- RESTEX_INSTANCE *Instance;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+ RESTEX_INSTANCE *Instance;
- EFI_HTTP_CONFIG_DATA *HttpConfigData;
+ EFI_HTTP_CONFIG_DATA *HttpConfigData;
Status = EFI_SUCCESS;
HttpConfigData = NULL;
@@ -589,7 +605,7 @@ RedfishRestExConfigure ( return EFI_INVALID_PARAMETER;
}
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Instance = RESTEX_INSTANCE_FROM_THIS (This);
@@ -601,19 +617,21 @@ 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;
}
Instance->State = RESTEX_STATE_UNCONFIGED;
} else {
HttpConfigData = &((EFI_REST_EX_HTTP_CONFIG_DATA *)RestExConfigData)->HttpConfigData;
- Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, HttpConfigData);
+ Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, HttpConfigData);
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;
}
@@ -687,10 +709,10 @@ ON_EXIT: EFI_STATUS
EFIAPI
RedfishRestExAyncSendReceive (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken,
- IN UINTN *TimeOutInMilliSeconds OPTIONAL
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
+ IN EFI_REST_EX_TOKEN *RestExToken,
+ IN UINTN *TimeOutInMilliSeconds OPTIONAL
)
{
return EFI_UNSUPPORTED;
@@ -725,11 +747,10 @@ RedfishRestExAyncSendReceive ( EFI_STATUS
EFIAPI
RedfishRestExEventService (
- IN EFI_REST_EX_PROTOCOL *This,
- IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
- IN EFI_REST_EX_TOKEN *RestExToken
+ IN EFI_REST_EX_PROTOCOL *This,
+ IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
+ IN EFI_REST_EX_TOKEN *RestExToken
)
{
return EFI_UNSUPPORTED;
}
-
diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c index a3f4cd3c9a..404866fb31 100644 --- a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c @@ -13,8 +13,8 @@ #include <Protocol/RestJsonStructure.h>
#include "RestJsonStructureInternal.h"
-LIST_ENTRY mRestJsonStructureList;
-EFI_HANDLE mProtocolHandle;
+LIST_ENTRY mRestJsonStructureList;
+EFI_HANDLE mProtocolHandle;
/**
This function registers Restful resource interpreter for the
@@ -34,63 +34,66 @@ EFI_HANDLE mProtocolHandle; EFI_STATUS
EFIAPI
RestJsonStructureRegister (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN EFI_REST_JSON_STRUCTURE_SUPPORTED *JsonStructureSupported,
- IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE ToStructure,
- IN EFI_REST_JSON_STRUCTURE_TO_JSON ToJson,
- IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure
-)
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ IN EFI_REST_JSON_STRUCTURE_SUPPORTED *JsonStructureSupported,
+ 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;
- LIST_ENTRY *ThisList;
- REST_JSON_STRUCTURE_INSTANCE *Instance;
- EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId;
- EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp;
-
- if (This == NULL ||
- ToStructure == NULL ||
- ToJson == NULL ||
- DestroyStructure == NULL ||
- JsonStructureSupported == NULL
- ) {
+ UINTN NumberOfNS;
+ UINTN Index;
+ LIST_ENTRY *ThisList;
+ REST_JSON_STRUCTURE_INSTANCE *Instance;
+ EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId;
+ EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp;
+
+ if ((This == NULL) ||
+ (ToStructure == NULL) ||
+ (ToJson == NULL) ||
+ (DestroyStructure == NULL) ||
+ (JsonStructureSupported == NULL)
+ )
+ {
return EFI_INVALID_PARAMETER;
}
//
// Check how many name space interpreter can interpret.
//
- ThisList = &JsonStructureSupported->NextSupportedRsrcInterp;
+ ThisList = &JsonStructureSupported->NextSupportedRsrcInterp;
NumberOfNS = 1;
while (TRUE) {
if (ThisList->ForwardLink == &JsonStructureSupported->NextSupportedRsrcInterp) {
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);
+ Instance->SupportedRsrcIndentifier = (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1);
//
// Copy supported resource identifer interpreter.
//
CloneSupportedInterpId = Instance->SupportedRsrcIndentifier;
- ThisSupportedInterp = JsonStructureSupported;
- for (Index = 0; Index < NumberOfNS; Index ++) {
+ ThisSupportedInterp = JsonStructureSupported;
+ 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->JsonToStructure = ToStructure;
+ Instance->StructureToJson = ToJson;
Instance->DestroyStructure = DestroyStructure;
InsertTailList (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
return EFI_SUCCESS;
@@ -111,23 +114,24 @@ RestJsonStructureRegister ( **/
EFI_STATUS
InterpreterInstanceToStruct (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
- IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,
- IN CHAR8 *ResourceRaw,
- OUT EFI_REST_JSON_STRUCTURE_HEADER **RestJSonHeader
- )
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
+ IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,
+ IN CHAR8 *ResourceRaw,
+ OUT EFI_REST_JSON_STRUCTURE_HEADER **RestJSonHeader
+ )
{
- UINTN Index;
- EFI_STATUS Status;
- EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
-
- if (This == NULL ||
- InterpreterInstance == NULL ||
- ResourceRaw == NULL ||
- RestJSonHeader == NULL
- ) {
- return EFI_INVALID_PARAMETER;
+ UINTN Index;
+ EFI_STATUS Status;
+ EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
+
+ if ((This == NULL) ||
+ (InterpreterInstance == NULL) ||
+ (ResourceRaw == NULL) ||
+ (RestJSonHeader == NULL)
+ )
+ {
+ return EFI_INVALID_PARAMETER;
}
Status = EFI_UNSUPPORTED;
@@ -137,62 +141,72 @@ InterpreterInstanceToStruct ( // Interpreter may recognize this resource.
//
Status = InterpreterInstance->JsonToStructure (
- This,
- NULL,
- ResourceRaw,
- RestJSonHeader
- );
+ This,
+ NULL,
+ ResourceRaw,
+ RestJSonHeader
+ );
} else {
//
// 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.
//
Status = InterpreterInstance->JsonToStructure (
- This,
- RsrcTypeIdentifier,
- ResourceRaw,
- RestJSonHeader
- );
+ This,
+ RsrcTypeIdentifier,
+ ResourceRaw,
+ RestJSonHeader
+ );
break;
} else {
//
// Check version.
//
if ((AsciiStrCmp (
- RsrcTypeIdentifier->NameSpace.MajorVersion,
- ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
+ RsrcTypeIdentifier->NameSpace.MajorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MajorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RsrcTypeIdentifier->NameSpace.MinorVersion,
- ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+ RsrcTypeIdentifier->NameSpace.MinorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MinorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RsrcTypeIdentifier->NameSpace.ErrataVersion,
- ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+ RsrcTypeIdentifier->NameSpace.ErrataVersion,
+ ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
+ ) == 0))
+ {
Status = InterpreterInstance->JsonToStructure (
- This,
- RsrcTypeIdentifier,
- ResourceRaw,
- RestJSonHeader
- );
+ This,
+ RsrcTypeIdentifier,
+ ResourceRaw,
+ RestJSonHeader
+ );
break;
}
}
}
- ThisSupportedRsrcTypeId ++;
+
+ ThisSupportedRsrcTypeId++;
}
}
+
return Status;
}
+
/**
This function converts JSON C structure to JSON property.
@@ -207,65 +221,76 @@ InterpreterInstanceToStruct ( **/
EFI_STATUS
InterpreterEfiStructToInstance (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
- IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,
- OUT CHAR8 **ResourceRaw
-)
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ 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
- ) {
+ 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)
+ )
+ {
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;
}
//
// Check if the namesapce and version is supported by this interpreter.
//
- Status = EFI_UNSUPPORTED;
+ 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) &&
+ RsrcTypeIdentifier->NameSpace.MajorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MajorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RsrcTypeIdentifier->NameSpace.MinorVersion,
- ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+ RsrcTypeIdentifier->NameSpace.MinorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MinorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RsrcTypeIdentifier->NameSpace.ErrataVersion,
- ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+ RsrcTypeIdentifier->NameSpace.ErrataVersion,
+ ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
+ ) == 0))
+ {
Status = InterpreterInstance->StructureToJson (
- This,
- RestJSonHeader,
- ResourceRaw
- );
+ This,
+ RestJSonHeader,
+ ResourceRaw
+ );
break;
}
}
- ThisSupportedRsrcTypeId ++;
+
+ ThisSupportedRsrcTypeId++;
}
+
return Status;
}
@@ -282,19 +307,20 @@ InterpreterEfiStructToInstance ( **/
EFI_STATUS
InterpreterInstanceDestoryJsonStruct (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
- IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader
- )
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,
+ IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader
+ )
{
- UINTN Index;
- EFI_STATUS Status;
- EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
-
- if (This == NULL ||
- InterpreterInstance == NULL ||
- RestJSonHeader == NULL
- ) {
+ UINTN Index;
+ EFI_STATUS Status;
+ EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
+
+ if ((This == NULL) ||
+ (InterpreterInstance == NULL) ||
+ (RestJSonHeader == NULL)
+ )
+ {
return EFI_INVALID_PARAMETER;
}
@@ -303,45 +329,54 @@ 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.
//
Status = InterpreterInstance->DestroyStructure (
- This,
- RestJSonHeader
- );
+ This,
+ RestJSonHeader
+ );
break;
} else {
//
// Check version.
//
if ((AsciiStrCmp (
- RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion,
- ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
+ RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MajorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion,
- ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+ RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion,
+ ThisSupportedRsrcTypeId->NameSpace.MinorVersion
+ ) == 0) &&
(AsciiStrCmp (
- RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion,
- ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+ RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion,
+ ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
+ ) == 0))
+ {
Status = InterpreterInstance->DestroyStructure (
- This,
- RestJSonHeader
- );
+ This,
+ RestJSonHeader
+ );
break;
}
}
}
- ThisSupportedRsrcTypeId ++;
+
+ ThisSupportedRsrcTypeId++;
}
+
return Status;
}
@@ -360,44 +395,49 @@ InterpreterInstanceDestoryJsonStruct ( EFI_STATUS
EFIAPI
RestJsonStructureToStruct (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,
- IN CHAR8 *ResourceJsonText,
- OUT EFI_REST_JSON_STRUCTURE_HEADER **JsonStructure
-)
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ 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
- ) {
+ EFI_STATUS Status;
+ REST_JSON_STRUCTURE_INSTANCE *Instance;
+
+ if ((This == NULL) ||
+ (ResourceJsonText == NULL) ||
+ (JsonStructure == NULL)
+ )
+ {
return EFI_INVALID_PARAMETER;
}
if (IsListEmpty (&mRestJsonStructureList)) {
return EFI_UNSUPPORTED;
}
- Status = EFI_SUCCESS;
+
+ Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
Status = InterpreterInstanceToStruct (
- This,
- Instance,
- RsrcTypeIdentifier,
- ResourceJsonText,
- JsonStructure
- );
+ This,
+ Instance,
+ RsrcTypeIdentifier,
+ ResourceJsonText,
+ JsonStructure
+ );
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;
}
@@ -415,37 +455,41 @@ RestJsonStructureToStruct ( EFI_STATUS
EFIAPI
RestJsonStructureDestroyStruct (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader
-)
+ IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+ IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader
+ )
{
- EFI_STATUS Status;
- REST_JSON_STRUCTURE_INSTANCE *Instance;
+ 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;
+
+ Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
Status = InterpreterInstanceDestoryJsonStruct (
- This,
- Instance,
- RestJSonHeader
- );
+ This,
+ Instance,
+ RestJSonHeader
+ );
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;
}
@@ -463,43 +507,47 @@ RestJsonStructureDestroyStruct ( EFI_STATUS
EFIAPI
RestJsonStructureToJson (
- IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
- IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,
- OUT CHAR8 **ResourceRaw
-)
+ 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;
+ 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;
+
+ Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) {
Status = InterpreterEfiStructToInstance (
- This,
- Instance,
- RestJSonHeader,
- ResourceRaw
- );
+ This,
+ Instance,
+ RestJSonHeader,
+ ResourceRaw
+ );
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;
}
-EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol = {
+EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol = {
RestJsonStructureRegister,
RestJsonStructureToStruct,
RestJsonStructureToJson,
@@ -522,19 +570,19 @@ RestJsonStructureEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
InitializeListHead (&mRestJsonStructureList);
//
// Install the Restful Resource Interpreter Protocol.
//
mProtocolHandle = NULL;
- Status = gBS->InstallProtocolInterface (
- &mProtocolHandle,
- &gEfiRestJsonStructureProtocolGuid,
- EFI_NATIVE_INTERFACE,
- (VOID *)&mRestJsonStructureProtocol
- );
+ Status = gBS->InstallProtocolInterface (
+ &mProtocolHandle,
+ &gEfiRestJsonStructureProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ (VOID *)&mRestJsonStructureProtocol
+ );
return Status;
}
@@ -553,12 +601,12 @@ RestJsonStructureEntryPoint ( EFI_STATUS
EFIAPI
RestJsonStructureUnload (
- IN EFI_HANDLE ImageHandle
+ IN EFI_HANDLE ImageHandle
)
{
- EFI_STATUS Status;
- REST_JSON_STRUCTURE_INSTANCE *Instance;
- REST_JSON_STRUCTURE_INSTANCE *NextInstance;
+ EFI_STATUS Status;
+ REST_JSON_STRUCTURE_INSTANCE *Instance;
+ REST_JSON_STRUCTURE_INSTANCE *NextInstance;
Status = gBS->UninstallProtocolInterface (
mProtocolHandle,
@@ -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);
diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h index e8a3408404..8d7175125c 100644 --- a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h +++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h @@ -23,11 +23,11 @@ /// C structure convertor.
///
typedef struct _REST_JSON_STRUCTURE_INSTANCE {
- LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor instance
- UINTN NumberOfNameSpaceToConvert; ///< Number of resource type this convertor supports.
- EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *SupportedRsrcIndentifier; ///< The resource type linklist
- EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; ///< JSON to C structure function
- EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; ///< C structure to JSON function
- EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; ///< Destory C struture function.
+ LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor instance
+ UINTN NumberOfNameSpaceToConvert; ///< Number of resource type this convertor supports.
+ EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *SupportedRsrcIndentifier; ///< The resource type linklist
+ EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; ///< JSON to C structure function
+ EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; ///< C structure to JSON function
+ EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; ///< Destory C struture function.
} REST_JSON_STRUCTURE_INSTANCE;
#endif
|