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

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