]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Include/Library/HttpIoLib.h
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Include / Library / HttpIoLib.h
CommitLineData
71a40415
AC
1/** @file\r
2 HttpIoLib.h.\r
3\r
4(C) Copyright 2020 Hewlett-Packard Development Company, L.P.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#ifndef HTTP_IO_LIB_H_\r
10#define HTTP_IO_LIB_H_\r
11\r
12#include <IndustryStandard/Http11.h>\r
13\r
14#include <Library/DpcLib.h>\r
15#include <Library/HttpLib.h>\r
16#include <Library/NetLib.h>\r
17\r
d1050b9d
MK
18#define HTTP_IO_MAX_SEND_PAYLOAD 1024\r
19#define HTTP_IO_CHUNK_SIZE_STRING_LEN 50\r
20#define HTTP_IO_CHUNKED_TRANSFER_CODING_DATA_LENGTH 256\r
71a40415
AC
21\r
22///\r
23/// HTTP_IO_CALLBACK_EVENT\r
24///\r
25typedef enum {\r
26 HttpIoRequest,\r
27 HttpIoResponse\r
28} HTTP_IO_CALLBACK_EVENT;\r
29\r
30/**\r
31 HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened.\r
32\r
33 @param[in] EventType Indicate the Event type that occurs in the current callback.\r
34 @param[in] Message HTTP message which will be send to, or just received from HTTP server.\r
35 @param[in] Context The Callback Context pointer.\r
36\r
37 @retval EFI_SUCCESS Tells the HttpIo to continue the HTTP process.\r
38 @retval Others Tells the HttpIo to abort the current HTTP process.\r
39**/\r
40typedef\r
41EFI_STATUS\r
d1050b9d 42(EFIAPI *HTTP_IO_CALLBACK)(\r
71a40415
AC
43 IN HTTP_IO_CALLBACK_EVENT EventType,\r
44 IN EFI_HTTP_MESSAGE *Message,\r
45 IN VOID *Context\r
46 );\r
47\r
48///\r
49/// A wrapper structure to hold the received HTTP response data.\r
50///\r
51typedef struct {\r
d1050b9d
MK
52 EFI_HTTP_RESPONSE_DATA Response;\r
53 UINTN HeaderCount;\r
54 EFI_HTTP_HEADER *Headers;\r
55 UINTN BodyLength;\r
56 CHAR8 *Body;\r
57 EFI_STATUS Status;\r
71a40415
AC
58} HTTP_IO_RESPONSE_DATA;\r
59\r
60///\r
61/// HTTP_IO configuration data for IPv4\r
62///\r
63typedef struct {\r
d1050b9d
MK
64 EFI_HTTP_VERSION HttpVersion;\r
65 UINT32 RequestTimeOut; ///< In milliseconds.\r
66 UINT32 ResponseTimeOut; ///< In milliseconds.\r
67 BOOLEAN UseDefaultAddress;\r
68 EFI_IPv4_ADDRESS LocalIp;\r
69 EFI_IPv4_ADDRESS SubnetMask;\r
70 UINT16 LocalPort;\r
71a40415
AC
71} HTTP4_IO_CONFIG_DATA;\r
72\r
73///\r
74/// HTTP_IO configuration data for IPv6\r
75///\r
76typedef struct {\r
d1050b9d
MK
77 EFI_HTTP_VERSION HttpVersion;\r
78 UINT32 RequestTimeOut; ///< In milliseconds.\r
79 BOOLEAN UseDefaultAddress;\r
80 EFI_IPv6_ADDRESS LocalIp;\r
81 UINT16 LocalPort;\r
71a40415
AC
82} HTTP6_IO_CONFIG_DATA;\r
83\r
84///\r
85/// HTTP_IO configuration\r
86///\r
87typedef union {\r
d1050b9d
MK
88 HTTP4_IO_CONFIG_DATA Config4;\r
89 HTTP6_IO_CONFIG_DATA Config6;\r
71a40415
AC
90} HTTP_IO_CONFIG_DATA;\r
91\r
92///\r
93/// HTTP_IO wrapper of the EFI HTTP service.\r
94///\r
95typedef struct {\r
d1050b9d
MK
96 UINT8 IpVersion;\r
97 EFI_HANDLE Image;\r
98 EFI_HANDLE Controller;\r
99 EFI_HANDLE Handle;\r
71a40415 100\r
d1050b9d 101 EFI_HTTP_PROTOCOL *Http;\r
71a40415 102\r
d1050b9d
MK
103 HTTP_IO_CALLBACK Callback;\r
104 VOID *Context;\r
71a40415 105\r
d1050b9d
MK
106 EFI_HTTP_TOKEN ReqToken;\r
107 EFI_HTTP_MESSAGE ReqMessage;\r
108 EFI_HTTP_TOKEN RspToken;\r
109 EFI_HTTP_MESSAGE RspMessage;\r
71a40415 110\r
d1050b9d
MK
111 BOOLEAN IsTxDone;\r
112 BOOLEAN IsRxDone;\r
71a40415 113\r
d1050b9d
MK
114 EFI_EVENT TimeoutEvent;\r
115 UINT32 Timeout;\r
71a40415
AC
116} HTTP_IO;\r
117\r
118///\r
119/// Process code of HTTP chunk transfer.\r
120///\r
121typedef enum {\r
122 HttpIoSendChunkNone = 0,\r
123 HttpIoSendChunkHeaderZeroContent,\r
124 HttpIoSendChunkContent,\r
125 HttpIoSendChunkEndChunk,\r
126 HttpIoSendChunkFinish\r
127} HTTP_IO_SEND_CHUNK_PROCESS;\r
128\r
129///\r
130/// Process code of HTTP non chunk transfer.\r
131///\r
132typedef enum {\r
133 HttpIoSendNonChunkNone = 0,\r
134 HttpIoSendNonChunkHeaderZeroContent,\r
135 HttpIoSendNonChunkContent,\r
136 HttpIoSendNonChunkFinish\r
137} HTTP_IO_SEND_NON_CHUNK_PROCESS;\r
138\r
139///\r
140/// Chunk links for HTTP chunked transfer coding.\r
141///\r
142typedef struct {\r
d1050b9d
MK
143 LIST_ENTRY NextChunk;\r
144 UINTN Length;\r
145 CHAR8 *Data;\r
71a40415
AC
146} HTTP_IO_CHUNKS;\r
147\r
148/**\r
149 Notify the callback function when an event is triggered.\r
150\r
151 @param[in] Context The opaque parameter to the function.\r
152\r
153**/\r
154VOID\r
155EFIAPI\r
156HttpIoNotifyDpc (\r
d1050b9d 157 IN VOID *Context\r
71a40415
AC
158 );\r
159\r
160/**\r
161 Request HttpIoNotifyDpc as a DPC at TPL_CALLBACK.\r
162\r
163 @param[in] Event The event signaled.\r
164 @param[in] Context The opaque parameter to the function.\r
165\r
166**/\r
167VOID\r
168EFIAPI\r
169HttpIoNotify (\r
d1050b9d
MK
170 IN EFI_EVENT Event,\r
171 IN VOID *Context\r
71a40415
AC
172 );\r
173\r
174/**\r
175 Destroy the HTTP_IO and release the resources.\r
176\r
177 @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.\r
178\r
179**/\r
180VOID\r
181HttpIoDestroyIo (\r
d1050b9d 182 IN HTTP_IO *HttpIo\r
71a40415
AC
183 );\r
184\r
185/**\r
186 Create a HTTP_IO to access the HTTP service. It will create and configure\r
187 a HTTP child handle.\r
188\r
189 @param[in] Image The handle of the driver image.\r
190 @param[in] Controller The handle of the controller.\r
191 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
192 @param[in] ConfigData The HTTP_IO configuration data.\r
193 @param[in] Callback Callback function which will be invoked when specified\r
194 HTTP_IO_CALLBACK_EVENT happened.\r
195 @param[in] Context The Context data which will be passed to the Callback function.\r
196 @param[out] HttpIo The HTTP_IO.\r
197\r
198 @retval EFI_SUCCESS The HTTP_IO is created and configured.\r
199 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
200 @retval EFI_UNSUPPORTED One or more of the control options are not\r
201 supported in the implementation.\r
202 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
203 @retval Others Failed to create the HTTP_IO or configure it.\r
204\r
205**/\r
206EFI_STATUS\r
207HttpIoCreateIo (\r
d1050b9d
MK
208 IN EFI_HANDLE Image,\r
209 IN EFI_HANDLE Controller,\r
210 IN UINT8 IpVersion,\r
211 IN HTTP_IO_CONFIG_DATA *ConfigData,\r
212 IN HTTP_IO_CALLBACK Callback,\r
213 IN VOID *Context,\r
214 OUT HTTP_IO *HttpIo\r
71a40415
AC
215 );\r
216\r
217/**\r
218 Synchronously send a HTTP REQUEST message to the server.\r
219\r
220 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
221 @param[in] Request A pointer to storage such data as URL and HTTP method.\r
222 @param[in] HeaderCount Number of HTTP header structures in Headers list.\r
223 @param[in] Headers Array containing list of HTTP headers.\r
224 @param[in] BodyLength Length in bytes of the HTTP body.\r
225 @param[in] Body Body associated with the HTTP request.\r
226\r
227 @retval EFI_SUCCESS The HTTP request is transmitted.\r
228 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
229 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
230 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
231 @retval Others Other errors as indicated.\r
232\r
233**/\r
234EFI_STATUS\r
235HttpIoSendRequest (\r
236 IN HTTP_IO *HttpIo,\r
8874fa19 237 IN EFI_HTTP_REQUEST_DATA *Request OPTIONAL,\r
71a40415 238 IN UINTN HeaderCount,\r
8874fa19 239 IN EFI_HTTP_HEADER *Headers OPTIONAL,\r
71a40415
AC
240 IN UINTN BodyLength,\r
241 IN VOID *Body OPTIONAL\r
242 );\r
243\r
244/**\r
245 Synchronously receive a HTTP RESPONSE message from the server.\r
246\r
247 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
248 @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).\r
249 FALSE to continue receive the previous response message.\r
250 @param[out] ResponseData Point to a wrapper of the received response data.\r
251\r
252 @retval EFI_SUCCESS The HTTP response is received.\r
253 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
254 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
255 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
256 @retval Others Other errors as indicated.\r
257\r
258**/\r
259EFI_STATUS\r
260HttpIoRecvResponse (\r
d1050b9d
MK
261 IN HTTP_IO *HttpIo,\r
262 IN BOOLEAN RecvMsgHeader,\r
263 OUT HTTP_IO_RESPONSE_DATA *ResponseData\r
71a40415
AC
264 );\r
265\r
266/**\r
267 Get the value of the content length if there is a "Content-Length" header.\r
268\r
269 @param[in] HeaderCount Number of HTTP header structures in Headers.\r
270 @param[in] Headers Array containing list of HTTP headers.\r
271 @param[out] ContentLength Pointer to save the value of the content length.\r
272\r
273 @retval EFI_SUCCESS Successfully get the content length.\r
274 @retval EFI_NOT_FOUND No "Content-Length" header in the Headers.\r
275\r
276**/\r
277EFI_STATUS\r
278HttpIoGetContentLength (\r
d1050b9d
MK
279 IN UINTN HeaderCount,\r
280 IN EFI_HTTP_HEADER *Headers,\r
281 OUT UINTN *ContentLength\r
71a40415
AC
282 );\r
283\r
284/**\r
285 Synchronously receive a HTTP RESPONSE message from the server.\r
286\r
287 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
288 @param[in] HeaderCount Number of headers in Headers.\r
289 @param[in] Headers Array containing list of HTTP headers.\r
290 @param[out] ChunkListHead A pointer to receivce list head of chunked data.\r
291 Caller has to release memory of ChunkListHead\r
292 and all list entries.\r
293 @param[out] ContentLength Total content length\r
294\r
295 @retval EFI_SUCCESS The HTTP chunked transfer is received.\r
296 @retval EFI_NOT_FOUND No chunked transfer coding header found.\r
297 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
298 @retval EFI_INVALID_PARAMETER Improper parameters.\r
299 @retval Others Other errors as indicated.\r
300\r
301**/\r
302EFI_STATUS\r
303HttpIoGetChunkedTransferContent (\r
d1050b9d
MK
304 IN HTTP_IO *HttpIo,\r
305 IN UINTN HeaderCount,\r
306 IN EFI_HTTP_HEADER *Headers,\r
307 OUT LIST_ENTRY **ChunkListHead,\r
308 OUT UINTN *ContentLength\r
71a40415
AC
309 );\r
310\r
311/**\r
312 Send HTTP request in chunks.\r
313\r
314 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
315 @param[in] SendChunkProcess Pointer to current chunk process status.\r
316 @param[out] RequestMessage Request to send.\r
317\r
318 @retval EFI_SUCCESS Successfully to send chunk data according to SendChunkProcess.\r
319 @retval Other Other errors.\r
320\r
321**/\r
322EFI_STATUS\r
323HttpIoSendChunkedTransfer (\r
d1050b9d
MK
324 IN HTTP_IO *HttpIo,\r
325 IN HTTP_IO_SEND_CHUNK_PROCESS *SendChunkProcess,\r
326 IN EFI_HTTP_MESSAGE *RequestMessage\r
327 );\r
328\r
71a40415 329#endif\r