HttpImpl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /** @file
  2. The header files of implementation of EFI_HTTP_PROTOCOL protocol interfaces.
  3. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  4. (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __EFI_HTTP_IMPL_H__
  8. #define __EFI_HTTP_IMPL_H__
  9. #define HTTP_DEFAULT_PORT 80
  10. #define HTTP_END_OF_HDR_STR "\r\n\r\n"
  11. #define HTTP_CRLF_STR "\r\n"
  12. #define HTTP_VERSION_STR HTTP_VERSION
  13. #define HTTP_VERSION_CRLF_STR " HTTP/1.1\r\n"
  14. #define HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE 300
  15. /**
  16. Returns the operational parameters for the current HTTP child instance.
  17. The GetModeData() function is used to read the current mode data (operational
  18. parameters) for this HTTP protocol instance.
  19. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  20. @param[out] HttpConfigData Point to buffer for operational parameters of this
  21. HTTP instance. It is the responsibility of the caller
  22. to allocate the memory for HttpConfigData and
  23. HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,
  24. it is recommended to allocate sufficient memory to record
  25. IPv6Node since it is big enough for all possibilities.
  26. @retval EFI_SUCCESS Operation succeeded.
  27. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  28. This is NULL.
  29. HttpConfigData is NULL.
  30. HttpConfigData->AccessPoint.IPv4Node or
  31. HttpConfigData->AccessPoint.IPv6Node is NULL.
  32. @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
  33. **/
  34. EFI_STATUS
  35. EFIAPI
  36. EfiHttpGetModeData (
  37. IN EFI_HTTP_PROTOCOL *This,
  38. OUT EFI_HTTP_CONFIG_DATA *HttpConfigData
  39. );
  40. /**
  41. Initialize or brutally reset the operational parameters for this EFI HTTP instance.
  42. The Configure() function does the following:
  43. When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
  44. timeout, local address, port, etc.
  45. When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
  46. connections with remote hosts, canceling all asynchronous tokens, and flush request
  47. and response buffers without informing the appropriate hosts.
  48. No other EFI HTTP function can be executed by this instance until the Configure()
  49. function is executed and returns successfully.
  50. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  51. @param[in] HttpConfigData Pointer to the configure data to configure the instance.
  52. @retval EFI_SUCCESS Operation succeeded.
  53. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  54. This is NULL.
  55. HttpConfigData->LocalAddressIsIPv6 is FALSE and
  56. HttpConfigData->AccessPoint.IPv4Node is NULL.
  57. HttpConfigData->LocalAddressIsIPv6 is TRUE and
  58. HttpConfigData->AccessPoint.IPv6Node is NULL.
  59. @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
  60. Configure() with NULL to reset it.
  61. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  62. @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
  63. executing Configure().
  64. @retval EFI_UNSUPPORTED One or more options in ConfigData are not supported
  65. in the implementation.
  66. **/
  67. EFI_STATUS
  68. EFIAPI
  69. EfiHttpConfigure (
  70. IN EFI_HTTP_PROTOCOL *This,
  71. IN EFI_HTTP_CONFIG_DATA *HttpConfigData
  72. );
  73. /**
  74. The Request() function queues an HTTP request to this HTTP instance.
  75. Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
  76. successfully, or if there is an error, Status in token will be updated and Event will
  77. be signaled.
  78. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  79. @param[in] Token Pointer to storage containing HTTP request token.
  80. @retval EFI_SUCCESS Outgoing data was processed.
  81. @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
  82. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  83. @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
  84. @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
  85. @retval EFI_UNSUPPORTED The HTTP method is not supported in current
  86. implementation.
  87. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  88. This is NULL.
  89. Token is NULL.
  90. Token->Message is NULL.
  91. Token->Message->Body is not NULL,
  92. Token->Message->BodyLength is non-zero, and
  93. Token->Message->Data is NULL, but a previous call to
  94. Request()has not been completed successfully.
  95. **/
  96. EFI_STATUS
  97. EFIAPI
  98. EfiHttpRequest (
  99. IN EFI_HTTP_PROTOCOL *This,
  100. IN EFI_HTTP_TOKEN *Token
  101. );
  102. /**
  103. Abort an asynchronous HTTP request or response token.
  104. The Cancel() function aborts a pending HTTP request or response transaction. If
  105. Token is not NULL and the token is in transmit or receive queues when it is being
  106. cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
  107. be signaled. If the token is not in one of the queues, which usually means that the
  108. asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
  109. all asynchronous tokens issued by Request() or Response() will be aborted.
  110. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  111. @param[in] Token Point to storage containing HTTP request or response
  112. token.
  113. @retval EFI_SUCCESS Request and Response queues are successfully flushed.
  114. @retval EFI_INVALID_PARAMETER This is NULL.
  115. @retval EFI_NOT_STARTED This instance hasn't been configured.
  116. @retval EFI_NOT_FOUND The asynchronous request or response token is not
  117. found.
  118. @retval EFI_UNSUPPORTED The implementation does not support this function.
  119. **/
  120. EFI_STATUS
  121. EFIAPI
  122. EfiHttpCancel (
  123. IN EFI_HTTP_PROTOCOL *This,
  124. IN EFI_HTTP_TOKEN *Token
  125. );
  126. /**
  127. The Response() function queues an HTTP response to this HTTP instance, similar to
  128. Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
  129. or if there is an error, Status in token will be updated and Event will be signaled.
  130. The HTTP driver will queue a receive token to the underlying TCP instance. When data
  131. is received in the underlying TCP instance, the data will be parsed and Token will
  132. be populated with the response data. If the data received from the remote host
  133. contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
  134. (asynchronously) for more data to be sent from the remote host before signaling
  135. Event in Token.
  136. It is the responsibility of the caller to allocate a buffer for Body and specify the
  137. size in BodyLength. If the remote host provides a response that contains a content
  138. body, up to BodyLength bytes will be copied from the receive buffer into Body and
  139. BodyLength will be updated with the amount of bytes received and copied to Body. This
  140. allows the client to download a large file in chunks instead of into one contiguous
  141. block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
  142. non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
  143. token to underlying TCP instance. If data arrives in the receive buffer, up to
  144. BodyLength bytes of data will be copied to Body. The HTTP driver will then update
  145. BodyLength with the amount of bytes received and copied to Body.
  146. If the HTTP driver does not have an open underlying TCP connection with the host
  147. specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
  148. consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
  149. an open TCP connection between client and host.
  150. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  151. @param[in] Token Pointer to storage containing HTTP response token.
  152. @retval EFI_SUCCESS Allocation succeeded.
  153. @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
  154. initialized.
  155. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  156. This is NULL.
  157. Token is NULL.
  158. Token->Message->Headers is NULL.
  159. Token->Message is NULL.
  160. Token->Message->Body is not NULL,
  161. Token->Message->BodyLength is non-zero, and
  162. Token->Message->Data is NULL, but a previous call to
  163. Response() has not been completed successfully.
  164. @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
  165. @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
  166. specified by response URL.
  167. **/
  168. EFI_STATUS
  169. EFIAPI
  170. EfiHttpResponse (
  171. IN EFI_HTTP_PROTOCOL *This,
  172. IN EFI_HTTP_TOKEN *Token
  173. );
  174. /**
  175. The Poll() function can be used by network drivers and applications to increase the
  176. rate that data packets are moved between the communication devices and the transmit
  177. and receive queues.
  178. In some systems, the periodic timer event in the managed network driver may not poll
  179. the underlying communications device fast enough to transmit and/or receive all data
  180. packets without missing incoming packets or dropping outgoing packets. Drivers and
  181. applications that are experiencing packet loss should try calling the Poll() function
  182. more often.
  183. @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
  184. @retval EFI_SUCCESS Incoming or outgoing data was processed.
  185. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  186. @retval EFI_INVALID_PARAMETER This is NULL.
  187. @retval EFI_NOT_READY No incoming or outgoing data is processed.
  188. @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
  189. **/
  190. EFI_STATUS
  191. EFIAPI
  192. EfiHttpPoll (
  193. IN EFI_HTTP_PROTOCOL *This
  194. );
  195. extern EFI_HTTP_PROTOCOL mEfiHttpTemplate;
  196. #endif