]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/HttpLib.h
EmbeddedPkg/AndroidFastboot: fix size with 64bit
[mirror_edk2.git] / MdeModulePkg / Include / Library / HttpLib.h
CommitLineData
f9a14916
JW
1/** @file\r
2 This library is used to share code between UEFI network stack modules.\r
3 It provides the helper routines to parse the HTTP message byte stream.\r
4\r
5Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at<BR>\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _HTTP_LIB_H_\r
17#define _HTTP_LIB_H_\r
18\r
19#include <Protocol/Http.h>\r
20\r
21/**\r
22 Decode a percent-encoded URI component to the ASCII character.\r
23 \r
24 Decode the input component in Buffer according to RFC 3986. The caller is responsible to make \r
25 sure ResultBuffer points to a buffer with size equal or greater than ((AsciiStrSize (Buffer))\r
26 in bytes. \r
27\r
28 @param[in] Buffer The pointer to a percent-encoded URI component.\r
29 @param[in] BufferLength Length of Buffer in bytes.\r
30 @param[out] ResultBuffer Point to the buffer to store the decode result.\r
31 @param[out] ResultLength Length of decoded string in ResultBuffer in bytes.\r
32\r
33 @retval EFI_SUCCESS Successfully decoded the URI.\r
34 @retval EFI_INVALID_PARAMETER Buffer is not a valid percent-encoded string.\r
35 \r
36**/\r
37EFI_STATUS\r
38EFIAPI\r
39UriPercentDecode (\r
40 IN CHAR8 *Buffer,\r
41 IN UINT32 BufferLength,\r
42 OUT CHAR8 *ResultBuffer,\r
43 OUT UINT32 *ResultLength\r
44 );\r
45\r
46/**\r
47 Create a URL parser for the input URL string.\r
48\r
49 This function will parse and dereference the input HTTP URL into it components. The original\r
50 content of the URL won't be modified and the result will be returned in UrlParser, which can\r
51 be used in other functions like NetHttpUrlGetHostName(). It is the caller's responsibility to\r
52 free the buffer returned in *UrlParser by HttpUrlFreeParser().\r
53\r
54 @param[in] Url The pointer to a HTTP URL string.\r
55 @param[in] Length Length of Url in bytes.\r
56 @param[in] IsConnectMethod Whether the Url is used in HTTP CONNECT method or not.\r
57 @param[out] UrlParser Pointer to the returned buffer to store the parse result.\r
58\r
59 @retval EFI_SUCCESS Successfully dereferenced the HTTP URL.\r
60 @retval EFI_INVALID_PARAMETER UrlParser is NULL or Url is not a valid HTTP URL.\r
61 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
62 \r
63**/\r
64EFI_STATUS\r
65EFIAPI\r
66HttpParseUrl (\r
67 IN CHAR8 *Url,\r
68 IN UINT32 Length,\r
69 IN BOOLEAN IsConnectMethod,\r
70 OUT VOID **UrlParser\r
71 );\r
72\r
73/**\r
74 Get the Hostname from a HTTP URL.\r
75\r
76 This function will return the HostName according to the Url and previous parse result ,and\r
77 it is the caller's responsibility to free the buffer returned in *HostName.\r
78\r
79 @param[in] Url The pointer to a HTTP URL string.\r
80 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().\r
81 @param[out] HostName Pointer to a buffer to store the HostName.\r
82\r
83 @retval EFI_SUCCESS Successfully get the required component.\r
84 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.\r
85 @retval EFI_NOT_FOUND No hostName component in the URL.\r
86 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
87 \r
88**/\r
89EFI_STATUS\r
90EFIAPI\r
91HttpUrlGetHostName (\r
92 IN CHAR8 *Url,\r
93 IN VOID *UrlParser,\r
94 OUT CHAR8 **HostName\r
95 );\r
96\r
97/**\r
98 Get the IPv4 address from a HTTP URL.\r
99\r
100 This function will return the IPv4 address according to the Url and previous parse result.\r
101\r
102 @param[in] Url The pointer to a HTTP URL string.\r
103 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().\r
104 @param[out] Ip4Address Pointer to a buffer to store the IP address.\r
105\r
106 @retval EFI_SUCCESS Successfully get the required component.\r
107 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip4Address is NULL or UrlParser is invalid.\r
108 @retval EFI_NOT_FOUND No IPv4 address component in the URL.\r
109 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
110 \r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114HttpUrlGetIp4 (\r
115 IN CHAR8 *Url,\r
116 IN VOID *UrlParser,\r
117 OUT EFI_IPv4_ADDRESS *Ip4Address\r
118 );\r
119\r
120/**\r
121 Get the IPv6 address from a HTTP URL.\r
122\r
123 This function will return the IPv6 address according to the Url and previous parse result.\r
124\r
125 @param[in] Url The pointer to a HTTP URL string.\r
126 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().\r
127 @param[out] Ip6Address Pointer to a buffer to store the IP address.\r
128\r
129 @retval EFI_SUCCESS Successfully get the required component.\r
130 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip6Address is NULL or UrlParser is invalid.\r
131 @retval EFI_NOT_FOUND No IPv6 address component in the URL.\r
132 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
133 \r
134**/\r
135EFI_STATUS\r
136EFIAPI\r
137HttpUrlGetIp6 (\r
138 IN CHAR8 *Url,\r
139 IN VOID *UrlParser,\r
140 OUT EFI_IPv6_ADDRESS *Ip6Address\r
141 );\r
142\r
143/**\r
144 Get the port number from a HTTP URL.\r
145\r
146 This function will return the port number according to the Url and previous parse result.\r
147\r
148 @param[in] Url The pointer to a HTTP URL string.\r
149 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().\r
150 @param[out] Port Pointer to a buffer to store the port number.\r
151\r
152 @retval EFI_SUCCESS Successfully get the required component.\r
153 @retval EFI_INVALID_PARAMETER Uri is NULL or Port is NULL or UrlParser is invalid.\r
154 @retval EFI_NOT_FOUND No port number in the URL.\r
155 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
156 \r
157**/\r
158EFI_STATUS\r
159EFIAPI\r
160HttpUrlGetPort (\r
161 IN CHAR8 *Url,\r
162 IN VOID *UrlParser,\r
163 OUT UINT16 *Port\r
164 );\r
165\r
166/**\r
167 Release the resource of the URL parser.\r
168\r
169 @param[in] UrlParser Pointer to the parser.\r
170 \r
171**/\r
172VOID\r
173EFIAPI\r
174HttpUrlFreeParser (\r
175 IN VOID *UrlParser\r
176 );\r
177\r
178//\r
179// HTTP body parser interface.\r
180//\r
181\r
182typedef enum {\r
183 //\r
184 // Part of entity data.\r
185 // Length of entity body in Data.\r
186 //\r
187 BodyParseEventOnData,\r
188 //\r
189 // End of message body.\r
190 // Length is 0 and Data points to next byte after the end of the message.\r
191 //\r
192 BodyParseEventOnComplete\r
193} HTTP_BODY_PARSE_EVENT;\r
194\r
195/**\r
196 A callback function to intercept events during message parser.\r
197\r
198 This function will be invoked during HttpParseMessageBody() with various events type. An error\r
199 return status of the callback function will cause the HttpParseMessageBody() aborted.\r
200\r
201 @param[in] EventType Event type of this callback call.\r
202 @param[in] Data A pointer to data buffer.\r
203 @param[in] Length Length in bytes of the Data.\r
204 @param[in] Context Callback context set by HttpInitMsgParser().\r
205\r
206 @retval EFI_SUCCESS Continue to parser the message body.\r
207 @retval Others Abort the parse.\r
208 \r
209**/\r
210typedef\r
211EFI_STATUS\r
212(EFIAPI *HTTP_BODY_PARSER_CALLBACK) (\r
213 IN HTTP_BODY_PARSE_EVENT EventType,\r
214 IN CHAR8 *Data,\r
215 IN UINTN Length,\r
216 IN VOID *Context\r
217);\r
218\r
219/**\r
220 Initialize a HTTP message-body parser.\r
221\r
222 This function will create and initialize a HTTP message parser according to caller provided HTTP message\r
223 header information. It is the caller's responsibility to free the buffer returned in *UrlParser by HttpFreeMsgParser().\r
224\r
225 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.\r
226 @param[in] StatusCode Response status code returned by the remote host.\r
227 @param[in] HeaderCount Number of HTTP header structures in Headers.\r
228 @param[in] Headers Array containing list of HTTP headers.\r
229 @param[in] Callback Callback function that is invoked when parsing the HTTP message-body,\r
230 set to NULL to ignore all events.\r
231 @param[in] Context Pointer to the context that will be passed to Callback.\r
232 @param[out] MsgParser Pointer to the returned buffer to store the message parser.\r
233\r
234 @retval EFI_SUCCESS Successfully initialized the parser.\r
235 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.\r
236 @retval EFI_INVALID_PARAMETER MsgParser is NULL or HeaderCount is not NULL but Headers is NULL.\r
237 @retval Others Failed to initialize the parser.\r
238\r
239**/\r
240EFI_STATUS\r
241EFIAPI\r
242HttpInitMsgParser (\r
243 IN EFI_HTTP_METHOD Method,\r
244 IN EFI_HTTP_STATUS_CODE StatusCode,\r
245 IN UINTN HeaderCount,\r
246 IN EFI_HTTP_HEADER *Headers,\r
247 IN HTTP_BODY_PARSER_CALLBACK Callback,\r
248 IN VOID *Context,\r
249 OUT VOID **MsgParser\r
250 );\r
251\r
252/**\r
253 Parse message body.\r
254\r
255 Parse BodyLength of message-body. This function can be called repeatedly to parse the message-body partially.\r
256\r
257 @param[in, out] MsgParser Pointer to the message parser.\r
258 @param[in] BodyLength Length in bytes of the Body.\r
259 @param[in] Body Pointer to the buffer of the message-body to be parsed.\r
260\r
261 @retval EFI_SUCCESS Successfully parse the message-body.\r
262 @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or BodyLength is 0.\r
263 @retval Others Operation aborted.\r
264\r
265**/\r
266EFI_STATUS\r
267EFIAPI\r
268HttpParseMessageBody (\r
269 IN OUT VOID *MsgParser,\r
270 IN UINTN BodyLength,\r
271 IN CHAR8 *Body\r
272 );\r
273\r
274/**\r
275 Check whether the message-body is complete or not.\r
276\r
277 @param[in] MsgParser Pointer to the message parser.\r
278\r
279 @retval TRUE Message-body is complete.\r
280 @retval FALSE Message-body is not complete.\r
281\r
282**/\r
283BOOLEAN\r
284EFIAPI\r
285HttpIsMessageComplete (\r
286 IN VOID *MsgParser\r
287 );\r
288\r
289/**\r
290 Get the content length of the entity.\r
291\r
292 Note that in trunk transfer, the entity length is not valid until the whole message body is received.\r
293\r
294 @param[in] MsgParser Pointer to the message parser.\r
295 @param[out] ContentLength Pointer to store the length of the entity.\r
296\r
297 @retval EFI_SUCCESS Successfully to get the entity length.\r
298 @retval EFI_NOT_READY Entity length is not valid yet.\r
299 @retval EFI_INVALID_PARAMETER MsgParser is NULL or ContentLength is NULL.\r
300 \r
301**/\r
302EFI_STATUS\r
303EFIAPI\r
304HttpGetEntityLength (\r
305 IN VOID *MsgParser,\r
306 OUT UINTN *ContentLength\r
307 );\r
308\r
309/**\r
310 Release the resource of the message parser.\r
311\r
312 @param[in] MsgParser Pointer to the message parser.\r
313 \r
314**/\r
315VOID\r
316EFIAPI\r
317HttpFreeMsgParser (\r
318 IN VOID *MsgParser\r
319 );\r
320\r
321\r
322#endif\r
323\r