TianoCore EDK2 master
Loading...
Searching...
No Matches
HttpImpl.c File Reference
#include "HttpDriver.h"

Go to the source code of this file.

Functions

EFI_STATUS EFIAPI EfiHttpGetModeData (IN EFI_HTTP_PROTOCOL *This, OUT EFI_HTTP_CONFIG_DATA *HttpConfigData)
 
EFI_STATUS EFIAPI EfiHttpConfigure (IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL)
 
EFI_STATUS EFIAPI EfiHttpRequest (IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
 
EFI_STATUS EFIAPI HttpCancelTokens (IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Context)
 
EFI_STATUS HttpCancel (IN HTTP_PROTOCOL *HttpInstance, IN EFI_HTTP_TOKEN *Token)
 
EFI_STATUS EFIAPI EfiHttpCancel (IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
 
EFI_STATUS EFIAPI HttpBodyParserCallback (IN HTTP_BODY_PARSE_EVENT EventType, IN CHAR8 *Data, IN UINTN Length, IN VOID *Context)
 
EFI_STATUS HttpResponseWorker (IN HTTP_TOKEN_WRAP *Wrap)
 
EFI_STATUS EFIAPI EfiHttpResponse (IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
 
EFI_STATUS EFIAPI EfiHttpPoll (IN EFI_HTTP_PROTOCOL *This)
 

Variables

EFI_HTTP_PROTOCOL mEfiHttpTemplate
 

Detailed Description

Implementation of EFI_HTTP_PROTOCOL protocol interfaces.

Copyright (c) 2015, Intel Corporation. All rights reserved.
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file HttpImpl.c.

Function Documentation

◆ EfiHttpCancel()

EFI_STATUS EFIAPI EfiHttpCancel ( IN EFI_HTTP_PROTOCOL This,
IN EFI_HTTP_TOKEN Token 
)

Abort an asynchronous HTTP request or response token.

The Cancel() function aborts a pending HTTP request or response transaction. If Token is not NULL and the token is in transmit or receive queues when it is being cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will be signaled. If the token is not in one of the queues, which usually means that the asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL, all asynchronous tokens issued by Request() or Response() will be aborted.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
[in]TokenPoint to storage containing HTTP request or response token.
Return values
EFI_SUCCESSRequest and Response queues are successfully flushed.
EFI_INVALID_PARAMETERThis is NULL.
EFI_NOT_STARTEDThis instance hasn't been configured.
EFI_NOT_FOUNDThe asynchronous request or response token is not found.
EFI_UNSUPPORTEDThe implementation does not support this function.

Definition at line 883 of file HttpImpl.c.

◆ EfiHttpConfigure()

EFI_STATUS EFIAPI EfiHttpConfigure ( IN EFI_HTTP_PROTOCOL This,
IN EFI_HTTP_CONFIG_DATA *HttpConfigData  OPTIONAL 
)

Initialize or brutally reset the operational parameters for this EFI HTTP instance.

The Configure() function does the following: When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring timeout, local address, port, etc. When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active connections with remote hosts, canceling all asynchronous tokens, and flush request and response buffers without informing the appropriate hosts.

No other EFI HTTP function can be executed by this instance until the Configure() function is executed and returns successfully.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
[in]HttpConfigDataPointer to the configure data to configure the instance.
Return values
EFI_SUCCESSOperation succeeded.
EFI_INVALID_PARAMETEROne or more of the following conditions is TRUE: This is NULL. HttpConfigData->LocalAddressIsIPv6 is FALSE and HttpConfigData->AccessPoint.IPv4Node is NULL. HttpConfigData->LocalAddressIsIPv6 is TRUE and HttpConfigData->AccessPoint.IPv6Node is NULL.
EFI_ALREADY_STARTEDReinitialize this HTTP instance without calling Configure() with NULL to reset it.
EFI_DEVICE_ERRORAn unexpected system or network error occurred.
EFI_OUT_OF_RESOURCESCould not allocate enough system resources when executing Configure().
EFI_UNSUPPORTEDOne or more options in HttpConfigData are not supported in the implementation.

Definition at line 128 of file HttpImpl.c.

◆ EfiHttpGetModeData()

EFI_STATUS EFIAPI EfiHttpGetModeData ( IN EFI_HTTP_PROTOCOL This,
OUT EFI_HTTP_CONFIG_DATA HttpConfigData 
)

Returns the operational parameters for the current HTTP child instance.

The GetModeData() function is used to read the current mode data (operational parameters) for this HTTP protocol instance.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
[out]HttpConfigDataPoint to buffer for operational parameters of this HTTP instance. It is the responsibility of the caller to allocate the memory for HttpConfigData and HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact, it is recommended to allocate sufficient memory to record IPv6Node since it is big enough for all possibilities.
Return values
EFI_SUCCESSOperation succeeded.
EFI_INVALID_PARAMETEROne or more of the following conditions is TRUE: This is NULL. HttpConfigData is NULL. HttpConfigData->AccessPoint.IPv4Node or HttpConfigData->AccessPoint.IPv6Node is NULL.
EFI_NOT_STARTEDThis EFI HTTP Protocol instance has not been started.

Definition at line 48 of file HttpImpl.c.

◆ EfiHttpPoll()

EFI_STATUS EFIAPI EfiHttpPoll ( IN EFI_HTTP_PROTOCOL This)

The Poll() function can be used by network drivers and applications to increase the rate that data packets are moved between the communication devices and the transmit and receive queues.

In some systems, the periodic timer event in the managed network driver may not poll the underlying communications device fast enough to transmit and/or receive all data packets without missing incoming packets or dropping outgoing packets. Drivers and applications that are experiencing packet loss should try calling the Poll() function more often.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
Return values
EFI_SUCCESSIncoming or outgoing data was processed.
EFI_DEVICE_ERRORAn unexpected system or network error occurred.
EFI_INVALID_PARAMETERThis is NULL.
EFI_NOT_READYNo incoming or outgoing data is processed.
EFI_NOT_STARTEDThis EFI HTTP Protocol instance has not been started.

Definition at line 1665 of file HttpImpl.c.

◆ EfiHttpRequest()

EFI_STATUS EFIAPI EfiHttpRequest ( IN EFI_HTTP_PROTOCOL This,
IN EFI_HTTP_TOKEN Token 
)

The Request() function queues an HTTP request to this HTTP instance.

Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent successfully, or if there is an error, Status in token will be updated and Event will be signaled.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
[in]TokenPointer to storage containing HTTP request token.
Return values
EFI_SUCCESSOutgoing data was processed.
EFI_NOT_STARTEDThis EFI HTTP Protocol instance has not been started.
EFI_DEVICE_ERRORAn unexpected system or network error occurred.
EFI_TIMEOUTData was dropped out of the transmit or receive queue.
EFI_OUT_OF_RESOURCESCould not allocate enough system resources.
EFI_UNSUPPORTEDThe HTTP method is not supported in current implementation.
EFI_INVALID_PARAMETEROne or more of the following conditions is TRUE: This is NULL. Token is NULL. Token->Message is NULL. Token->Message->Body is not NULL, Token->Message->BodyLength is non-zero, and Token->Message->Data is NULL, but a previous call to Request()has not been completed successfully.

Definition at line 229 of file HttpImpl.c.

◆ EfiHttpResponse()

EFI_STATUS EFIAPI EfiHttpResponse ( IN EFI_HTTP_PROTOCOL This,
IN EFI_HTTP_TOKEN Token 
)

The Response() function queues an HTTP response to this HTTP instance, similar to Receive() function in the EFI TCP driver. When the HTTP response is received successfully, or if there is an error, Status in token will be updated and Event will be signaled.

The HTTP driver will queue a receive token to the underlying TCP instance. When data is received in the underlying TCP instance, the data will be parsed and Token will be populated with the response data. If the data received from the remote host contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting (asynchronously) for more data to be sent from the remote host before signaling Event in Token.

It is the responsibility of the caller to allocate a buffer for Body and specify the size in BodyLength. If the remote host provides a response that contains a content body, up to BodyLength bytes will be copied from the receive buffer into Body and BodyLength will be updated with the amount of bytes received and copied to Body. This allows the client to download a large file in chunks instead of into one contiguous block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive token to underlying TCP instance. If data arrives in the receive buffer, up to BodyLength bytes of data will be copied to Body. The HTTP driver will then update BodyLength with the amount of bytes received and copied to Body.

If the HTTP driver does not have an open underlying TCP connection with the host specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain an open TCP connection between client and host.

Parameters
[in]ThisPointer to EFI_HTTP_PROTOCOL instance.
[in]TokenPointer to storage containing HTTP response token.
Return values
EFI_SUCCESSAllocation succeeded.
EFI_NOT_STARTEDThis EFI HTTP Protocol instance has not been initialized.
EFI_INVALID_PARAMETEROne or more of the following conditions is TRUE: This is NULL. Token is NULL. Token->Message->Headers is NULL. Token->Message is NULL. Token->Message->Body is not NULL, Token->Message->BodyLength is non-zero, and Token->Message->Data is NULL, but a previous call to Response() has not been completed successfully.
EFI_OUT_OF_RESOURCESCould not allocate enough system resources.
EFI_ACCESS_DENIEDAn open TCP connection is not present with the host specified by response URL.

Definition at line 1561 of file HttpImpl.c.

◆ HttpBodyParserCallback()

EFI_STATUS EFIAPI HttpBodyParserCallback ( IN HTTP_BODY_PARSE_EVENT  EventType,
IN CHAR8 *  Data,
IN UINTN  Length,
IN VOID *  Context 
)

A callback function to intercept events during message parser.

This function will be invoked during HttpParseMessageBody() with various events type. An error return status of the callback function will cause the HttpParseMessageBody() aborted.

Parameters
[in]EventTypeEvent type of this callback call.
[in]DataA pointer to data buffer.
[in]LengthLength in bytes of the Data.
[in]ContextCallback context set by HttpInitMsgParser().
Return values
EFI_SUCCESSContinue to parser the message body.

Definition at line 919 of file HttpImpl.c.

◆ HttpCancel()

EFI_STATUS HttpCancel ( IN HTTP_PROTOCOL HttpInstance,
IN EFI_HTTP_TOKEN Token 
)

Cancel the user's receive/transmit request. It is the worker function of EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the token.

Parameters
[in]HttpInstancePointer to HTTP_PROTOCOL structure.
[in]TokenThe token to cancel. If NULL, all token will be cancelled.
Return values
EFI_SUCCESSThe token is cancelled.
EFI_NOT_FOUNDThe asynchronous request or response token is not found.
OthersOther error as indicated.

Definition at line 811 of file HttpImpl.c.

◆ HttpCancelTokens()

EFI_STATUS EFIAPI HttpCancelTokens ( IN NET_MAP Map,
IN NET_MAP_ITEM Item,
IN VOID *  Context 
)

Cancel a user's Token.

Parameters
[in]MapThe HTTP instance's token queue.
[in]ItemObject container for one HTTP token and token's wrap.
[in]ContextThe user's token to cancel.
Return values
EFI_SUCCESSContinue to check the next Item.
EFI_ABORTEDThe user's Token (Token != NULL) is cancelled.

Definition at line 735 of file HttpImpl.c.

◆ HttpResponseWorker()

EFI_STATUS HttpResponseWorker ( IN HTTP_TOKEN_WRAP Wrap)

The work function of EfiHttpResponse().

Parameters
[in]WrapPointer to HTTP token's wrap data.
Return values
EFI_SUCCESSAllocation succeeded.
EFI_OUT_OF_RESOURCESFailed to complete the operation due to lack of resources.
EFI_NOT_READYCan't find a corresponding Tx4Token/Tx6Token or the EFI_HTTP_UTILITIES_PROTOCOL is not available.

Definition at line 966 of file HttpImpl.c.

Variable Documentation

◆ mEfiHttpTemplate

EFI_HTTP_PROTOCOL mEfiHttpTemplate
Initial value:
= {
}
EFI_STATUS EFIAPI EfiHttpConfigure(IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL)
Definition: HttpImpl.c:128
EFI_STATUS EFIAPI EfiHttpGetModeData(IN EFI_HTTP_PROTOCOL *This, OUT EFI_HTTP_CONFIG_DATA *HttpConfigData)
Definition: HttpImpl.c:48
EFI_STATUS EFIAPI EfiHttpCancel(IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
Definition: HttpImpl.c:883
EFI_STATUS EFIAPI EfiHttpResponse(IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
Definition: HttpImpl.c:1561
EFI_STATUS EFIAPI EfiHttpPoll(IN EFI_HTTP_PROTOCOL *This)
Definition: HttpImpl.c:1665
EFI_STATUS EFIAPI EfiHttpRequest(IN EFI_HTTP_PROTOCOL *This, IN EFI_HTTP_TOKEN *Token)
Definition: HttpImpl.c:229

Definition at line 14 of file HttpImpl.c.