RedfishPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the RedfishPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Abner Chang <abner.chang@hpe.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:11 -08:00
committed by mergify[bot]
parent 5220bd211d
commit 39de741e2d
56 changed files with 6067 additions and 4616 deletions

View File

@@ -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) {
return EFI_INVALID_PARAMETER;
}
if (!RedfishIsPayloadCollection(Payload)) {
if ((Payload == NULL) || (CollectionSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
*CollectionSize = (UINTN)getCollectionSize(Payload);
if (!RedfishIsPayloadCollection (Payload)) {
return EFI_INVALID_PARAMETER;
}
*CollectionSize = (UINTN)getCollectionSize (Payload);
return EFI_SUCCESS;
}
/**
Get Redfish payload of collection member
@@ -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;
}

View File

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

View File

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

View File

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

View File

@@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef LIBREDFISH_REDFISH_PAYLOAD_H_
#define LIBREDFISH_REDFISH_PAYLOAD_H_
@@ -23,17 +24,83 @@
#include <redfishService.h>
#include <redpath.h>
redfishPayload* createRedfishPayload(json_t* value, redfishService* service);
redfishPayload* getPayloadByNodeName(redfishPayload* payload, const char* nodeName, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* getPayloadByIndex(redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* getPayloadForPath(redfishPayload* payload, redPathNode* redpath, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* getPayloadForPathString(redfishPayload* payload, const char* string, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* patchPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* postContentToPayload(redfishPayload* target, const char* data, size_t dataSize, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload, EFI_HTTP_STATUS_CODE** StatusCode);
void cleanupPayload(redfishPayload* payload);
bool isPayloadCollection (redfishPayload *Payload);
size_t getCollectionSize(redfishPayload* payload);
redfishPayload* getPayloadByIndex (redfishPayload* payload, size_t index, EFI_HTTP_STATUS_CODE** StatusCode);
redfishPayload *
createRedfishPayload (
json_t *value,
redfishService *service
);
redfishPayload *
getPayloadByNodeName (
redfishPayload *payload,
const char *nodeName,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
getPayloadByIndex (
redfishPayload *payload,
size_t index,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
getPayloadForPath (
redfishPayload *payload,
redPathNode *redpath,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
getPayloadForPathString (
redfishPayload *payload,
const char *string,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
patchPayload (
redfishPayload *target,
redfishPayload *payload,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
postContentToPayload (
redfishPayload *target,
const char *data,
size_t dataSize,
const char *contentType,
EFI_HTTP_STATUS_CODE **StatusCode
);
redfishPayload *
postPayload (
redfishPayload *target,
redfishPayload *payload,
EFI_HTTP_STATUS_CODE **StatusCode
);
void
cleanupPayload (
redfishPayload *payload
);
bool
isPayloadCollection (
redfishPayload *Payload
);
size_t
getCollectionSize (
redfishPayload *payload
);
redfishPayload *
getPayloadByIndex (
redfishPayload *payload,
size_t index,
EFI_HTTP_STATUS_CODE **StatusCode
);
#endif

View File

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

View File

@@ -14,6 +14,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef LIBREDFISH_REDPATH_H_
#define LIBREDFISH_REDPATH_H_
@@ -21,22 +22,28 @@
#include <jansson.h>
typedef struct _redPathNode
{
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

View File

@@ -16,177 +16,209 @@
**/
#include <redpath.h>
static char* getVersion(const char* path, char** end);
static void parseNode(const char* path, redPathNode* node, redPathNode** end);
static char *
getVersion (
const char *path,
char **end
);
static char* getStringTill(const char* string, const char* terminator, char** retEnd);
static void
parseNode (
const char *path,
redPathNode *node,
redPathNode **end
);
redPathNode* parseRedPath(const char* path)
static char *
getStringTill (
const char *string,
const char *terminator,
char **retEnd
);
redPathNode *
parseRedPath (
const char *path
)
{
redPathNode* node;
redPathNode* endNode;
char* curPath;
char* end;
redPathNode *node;
redPathNode *endNode;
char *curPath;
char *end;
if(!path || strlen(path) == 0)
{
return NULL;
}
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;
}
if(curPath[0] == '/')
{
curPath++;
}
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);
}
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;
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;
node->nodeName = nodeName;
if (indexStart == NULL) {
*end = node;
return;
}
tmpIndex = 1;
while(1)
{
if(opChars[tmpIndex] == '=' || opChars[tmpIndex] == '<' || opChars[tmpIndex] == '>' || opChars[tmpIndex] == '~')
{
tmpIndex++;
continue;
}
break;
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;
}
node->next->op = (char*)malloc(tmpIndex+1);
memcpy(node->next->op, opChars, tmpIndex);
node->next->op[tmpIndex] = 0;
break;
}
node->next->value = strdup(opChars+tmpIndex);
free(index);
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;
}