OUT REDFISH_RESPONSE *RedResponse\r
);\r
\r
+/**\r
+ Use HTTP POST to create new Redfish resource in the Resource Collection.\r
+\r
+ The POST request should be submitted to the Resource Collection in which the new resource\r
+ is to belong. The Resource Collection is addressed by URI. The Redfish may\r
+ ignore any service controlled properties. The corresponding redfish response will returned,\r
+ including HTTP StatusCode, Headers and Payload which record any HTTP response messages.\r
+\r
+ Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in\r
+ redfish response data.\r
+\r
+ @param[in] RedfishService The Service to access the Redfish resources.\r
+ @param[in] Uri Relative path to address the resource.\r
+ @param[in] Content JSON represented properties to be update.\r
+ @param[in] ContentSize Size of the Content to be send to Redfish service\r
+ @param[in] ContentType Type of the Content to be send to Redfish service\r
+ @param[out] RedResponse Pointer to the Redfish response data.\r
+\r
+ @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not\r
+ NULL and the value is 2XX. The Redfish resource will be returned\r
+ in Payload within RedResponse if server send it back in the HTTP\r
+ response message body.\r
+ @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResponse is NULL.\r
+ @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get\r
+ more error info from returned HTTP StatusCode, Headers and Payload\r
+ within RedResponse:\r
+ 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ 2. If the returned StatusCode is not NULL and the value is not 2XX,\r
+ indicates any error happen.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RedfishPostToUri (\r
+ IN REDFISH_SERVICE RedfishService,\r
+ IN CONST CHAR8 *Uri,\r
+ IN CONST CHAR8 *Content,\r
+ IN UINTN ContentSize,\r
+ IN CONST CHAR8 *ContentType,\r
+ OUT REDFISH_RESPONSE *RedResponse\r
+ );\r
+\r
/**\r
Use HTTP POST to create a new resource in target payload.\r
\r
OUT REDFISH_RESPONSE *RedResponse\r
);\r
\r
+/**\r
+ Use HTTP DELETE to remove a resource.\r
+\r
+ This function uses the RedfishService to remove a Redfish resource which is addressed\r
+ by input Uri (only the relative path is required). The corresponding redfish response will\r
+ returned, including HTTP StatusCode, Headers and Payload which record any HTTP response\r
+ messages.\r
+\r
+ Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in\r
+ redfish response data.\r
+\r
+ @param[in] RedfishService The Service to access the Redfish resources.\r
+ @param[in] Uri Relative path to address the resource.\r
+ @param[in] Content JSON represented properties to be deleted.\r
+ @param[out] RedResponse Pointer to the Redfish response data.\r
+\r
+ @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not\r
+ NULL and the value is 2XX, the Redfish resource has been removed.\r
+ If there is any message returned from server, it will be returned\r
+ in Payload within RedResponse.\r
+ @retval EFI_INVALID_PARAMETER RedfishService, Uri, or RedResponse is NULL.\r
+ @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get\r
+ more error info from returned HTTP StatusCode, Headers and Payload\r
+ within RedResponse:\r
+ 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ 2. If the returned StatusCode is not NULL and the value is not 2XX,\r
+ indicates any error happen.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RedfishDeleteByUriEx (\r
+ IN REDFISH_SERVICE RedfishService,\r
+ IN CONST CHAR8 *Uri,\r
+ IN CONST CHAR8 *Content,\r
+ OUT REDFISH_RESPONSE *RedResponse\r
+ );\r
+\r
/**\r
Dump text in fractions.\r
\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Use HTTP POST to create new Redfish resource in the Resource Collection.\r
+\r
+ The POST request should be submitted to the Resource Collection in which the new resource\r
+ is to belong. The Resource Collection is addressed by URI. The Redfish may\r
+ ignore any service controlled properties. The corresponding redfish response will returned,\r
+ including HTTP StatusCode, Headers and Payload which record any HTTP response messages.\r
+\r
+ Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in\r
+ redfish response data.\r
+\r
+ @param[in] RedfishService The Service to access the Redfish resources.\r
+ @param[in] Uri Relative path to address the resource.\r
+ @param[in] Content JSON represented properties to be update.\r
+ @param[in] ContentSize Size of the Content to be send to Redfish service\r
+ @param[in] ContentType Type of the Content to be send to Redfish service\r
+ @param[out] RedResponse Pointer to the Redfish response data.\r
+\r
+ @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not\r
+ NULL and the value is 2XX. The Redfish resource will be returned\r
+ in Payload within RedResponse if server send it back in the HTTP\r
+ response message body.\r
+ @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResponse is NULL.\r
+ @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get\r
+ more error info from returned HTTP StatusCode, Headers and Payload\r
+ within RedResponse:\r
+ 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ 2. If the returned StatusCode is not NULL and the value is not 2XX,\r
+ indicates any error happen.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RedfishPostToUri (\r
+ IN REDFISH_SERVICE RedfishService,\r
+ IN CONST CHAR8 *Uri,\r
+ IN CONST CHAR8 *Content,\r
+ IN UINTN ContentSize,\r
+ IN CONST CHAR8 *ContentType,\r
+ OUT REDFISH_RESPONSE *RedResponse\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EDKII_JSON_VALUE JsonValue;\r
+\r
+ Status = EFI_SUCCESS;\r
+ JsonValue = NULL;\r
+\r
+ if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));\r
+\r
+ JsonValue = (EDKII_JSON_VALUE)postUriFromService (\r
+ RedfishService,\r
+ Uri,\r
+ Content,\r
+ ContentSize,\r
+ ContentType,\r
+ &(RedResponse->StatusCode)\r
+ );\r
+\r
+ //\r
+ // 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ //\r
+ if (RedResponse->StatusCode == NULL) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ //\r
+ // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.\r
+ // NOTE: If there is any error message returned from server, it will be returned in\r
+ // Payload within RedResponse.\r
+ //\r
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \\r
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))\r
+ {\r
+ Status = EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ON_EXIT:\r
+ if (JsonValue != NULL) {\r
+ RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);\r
+ if (RedResponse->Payload == NULL) {\r
+ //\r
+ // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what\r
+ // we care about if the returned StatusCode is 2XX.\r
+ //\r
+ JsonValueFree (JsonValue);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
/**\r
Use HTTP POST to create a new resource in target payload.\r
\r
return Status;\r
}\r
\r
+/**\r
+ Use HTTP DELETE to remove a resource.\r
+\r
+ This function uses the RedfishService to remove a Redfish resource which is addressed\r
+ by input Uri (only the relative path is required). The corresponding redfish response will\r
+ returned, including HTTP StatusCode, Headers and Payload which record any HTTP response\r
+ messages.\r
+\r
+ Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in\r
+ redfish response data.\r
+\r
+ @param[in] RedfishService The Service to access the Redfish resources.\r
+ @param[in] Uri Relative path to address the resource.\r
+ @param[in] Content JSON represented properties to be deleted.\r
+ @param[out] RedResponse Pointer to the Redfish response data.\r
+\r
+ @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not\r
+ NULL and the value is 2XX, the Redfish resource has been removed.\r
+ If there is any message returned from server, it will be returned\r
+ in Payload within RedResponse.\r
+ @retval EFI_INVALID_PARAMETER RedfishService, Uri, or RedResponse is NULL.\r
+ @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get\r
+ more error info from returned HTTP StatusCode, Headers and Payload\r
+ within RedResponse:\r
+ 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ 2. If the returned StatusCode is not NULL and the value is not 2XX,\r
+ indicates any error happen.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RedfishDeleteByUriEx (\r
+ IN REDFISH_SERVICE RedfishService,\r
+ IN CONST CHAR8 *Uri,\r
+ IN CONST CHAR8 *Content,\r
+ OUT REDFISH_RESPONSE *RedResponse\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EDKII_JSON_VALUE JsonValue;\r
+\r
+ Status = EFI_SUCCESS;\r
+ JsonValue = NULL;\r
+\r
+ if ((RedfishService == NULL) || (Content == NULL) || (Uri == NULL) || (RedResponse == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));\r
+\r
+ JsonValue = (EDKII_JSON_VALUE)deleteUriFromServiceEx (\r
+ RedfishService,\r
+ Uri,\r
+ Content,\r
+ &(RedResponse->StatusCode)\r
+ );\r
+\r
+ //\r
+ // 1. If the returned StatusCode is NULL, indicates any error happen.\r
+ //\r
+ if (RedResponse->StatusCode == NULL) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ //\r
+ // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.\r
+ // NOTE: If there is any error message returned from server, it will be returned in\r
+ // Payload within RedResponse.\r
+ //\r
+ if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \\r
+ (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))\r
+ {\r
+ Status = EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ON_EXIT:\r
+ if (JsonValue != NULL) {\r
+ RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);\r
+ if (RedResponse->Payload == NULL) {\r
+ //\r
+ // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what\r
+ // we care about if the returned StatusCode is 2XX.\r
+ //\r
+ JsonValueFree (JsonValue);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
/**\r
Dump text in fractions.\r
\r
}\r
\r
json_t *\r
-deleteUriFromService (\r
+deleteUriFromServiceEx (\r
redfishService *service,\r
const char *uri,\r
+ const char *content,\r
EFI_HTTP_STATUS_CODE **StatusCode\r
)\r
{\r
EFI_HTTP_REQUEST_DATA *RequestData = NULL;\r
EFI_HTTP_MESSAGE *RequestMsg = NULL;\r
EFI_HTTP_MESSAGE ResponseMsg;\r
+ CHAR8 ContentLengthStr[80];\r
+ size_t contentLength;\r
\r
ret = NULL;\r
\r
//\r
// Step 1: Create HTTP request message with 4 headers:\r
//\r
- HttpIoHeader = HttpIoCreateHeader ((service->sessionToken || service->basicAuthStr) ? 5 : 4);\r
+ HttpIoHeader = HttpIoCreateHeader ((service->sessionToken || service->basicAuthStr) ? 8 : 7);\r
if (HttpIoHeader == NULL) {\r
ret = NULL;\r
goto ON_EXIT;\r
Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");\r
ASSERT_EFI_ERROR (Status);\r
\r
+ Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/json");\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ if (content != NULL) {\r
+ contentLength = strlen (content);\r
+ AsciiSPrint (\r
+ ContentLengthStr,\r
+ sizeof (ContentLengthStr),\r
+ "%lu",\r
+ (UINT64)contentLength\r
+ );\r
+ Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);\r
+ ASSERT_EFI_ERROR (Status);\r
+ Status = HttpIoSetHeader (HttpIoHeader, "OData-Version", "4.0");\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
//\r
// Step 2: build the rest of HTTP request info.\r
//\r
RequestMsg->HeaderCount = HttpIoHeader->HeaderCount;\r
RequestMsg->Headers = HttpIoHeader->Headers;\r
\r
+ if (content != NULL) {\r
+ RequestMsg->BodyLength = contentLength;\r
+ RequestMsg->Body = (VOID *)content;\r
+ }\r
+\r
ZeroMem (&ResponseMsg, sizeof (ResponseMsg));\r
\r
//\r
return ret;\r
}\r
\r
+json_t *\r
+deleteUriFromService (\r
+ redfishService *service,\r
+ const char *uri,\r
+ EFI_HTTP_STATUS_CODE **StatusCode\r
+ )\r
+{\r
+ return deleteUriFromServiceEx (service, uri, NULL, StatusCode);\r
+}\r
+\r
redfishPayload *\r
getRedfishServiceRoot (\r
redfishService *service,\r