36 if ((SrcHeaders ==
NULL) || (SrcHeaderCount == 0) || (DstHeaders ==
NULL) || (DstHeaderCount ==
NULL)) {
37 return EFI_INVALID_PARAMETER;
42 if (*DstHeaders ==
NULL) {
43 return EFI_OUT_OF_RESOURCES;
46 *DstHeaderCount = SrcHeaderCount;
47 for (Index = 0; Index < SrcHeaderCount; Index++) {
48 (*DstHeaders)[Index].FieldName = ASCII_STR_DUPLICATE (SrcHeaders[Index].FieldName);
49 if ((*DstHeaders)[Index].FieldName ==
NULL) {
50 return EFI_OUT_OF_RESOURCES;
53 (*DstHeaders)[Index].FieldValue = ASCII_STR_DUPLICATE (SrcHeaders[Index].FieldValue);
54 if ((*DstHeaders)[Index].FieldValue ==
NULL) {
55 return EFI_OUT_OF_RESOURCES;
77 if (Request ==
NULL) {
78 return EFI_INVALID_PARAMETER;
81 if ((Request->Headers !=
NULL) && (Request->HeaderCount > 0)) {
83 Request->Headers =
NULL;
84 Request->HeaderCount = 0;
87 if (Request->Content !=
NULL) {
89 Request->Content =
NULL;
92 if (Request->ContentType !=
NULL) {
94 Request->ContentType =
NULL;
97 Request->ContentLength = 0;
116 if (Response ==
NULL) {
117 return EFI_INVALID_PARAMETER;
120 if ((Response->Headers !=
NULL) && (Response->HeaderCount > 0)) {
122 Response->Headers =
NULL;
123 Response->HeaderCount = 0;
126 if (Response->Payload !=
NULL) {
128 Response->Payload =
NULL;
131 if (Response->StatusCode !=
NULL) {
133 Response->StatusCode =
NULL;
156 if (HttpMessage ==
NULL) {
157 return EFI_INVALID_PARAMETER;
161 if (HttpMessage->Data.Request !=
NULL) {
162 if (HttpMessage->Data.Request->Url !=
NULL) {
163 FreePool (HttpMessage->Data.Request->Url);
166 FreePool (HttpMessage->Data.Request);
167 HttpMessage->Data.Request =
NULL;
170 if (HttpMessage->Data.Response !=
NULL) {
171 FreePool (HttpMessage->Data.Response);
172 HttpMessage->Data.Response =
NULL;
176 if (HttpMessage->Body !=
NULL) {
178 HttpMessage->Body =
NULL;
181 if (HttpMessage->Headers !=
NULL) {
183 HttpMessage->Headers =
NULL;
184 HttpMessage->HeaderCount = 0;
214 IN CHAR8 *ContentEncoding OPTIONAL
226 CHAR8 ContentLengthStr[REDFISH_CONTENT_LENGTH_SIZE];
230 BOOLEAN DoContentEncoding;
238 HeaderCount = REDFISH_COMMON_HEADER_SIZE;
242 DoContentEncoding =
FALSE;
244 if ((ServicePrivate ==
NULL) || (IS_EMPTY_STRING (Uri))) {
248 if (Method >= HttpMethodMax) {
252 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: %s\n", __func__, Uri));
257 UrlSize = (
AsciiStrLen (ServicePrivate->Host) +
StrLen (Uri) + 1) *
sizeof (CHAR16);
263 UnicodeSPrint (Url, UrlSize, L
"%a%s", ServicePrivate->Host, Uri);
264 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: Url: %s\n", __func__, Url));
269 if (!IS_EMPTY_STRING (ServicePrivate->SessionToken) || !IS_EMPTY_STRING (ServicePrivate->BasicAuth)) {
273 if ((Request !=
NULL) && (Request->HeaderCount > 0)) {
274 HeaderCount += Request->HeaderCount;
280 if (!IS_EMPTY_STRING (ContentEncoding)) {
281 if (
AsciiStrCmp (ContentEncoding, REDFISH_HTTP_CONTENT_ENCODING_NONE) != 0) {
282 DoContentEncoding =
TRUE;
286 if ((Request !=
NULL) && !IS_EMPTY_STRING (Request->Content)) {
289 if (DoContentEncoding) {
295 if (Headers ==
NULL) {
299 if (!IS_EMPTY_STRING (ServicePrivate->SessionToken)) {
301 if (EFI_ERROR (Status)) {
304 }
else if (!IS_EMPTY_STRING (ServicePrivate->BasicAuth)) {
306 if (EFI_ERROR (Status)) {
311 if (Request !=
NULL) {
312 for (Index = 0; Index < Request->HeaderCount; Index++) {
314 if (EFI_ERROR (Status)) {
321 if (EFI_ERROR (Status)) {
325 Status =
HttpSetFieldNameAndValue (&Headers[HeaderIndex++], REDFISH_HTTP_HEADER_ODATA_VERSION_STR, REDFISH_HTTP_HEADER_ODATA_VERSION_VALUE);
326 if (EFI_ERROR (Status)) {
331 if (EFI_ERROR (Status)) {
336 if (EFI_ERROR (Status)) {
340 Status =
HttpSetFieldNameAndValue (&Headers[HeaderIndex++], REDFISH_HTTP_HEADER_CONNECTION_STR, REDFISH_HTTP_HEADER_CONNECTION_VALUE);
341 if (EFI_ERROR (Status)) {
349 if (Request->ContentType ==
NULL) {
351 if (EFI_ERROR (Status)) {
356 if (EFI_ERROR (Status)) {
361 if (Request->ContentLength == 0) {
362 Request->ContentLength =
AsciiStrLen (Request->Content);
367 sizeof (ContentLengthStr),
369 (UINT64)Request->ContentLength
372 if (EFI_ERROR (Status)) {
379 if (DoContentEncoding) {
386 Request->ContentLength,
390 if (Status == EFI_INVALID_PARAMETER) {
391 DEBUG ((DEBUG_ERROR,
"%a: Error to encode content.\n", __func__));
393 }
else if (Status == EFI_UNSUPPORTED) {
394 DoContentEncoding =
FALSE;
395 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: No content coding for %a! Use raw data instead.\n", __func__, ContentEncoding));
397 if (EFI_ERROR (Status)) {
402 if (EFI_ERROR (Status)) {
411 if (!DoContentEncoding) {
413 if (Content ==
NULL) {
417 ContentLength = Request->ContentLength;
425 if (RequestData ==
NULL) {
429 RequestData->
Method = Method;
430 RequestData->
Url = Url;
436 if (RequestMsg ==
NULL) {
440 ASSERT (HeaderIndex == HeaderCount);
447 RequestMsg->
Body = Content;
454 if (Headers !=
NULL) {
458 if (RequestData !=
NULL) {
462 if (RequestMsg !=
NULL) {
494 EDKII_JSON_VALUE JsonData;
500 if ((ServicePrivate ==
NULL) || (ResponseMsg ==
NULL) || (RedfishResponse ==
NULL)) {
501 return EFI_INVALID_PARAMETER;
504 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a\n", __func__));
510 RedfishResponse->HeaderCount = 0;
511 RedfishResponse->Headers =
NULL;
512 RedfishResponse->Payload =
NULL;
513 RedfishResponse->StatusCode =
NULL;
520 if (ResponseMsg->Data.Response !=
NULL) {
521 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: status: %d\n", __func__, ResponseMsg->Data.Response->StatusCode));
523 if (RedfishResponse->StatusCode ==
NULL) {
524 DEBUG ((DEBUG_ERROR,
"%a: Failed to create status code.\n", __func__));
531 if (ResponseMsg->Headers !=
NULL) {
532 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: header count: %d\n", __func__, ResponseMsg->HeaderCount));
534 ResponseMsg->Headers,
535 ResponseMsg->HeaderCount,
536 &RedfishResponse->Headers,
537 &RedfishResponse->HeaderCount
539 if (EFI_ERROR (Status)) {
540 DEBUG ((DEBUG_ERROR,
"%a: Failed to copy HTTP headers: %r\n", __func__, Status));
547 if ((ResponseMsg->BodyLength != 0) && (ResponseMsg->Body !=
NULL)) {
548 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: body length: %d\n", __func__, ResponseMsg->BodyLength));
554 if (ContentTypeHeader !=
NULL) {
556 DEBUG ((DEBUG_WARN,
"%a: body is not in %a format\n", __func__, HTTP_CONTENT_TYPE_APP_JSON));
564 if (ContentEncodedHeader !=
NULL) {
571 ResponseMsg->BodyLength,
575 if (EFI_ERROR (Status)) {
576 DEBUG ((DEBUG_ERROR,
"%a: Failed to decompress the response content: %r decoding method: %a\n.", __func__, Status, ContentEncodedHeader->
FieldValue));
588 if (RedfishResponse->Payload ==
NULL) {
589 DEBUG ((DEBUG_ERROR,
"%a: Failed to create payload\n.", __func__));
594 DEBUG ((DEBUG_ERROR,
"%a: No payload available\n", __func__));
602 if (RedfishResponse !=
NULL) {
625 IN REDFISH_SERVICE Service,
638 CHAR8 *HttpContentEncoding;
640 if ((Service ==
NULL) || IS_EMPTY_STRING (Uri) || (Response ==
NULL)) {
641 return EFI_INVALID_PARAMETER;
644 DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST,
"%a: Method: 0x%x %s\n", __func__, Method, Uri));
647 if (ServicePrivate->Signature != REDFISH_HTTP_SERVICE_SIGNATURE) {
648 DEBUG ((DEBUG_ERROR,
"%a: signature check failure\n", __func__));
649 return EFI_INVALID_PARAMETER;
652 ZeroMem (&ResponseMsg,
sizeof (ResponseMsg));
653 HttpContentEncoding = (CHAR8 *)
PcdGetPtr (PcdRedfishServiceContentEncoding);
656 if (RequestMsg ==
NULL) {
657 DEBUG ((DEBUG_ERROR,
"%a: cannot build request message for %s\n", __func__, Uri));
658 return EFI_PROTOCOL_ERROR;
664 RestExStatus = ServicePrivate->RestEx->SendReceive (ServicePrivate->RestEx, RequestMsg, &ResponseMsg);
665 if (EFI_ERROR (RestExStatus)) {
666 DEBUG ((DEBUG_ERROR,
"%a: %s SendReceive failure: %r\n", __func__, Uri, RestExStatus));
673 if (EFI_ERROR (Status)) {
674 DEBUG ((DEBUG_ERROR,
"%a: %s parse response failure: %r\n", __func__, Uri, Status));
679 if ((Method == HttpMethodPost) &&
680 (Response->StatusCode !=
NULL) &&
681 ((*Response->StatusCode == HTTP_STATUS_200_OK) || (*Response->StatusCode == HTTP_STATUS_204_NO_CONTENT)))
684 if (XAuthTokenHeader !=
NULL) {
686 if (EFI_ERROR (Status)) {
687 DEBUG ((DEBUG_ERROR,
"%a: update session token failure: %r\n", __func__, Status));
696 if (RequestMsg !=
NULL) {
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define HTTP_HEADER_USER_AGENT
#define HTTP_HEADER_AUTHORIZATION
#define HTTP_HEADER_CONTENT_LENGTH
#define HTTP_CONTENT_ENCODING_IDENTITY
#define HTTP_HEADER_ACCEPT
#define HTTP_HEADER_X_AUTH_TOKEN
#define HTTP_HEADER_CONTENT_TYPE
#define HTTP_HEADER_CONTENT_ENCODING
EFI_STATUS EFIAPI HttpSetFieldNameAndValue(IN OUT EFI_HTTP_HEADER *HttpHeader, IN CONST CHAR8 *FieldName, IN CONST CHAR8 *FieldValue)
EFI_HTTP_HEADER *EFIAPI HttpFindHeader(IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers, IN CHAR8 *FieldName)
VOID EFIAPI HttpFreeHeaderFields(IN EFI_HTTP_HEADER *HeaderFields, IN UINTN FieldCount)
EDKII_JSON_VALUE EFIAPI JsonLoadBuffer(IN CONST CHAR8 *Buffer, IN UINTN BufferLen, IN UINTN Flags, IN OUT EDKII_JSON_ERROR *Error)
BOOLEAN EFIAPI JsonValueIsNull(IN EDKII_JSON_VALUE Json)
VOID EFIAPI JsonValueFree(IN EDKII_JSON_VALUE Json)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define DEBUG(Expression)
#define PcdGetPtr(TokenName)
EFI_STATUS RedfishContentEncode(IN CHAR8 *ContentEncodedValue, IN CHAR8 *OriginalContent, IN UINTN OriginalContentLength, OUT VOID **EncodedContentPointer, OUT UINTN *EncodedLength)
EFI_STATUS RedfishContentDecode(IN CHAR8 *ContentEncodedValue, IN VOID *ContentPointer, IN UINTN ContentLength, OUT VOID **DecodedContentPointer, OUT UINTN *DecodedLength)
EFI_STATUS ReleaseRedfishPayload(IN REDFISH_PAYLOAD_PRIVATE *Payload)
EFI_STATUS UpdateSessionToken(IN REDFISH_SERVICE_PRIVATE *Service, IN CHAR8 *Token)
REDFISH_PAYLOAD_PRIVATE * CreateRedfishPayload(IN REDFISH_SERVICE_PRIVATE *Service, IN EDKII_JSON_VALUE JsonValue)
EFI_STATUS ReleaseHttpMessage(IN EFI_HTTP_MESSAGE *HttpMessage, IN BOOLEAN IsRequest)
EFI_STATUS CopyHttpHeaders(IN EFI_HTTP_HEADER *SrcHeaders, IN UINTN SrcHeaderCount, OUT EFI_HTTP_HEADER **DstHeaders, OUT UINTN *DstHeaderCount)
EFI_STATUS ParseResponseMessage(IN REDFISH_SERVICE_PRIVATE *ServicePrivate, IN EFI_HTTP_MESSAGE *ResponseMsg, OUT REDFISH_RESPONSE *RedfishResponse)
EFI_STATUS ReleaseRedfishRequest(IN REDFISH_REQUEST *Request)
EFI_HTTP_MESSAGE * BuildRequestMessage(IN REDFISH_SERVICE_PRIVATE *ServicePrivate, IN EFI_STRING Uri, IN EFI_HTTP_METHOD Method, IN REDFISH_REQUEST *Request OPTIONAL, IN CHAR8 *ContentEncoding OPTIONAL)
EFI_STATUS ReleaseRedfishResponse(IN REDFISH_RESPONSE *Response)
EFI_STATUS HttpSendReceive(IN REDFISH_SERVICE Service, IN EFI_STRING Uri, IN EFI_HTTP_METHOD Method, IN REDFISH_REQUEST *Request OPTIONAL, OUT REDFISH_RESPONSE *Response)
EFI_HTTP_HEADER * Headers
union EFI_HTTP_MESSAGE::@577 Data
EFI_HTTP_REQUEST_DATA * Request