33 IN UINT32 BufferLength,
34 OUT CHAR8 *ResultBuffer,
35 OUT UINT32 *ResultLength
42 if ((Buffer ==
NULL) || (BufferLength == 0) || (ResultBuffer ==
NULL)) {
43 return EFI_INVALID_PARAMETER;
49 while (Index < BufferLength) {
50 if (Buffer[Index] ==
'%') {
51 if ((Index + 1 >= BufferLength) || (Index + 2 >= BufferLength) ||
52 !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2]))
54 return EFI_INVALID_PARAMETER;
57 HexStr[0] = Buffer[Index+1];
58 HexStr[1] = Buffer[Index+2];
62 ResultBuffer[Offset] = Buffer[Index];
69 *ResultLength = (UINT32)Offset;
88 IN HTTP_URL_PARSE_STATE State,
89 IN BOOLEAN *IsRightBracket
98 if ((Char ==
' ') || (Char ==
'\r') || (Char ==
'\n')) {
99 return UrlParserStateMax;
106 case UrlParserUserInfo:
108 return UrlParserHostStart;
114 case UrlParserHostStart:
116 return UrlParserHostIpv6;
120 return UrlParserPortStart;
123 return UrlParserHost;
125 case UrlParserHostIpv6:
127 *IsRightBracket =
TRUE;
130 if ((Char ==
':') && *IsRightBracket) {
131 return UrlParserPortStart;
134 return UrlParserHostIpv6;
137 case UrlParserPortStart:
138 return UrlParserPort;
168 HTTP_URL_PARSE_STATE State;
171 BOOLEAN IsrightBracket;
173 ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0);
179 State = UrlParserUserInfo;
181 State = UrlParserHost;
184 IsrightBracket =
FALSE;
185 Field = HTTP_URI_FIELD_MAX;
187 Authority = Url + UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Offset;
188 Length = UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Length;
189 for (Char = Authority; Char < Authority + Length; Char++) {
192 case UrlParserStateMax:
193 return EFI_INVALID_PARAMETER;
195 case UrlParserHostStart:
196 case UrlParserPortStart:
199 case UrlParserUserInfo:
200 Field = HTTP_URI_FIELD_USERINFO;
204 Field = HTTP_URI_FIELD_HOST;
207 case UrlParserHostIpv6:
208 Field = HTTP_URI_FIELD_HOST;
212 Field = HTTP_URI_FIELD_PORT;
222 ASSERT (Field < HTTP_URI_FIELD_MAX);
223 if (Field == OldField) {
224 UrlParser->FieldData[Field].Length++;
231 UrlParser->FieldBitMap |= BIT (Field);
232 UrlParser->FieldData[Field].Offset = (UINT32)(Char - Url);
233 UrlParser->FieldData[Field].Length = 1;
252 IN HTTP_URL_PARSE_STATE State
255 if ((Char ==
' ') || (Char ==
'\r') || (Char ==
'\n')) {
256 return UrlParserStateMax;
269 case UrlParserUrlStart:
270 if ((Char ==
'*') || (Char ==
'/')) {
271 return UrlParserPath;
274 return UrlParserScheme;
276 case UrlParserScheme:
278 return UrlParserSchemeColon;
283 case UrlParserSchemeColon:
285 return UrlParserSchemeColonSlash;
290 case UrlParserSchemeColonSlash:
292 return UrlParserSchemeColonSlashSlash;
297 case UrlParserAtInAuthority:
299 return UrlParserStateMax;
302 case UrlParserAuthority:
303 case UrlParserSchemeColonSlashSlash:
305 return UrlParserAtInAuthority;
309 return UrlParserPath;
313 return UrlParserQueryStart;
317 return UrlParserFragmentStart;
320 return UrlParserAuthority;
324 return UrlParserQueryStart;
328 return UrlParserFragmentStart;
334 case UrlParserQueryStart:
336 return UrlParserFragmentStart;
339 return UrlParserQuery;
341 case UrlParserFragmentStart:
342 return UrlParserFragment;
373 IN BOOLEAN IsConnectMethod,
377 HTTP_URL_PARSE_STATE State;
387 if ((Url ==
NULL) || (Length == 0) || (UrlParser ==
NULL)) {
388 return EFI_INVALID_PARAMETER;
392 if (Parser ==
NULL) {
393 return EFI_OUT_OF_RESOURCES;
396 if (IsConnectMethod) {
400 State = UrlParserAuthority;
402 State = UrlParserUrlStart;
405 Field = HTTP_URI_FIELD_MAX;
408 for (Char = Url; Char < Url + Length; Char++) {
415 case UrlParserStateMax:
417 return EFI_INVALID_PARAMETER;
419 case UrlParserSchemeColon:
420 case UrlParserSchemeColonSlash:
421 case UrlParserSchemeColonSlashSlash:
422 case UrlParserQueryStart:
423 case UrlParserFragmentStart:
429 case UrlParserScheme:
430 Field = HTTP_URI_FIELD_SCHEME;
433 case UrlParserAtInAuthority:
435 case UrlParserAuthority:
436 Field = HTTP_URI_FIELD_AUTHORITY;
440 Field = HTTP_URI_FIELD_PATH;
444 Field = HTTP_URI_FIELD_QUERY;
447 case UrlParserFragment:
448 Field = HTTP_URI_FIELD_FRAGMENT;
458 ASSERT (Field < HTTP_URI_FIELD_MAX);
459 if (Field == OldField) {
460 Parser->FieldData[Field].Length++;
467 Parser->FieldBitMap |= BIT (Field);
468 Parser->FieldData[Field].Offset = (UINT32)(Char - Url);
469 Parser->FieldData[Field].Length = 1;
476 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0) {
478 if (EFI_ERROR (Status)) {
517 if ((Url ==
NULL) || (UrlParser ==
NULL) || (HostName ==
NULL)) {
518 return EFI_INVALID_PARAMETER;
523 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
524 return EFI_NOT_FOUND;
527 Name =
AllocatePool (Parser->FieldData[HTTP_URI_FIELD_HOST].Length + 1);
529 return EFI_OUT_OF_RESOURCES;
533 Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,
534 Parser->FieldData[HTTP_URI_FIELD_HOST].Length,
538 if (EFI_ERROR (Status)) {
543 Name[ResultLength] =
'\0';
576 if ((Url ==
NULL) || (UrlParser ==
NULL) || (Ip4Address ==
NULL)) {
577 return EFI_INVALID_PARAMETER;
582 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
583 return EFI_NOT_FOUND;
586 Ip4String =
AllocatePool (Parser->FieldData[HTTP_URI_FIELD_HOST].Length + 1);
587 if (Ip4String ==
NULL) {
588 return EFI_OUT_OF_RESOURCES;
592 Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,
593 Parser->FieldData[HTTP_URI_FIELD_HOST].Length,
597 if (EFI_ERROR (Status)) {
602 Ip4String[ResultLength] =
'\0';
639 if ((Url ==
NULL) || (UrlParser ==
NULL) || (Ip6Address ==
NULL)) {
640 return EFI_INVALID_PARAMETER;
645 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {
646 return EFI_NOT_FOUND;
652 Length = Parser->FieldData[HTTP_URI_FIELD_HOST].Length;
654 return EFI_INVALID_PARAMETER;
657 Ptr = Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset;
658 if ((Ptr[0] !=
'[') || (Ptr[Length - 1] !=
']')) {
659 return EFI_INVALID_PARAMETER;
663 if (Ip6String ==
NULL) {
664 return EFI_OUT_OF_RESOURCES;
673 if (EFI_ERROR (Status)) {
678 Ip6String[ResultLength] =
'\0';
715 if ((Url ==
NULL) || (UrlParser ==
NULL) || (Port ==
NULL)) {
716 return EFI_INVALID_PARAMETER;
724 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {
725 return EFI_NOT_FOUND;
728 PortString =
AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PORT].Length + 1);
729 if (PortString ==
NULL) {
730 return EFI_OUT_OF_RESOURCES;
734 Url + Parser->FieldData[HTTP_URI_FIELD_PORT].Offset,
735 Parser->FieldData[HTTP_URI_FIELD_PORT].Length,
739 if (EFI_ERROR (Status)) {
743 PortString[ResultLength] =
'\0';
745 while (Index < ResultLength) {
746 if (!NET_IS_DIGIT (PortString[Index])) {
747 Status = EFI_INVALID_PARAMETER;
756 if (EFI_ERROR (Status) || (Data > HTTP_URI_PORT_MAX_NUM)) {
757 Status = EFI_INVALID_PARAMETER;
761 *Port = (UINT16)Data;
797 if ((Url ==
NULL) || (UrlParser ==
NULL) || (Path ==
NULL)) {
798 return EFI_INVALID_PARAMETER;
803 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {
804 return EFI_NOT_FOUND;
807 PathStr =
AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PATH].Length + 1);
808 if (PathStr ==
NULL) {
809 return EFI_OUT_OF_RESOURCES;
813 Url + Parser->FieldData[HTTP_URI_FIELD_PATH].Offset,
814 Parser->FieldData[HTTP_URI_FIELD_PATH].Length,
818 if (EFI_ERROR (Status)) {
823 PathStr[ResultLength] =
'\0';
863 if ((HeaderCount == 0) || (Headers ==
NULL) || (FieldName ==
NULL)) {
867 for (Index = 0; Index < HeaderCount; Index++) {
871 if (
AsciiStriCmp (Headers[Index].FieldName, FieldName) == 0) {
872 return &Headers[Index];
881 BodyParserBodyIdentity,
882 BodyParserChunkSizeStart,
884 BodyParserChunkSizeEndCR,
885 BodyParserChunkExtStart,
886 BodyParserChunkDataStart,
887 BodyParserChunkDataEnd,
888 BodyParserChunkDataEndCR,
891 BodyParserLastCRLFEnd,
894} HTTP_BODY_PARSE_STATE;
899 BOOLEAN ContentLengthIsValid;
904 UINTN ParsedBodyLength;
905 HTTP_BODY_PARSE_STATE State;
906 UINTN CurrentChunkSize;
907 UINTN CurrentChunkParsedSize;
923 if ((Char >=
'0') && (Char <=
'9')) {
951 if (Header ==
NULL) {
952 return EFI_NOT_FOUND;
977 if (Header ==
NULL) {
981 if (
AsciiStriCmp (Header->FieldValue,
"identity") != 0) {
1012 if (Method == HttpMethodHead) {
1016 if ((StatusCode == HTTP_STATUS_100_CONTINUE) ||
1017 (StatusCode == HTTP_STATUS_101_SWITCHING_PROTOCOLS) ||
1018 (StatusCode == HTTP_STATUS_204_NO_CONTENT) ||
1019 (StatusCode == HTTP_STATUS_304_NOT_MODIFIED))
1057 OUT VOID **MsgParser
1063 if ((HeaderCount != 0) && (Headers ==
NULL)) {
1064 return EFI_INVALID_PARAMETER;
1067 if (MsgParser ==
NULL) {
1068 return EFI_INVALID_PARAMETER;
1072 if (Parser ==
NULL) {
1073 return EFI_OUT_OF_RESOURCES;
1076 Parser->State = BodyParserBodyStart;
1091 if (!EFI_ERROR (Status)) {
1092 Parser->ContentLengthIsValid =
TRUE;
1103 if (Parser->IgnoreBody) {
1104 Parser->State = BodyParserComplete;
1106 Parser->Callback = Callback;
1107 Parser->Context = Context;
1110 *MsgParser = Parser;
1132 IN OUT VOID *MsgParser,
1138 UINTN RemainderLengthInThis;
1139 UINTN LengthForCallback;
1140 UINTN PortionLength;
1144 if ((BodyLength == 0) || (Body ==
NULL)) {
1145 return EFI_INVALID_PARAMETER;
1148 if (MsgParser ==
NULL) {
1149 return EFI_INVALID_PARAMETER;
1154 if (Parser->IgnoreBody) {
1155 Parser->State = BodyParserComplete;
1156 if (Parser->Callback !=
NULL) {
1157 Status = Parser->Callback (
1158 BodyParseEventOnComplete,
1163 if (EFI_ERROR (Status)) {
1171 if (Parser->State == BodyParserBodyStart) {
1172 Parser->ParsedBodyLength = 0;
1173 if (Parser->IsChunked) {
1174 Parser->State = BodyParserChunkSizeStart;
1176 Parser->State = BodyParserBodyIdentity;
1183 for (Char = Body; Char < Body + BodyLength; ) {
1184 switch (Parser->State) {
1185 case BodyParserStateMax:
1188 case BodyParserBodyIdentity:
1192 PortionLength =
MIN (
1194 Parser->ContentLength - Parser->ParsedBodyLength
1196 if (PortionLength == 0) {
1200 PortionLength = BodyLength;
1201 Parser->ContentLength = PortionLength;
1204 if (Parser->Callback !=
NULL) {
1205 Status = Parser->Callback (
1206 BodyParseEventOnData,
1211 if (EFI_ERROR (Status)) {
1216 Char += PortionLength;
1217 Parser->ParsedBodyLength += PortionLength;
1218 if (Parser->ParsedBodyLength == Parser->ContentLength) {
1219 Parser->State = BodyParserComplete;
1220 if (Parser->Callback !=
NULL) {
1221 Status = Parser->Callback (
1222 BodyParseEventOnComplete,
1227 if (EFI_ERROR (Status)) {
1235 case BodyParserChunkSizeStart:
1239 Parser->CurrentChunkSize = 0;
1240 Parser->State = BodyParserChunkSize;
1241 case BodyParserChunkSize:
1242 if (!NET_IS_HEX_CHAR (*Char)) {
1244 Parser->State = BodyParserChunkExtStart;
1246 }
else if (*Char ==
'\r') {
1247 Parser->State = BodyParserChunkSizeEndCR;
1250 Parser->State = BodyParserStateMax;
1256 if (Parser->CurrentChunkSize > (((~((
UINTN)0)) - 16) / 16)) {
1257 return EFI_INVALID_PARAMETER;
1264 case BodyParserChunkExtStart:
1268 if (*Char ==
'\r') {
1269 Parser->State = BodyParserChunkSizeEndCR;
1275 case BodyParserChunkSizeEndCR:
1276 if (*Char !=
'\n') {
1277 Parser->State = BodyParserStateMax;
1282 if (Parser->CurrentChunkSize == 0) {
1288 Parser->ContentLengthIsValid =
TRUE;
1289 Parser->State = BodyParserLastCRLF;
1293 Parser->State = BodyParserChunkDataStart;
1294 Parser->CurrentChunkParsedSize = 0;
1297 case BodyParserLastCRLF:
1302 if (*Char ==
'\r') {
1304 Parser->State = BodyParserLastCRLFEnd;
1307 Parser->State = BodyParserTrailer;
1311 case BodyParserLastCRLFEnd:
1312 if (*Char ==
'\n') {
1313 Parser->State = BodyParserComplete;
1315 if (Parser->Callback !=
NULL) {
1316 Status = Parser->Callback (
1317 BodyParseEventOnComplete,
1322 if (EFI_ERROR (Status)) {
1329 Parser->State = BodyParserStateMax;
1333 case BodyParserTrailer:
1334 if (*Char ==
'\r') {
1335 Parser->State = BodyParserChunkSizeEndCR;
1341 case BodyParserChunkDataStart:
1345 RemainderLengthInThis = BodyLength - (Char - Body);
1346 LengthForCallback =
MIN (Parser->CurrentChunkSize - Parser->CurrentChunkParsedSize, RemainderLengthInThis);
1347 if (Parser->Callback !=
NULL) {
1348 Status = Parser->Callback (
1349 BodyParseEventOnData,
1354 if (EFI_ERROR (Status)) {
1359 Char += LengthForCallback;
1360 Parser->ContentLength += LengthForCallback;
1361 Parser->CurrentChunkParsedSize += LengthForCallback;
1362 if (Parser->CurrentChunkParsedSize == Parser->CurrentChunkSize) {
1363 Parser->State = BodyParserChunkDataEnd;
1368 case BodyParserChunkDataEnd:
1369 if (*Char ==
'\r') {
1370 Parser->State = BodyParserChunkDataEndCR;
1372 Parser->State = BodyParserStateMax;
1378 case BodyParserChunkDataEndCR:
1379 if (*Char !=
'\n') {
1380 Parser->State = BodyParserStateMax;
1385 Parser->State = BodyParserChunkSizeStart;
1393 if (Parser->State == BodyParserStateMax) {
1417 if (MsgParser ==
NULL) {
1423 if (Parser->State == BodyParserComplete) {
1452 if ((MsgParser ==
NULL) || (ContentLength ==
NULL)) {
1453 return EFI_INVALID_PARAMETER;
1458 if (!Parser->ContentLengthIsValid) {
1459 return EFI_NOT_READY;
1462 *ContentLength = Parser->ContentLength;
1506 if (*Token == Separator) {
1507 return (CHAR8 *)(Token + 1);
1535 UINTN FieldNameSize;
1536 UINTN FieldValueSize;
1538 if ((HttpHeader ==
NULL) || (FieldName ==
NULL) || (FieldValue ==
NULL)) {
1539 return EFI_INVALID_PARAMETER;
1542 if (HttpHeader->FieldName !=
NULL) {
1546 if (HttpHeader->FieldValue !=
NULL) {
1552 if (HttpHeader->FieldName ==
NULL) {
1553 return EFI_OUT_OF_RESOURCES;
1556 CopyMem (HttpHeader->FieldName, FieldName, FieldNameSize);
1557 HttpHeader->FieldName[FieldNameSize - 1] = 0;
1561 if (HttpHeader->FieldValue ==
NULL) {
1563 return EFI_OUT_OF_RESOURCES;
1566 CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize);
1567 HttpHeader->FieldValue[FieldValueSize - 1] = 0;
1587 OUT CHAR8 **FieldName,
1588 OUT CHAR8 **FieldValue
1591 CHAR8 *FieldNameStr;
1592 CHAR8 *FieldValueStr;
1596 if ((String ==
NULL) || (FieldName ==
NULL) || (FieldValue ==
NULL)) {
1602 FieldNameStr =
NULL;
1603 FieldValueStr =
NULL;
1611 if (EndofHeader ==
NULL) {
1630 FieldNameStr = String;
1632 if (FieldValueStr ==
NULL) {
1639 *(FieldValueStr - 1) = 0;
1645 if ((*FieldValueStr ==
' ') || (*FieldValueStr ==
'\t')) {
1649 if ((
UINTN)EndofHeader - (
UINTN)FieldValueStr < 1) {
1657 }
else if (*FieldValueStr ==
'\r') {
1661 if ((
UINTN)EndofHeader - (
UINTN)FieldValueStr < 3) {
1668 if (*(FieldValueStr + 1) ==
'\n' ) {
1669 if ((*(FieldValueStr + 2) ==
' ') || (*(FieldValueStr + 2) ==
'\t')) {
1670 FieldValueStr = FieldValueStr + 3;
1691 StrPtr = FieldValueStr;
1697 if ((StrPtr ==
NULL) || (*StrPtr !=
'\n')) {
1705 }
while (*StrPtr ==
' ' || *StrPtr ==
'\t');
1715 *FieldName = FieldNameStr;
1716 *FieldValue = FieldValueStr;
1737 if (HeaderFields !=
NULL) {
1738 for (Index = 0; Index < FieldCount; Index++) {
1739 if (HeaderFields[Index].FieldName !=
NULL) {
1740 FreePool (HeaderFields[Index].FieldName);
1743 if (HeaderFields[Index].FieldValue !=
NULL) {
1744 FreePool (HeaderFields[Index].FieldValue);
1778 OUT CHAR8 **RequestMsg,
1799 HttpUtilitiesProtocol =
NULL;
1807 if (((Message ==
NULL) || (RequestMsg ==
NULL) || (RequestMsgSize ==
NULL)) ||
1808 ((Message->Data.Request !=
NULL) && (Url ==
NULL)) ||
1809 ((Message->Data.Request !=
NULL) && (Message->HeaderCount == 0)) ||
1810 ((Message->Data.Request ==
NULL) && (Message->HeaderCount != 0)) ||
1811 ((Message->Data.Request ==
NULL) && (Message->HeaderCount == 0) && (Message->BodyLength == 0)))
1813 return EFI_INVALID_PARAMETER;
1816 if (Message->HeaderCount != 0) {
1820 Status =
gBS->LocateProtocol (
1821 &gEfiHttpUtilitiesProtocolGuid,
1823 (VOID **)&HttpUtilitiesProtocol
1826 if (EFI_ERROR (Status)) {
1827 DEBUG ((DEBUG_ERROR,
"Failed to locate Http Utilities protocol. Status = %r.\n", Status));
1835 if (AppendList ==
NULL) {
1836 return EFI_OUT_OF_RESOURCES;
1839 for (Index = 0; Index < Message->HeaderCount; Index++) {
1840 AppendList[Index] = &Message->Headers[Index];
1846 Status = HttpUtilitiesProtocol->Build (
1847 HttpUtilitiesProtocol,
1852 Message->HeaderCount,
1860 if (EFI_ERROR (Status) || (HttpHdr ==
NULL)) {
1868 if (Message->HeaderCount != 0) {
1869 MsgSize = HttpHdrSize;
1875 if (Message->Data.Request !=
NULL) {
1882 MsgSize += Message->BodyLength;
1889 if (*RequestMsg ==
NULL) {
1890 Status = EFI_OUT_OF_RESOURCES;
1894 RequestPtr = *RequestMsg;
1898 if (Message->Data.Request !=
NULL) {
1899 switch (Message->Data.Request->Method) {
1901 StrLength =
sizeof (HTTP_METHOD_GET) - 1;
1902 CopyMem (RequestPtr, HTTP_METHOD_GET, StrLength);
1903 RequestPtr += StrLength;
1906 StrLength =
sizeof (HTTP_METHOD_PUT) - 1;
1907 CopyMem (RequestPtr, HTTP_METHOD_PUT, StrLength);
1908 RequestPtr += StrLength;
1910 case HttpMethodPatch:
1911 StrLength =
sizeof (HTTP_METHOD_PATCH) - 1;
1912 CopyMem (RequestPtr, HTTP_METHOD_PATCH, StrLength);
1913 RequestPtr += StrLength;
1915 case HttpMethodPost:
1916 StrLength =
sizeof (HTTP_METHOD_POST) - 1;
1917 CopyMem (RequestPtr, HTTP_METHOD_POST, StrLength);
1918 RequestPtr += StrLength;
1920 case HttpMethodHead:
1921 StrLength =
sizeof (HTTP_METHOD_HEAD) - 1;
1922 CopyMem (RequestPtr, HTTP_METHOD_HEAD, StrLength);
1923 RequestPtr += StrLength;
1925 case HttpMethodDelete:
1926 StrLength =
sizeof (HTTP_METHOD_DELETE) - 1;
1927 CopyMem (RequestPtr, HTTP_METHOD_DELETE, StrLength);
1928 RequestPtr += StrLength;
1930 case HttpMethodConnect:
1931 StrLength =
sizeof (HTTP_METHOD_CONNECT) - 1;
1932 CopyMem (RequestPtr, HTTP_METHOD_CONNECT, StrLength);
1933 RequestPtr += StrLength;
1937 Status = EFI_INVALID_PARAMETER;
1942 CopyMem (RequestPtr, EMPTY_SPACE, StrLength);
1943 RequestPtr += StrLength;
1946 CopyMem (RequestPtr, Url, StrLength);
1947 RequestPtr += StrLength;
1949 StrLength =
sizeof (HTTP_VERSION_CRLF_STR) - 1;
1950 CopyMem (RequestPtr, HTTP_VERSION_CRLF_STR, StrLength);
1951 RequestPtr += StrLength;
1953 if (HttpHdr !=
NULL) {
1957 CopyMem (RequestPtr, HttpHdr, HttpHdrSize);
1958 RequestPtr += HttpHdrSize;
1965 if (Message->Body !=
NULL) {
1966 CopyMem (RequestPtr, Message->Body, Message->BodyLength);
1967 RequestPtr += Message->BodyLength;
1973 (*RequestMsgSize) = (
UINTN)(RequestPtr) - (
UINTN)(*RequestMsg);
1979 if (*RequestMsg !=
NULL) {
1987 if (HttpHdr !=
NULL) {
2012 switch (StatusCode) {
2014 return HTTP_STATUS_100_CONTINUE;
2016 return HTTP_STATUS_101_SWITCHING_PROTOCOLS;
2018 return HTTP_STATUS_200_OK;
2020 return HTTP_STATUS_201_CREATED;
2022 return HTTP_STATUS_202_ACCEPTED;
2024 return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION;
2026 return HTTP_STATUS_204_NO_CONTENT;
2028 return HTTP_STATUS_205_RESET_CONTENT;
2030 return HTTP_STATUS_206_PARTIAL_CONTENT;
2032 return HTTP_STATUS_300_MULTIPLE_CHOICES;
2034 return HTTP_STATUS_301_MOVED_PERMANENTLY;
2036 return HTTP_STATUS_302_FOUND;
2038 return HTTP_STATUS_303_SEE_OTHER;
2040 return HTTP_STATUS_304_NOT_MODIFIED;
2042 return HTTP_STATUS_305_USE_PROXY;
2044 return HTTP_STATUS_307_TEMPORARY_REDIRECT;
2046 return HTTP_STATUS_308_PERMANENT_REDIRECT;
2048 return HTTP_STATUS_400_BAD_REQUEST;
2050 return HTTP_STATUS_401_UNAUTHORIZED;
2052 return HTTP_STATUS_402_PAYMENT_REQUIRED;
2054 return HTTP_STATUS_403_FORBIDDEN;
2056 return HTTP_STATUS_404_NOT_FOUND;
2058 return HTTP_STATUS_405_METHOD_NOT_ALLOWED;
2060 return HTTP_STATUS_406_NOT_ACCEPTABLE;
2062 return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED;
2064 return HTTP_STATUS_408_REQUEST_TIME_OUT;
2066 return HTTP_STATUS_409_CONFLICT;
2068 return HTTP_STATUS_410_GONE;
2070 return HTTP_STATUS_411_LENGTH_REQUIRED;
2072 return HTTP_STATUS_412_PRECONDITION_FAILED;
2074 return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE;
2076 return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE;
2078 return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE;
2080 return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED;
2082 return HTTP_STATUS_417_EXPECTATION_FAILED;
2084 return HTTP_STATUS_429_TOO_MANY_REQUESTS;
2086 return HTTP_STATUS_500_INTERNAL_SERVER_ERROR;
2088 return HTTP_STATUS_501_NOT_IMPLEMENTED;
2090 return HTTP_STATUS_502_BAD_GATEWAY;
2092 return HTTP_STATUS_503_SERVICE_UNAVAILABLE;
2094 return HTTP_STATUS_504_GATEWAY_TIME_OUT;
2096 return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED;
2099 return HTTP_STATUS_UNSUPPORTED_STATUS;
2117 IN CHAR8 *DeleteList[],
2124 if (FieldName ==
NULL) {
2128 for (Index = 0; Index < DeleteCount; Index++) {
2129 if (DeleteList[Index] ==
NULL) {
2133 if (
AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {
2151 UINTN MaxHeaderCount
2156 if (MaxHeaderCount == 0) {
2161 if (HttpIoHeader ==
NULL) {
2165 HttpIoHeader->MaxHeaderCount = MaxHeaderCount;
2168 return HttpIoHeader;
2184 if (HttpIoHeader !=
NULL) {
2185 if (HttpIoHeader->HeaderCount != 0) {
2186 for (Index = 0; Index < HttpIoHeader->HeaderCount; Index++) {
2187 FreePool (HttpIoHeader->Headers[Index].FieldName);
2188 ZeroMem (HttpIoHeader->Headers[Index].FieldValue,
AsciiStrSize (HttpIoHeader->Headers[Index].FieldValue));
2189 FreePool (HttpIoHeader->Headers[Index].FieldValue);
2213 IN CHAR8 *FieldName,
2214 IN CHAR8 *FieldValue
2219 CHAR8 *NewFieldValue;
2221 if ((HttpIoHeader ==
NULL) || (FieldName ==
NULL) || (FieldValue ==
NULL)) {
2222 return EFI_INVALID_PARAMETER;
2225 Header =
HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);
2226 if (Header ==
NULL) {
2230 if (HttpIoHeader->HeaderCount >= HttpIoHeader->MaxHeaderCount) {
2231 return EFI_OUT_OF_RESOURCES;
2234 Header = &HttpIoHeader->Headers[HttpIoHeader->HeaderCount];
2238 if (Header->FieldName ==
NULL) {
2239 return EFI_OUT_OF_RESOURCES;
2243 Header->FieldName[
StrSize -1] =
'\0';
2247 if (Header->FieldValue ==
NULL) {
2249 return EFI_OUT_OF_RESOURCES;
2253 Header->FieldValue[
StrSize -1] =
'\0';
2255 HttpIoHeader->HeaderCount++;
2262 if (NewFieldValue ==
NULL) {
2263 return EFI_OUT_OF_RESOURCES;
2267 NewFieldValue[
StrSize -1] =
'\0';
2269 if (Header->FieldValue !=
NULL) {
2273 Header->FieldValue = NewFieldValue;
INTN EFIAPI AsciiStriCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
RETURN_STATUS EFIAPI AsciiStrDecimalToUintnS(IN CONST CHAR8 *String, OUT CHAR8 **EndPointer OPTIONAL, OUT UINTN *Data)
UINTN EFIAPI AsciiStrHexToUintn(IN CONST CHAR8 *String)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
CHAR8 *EFIAPI AsciiStrStr(IN CONST CHAR8 *String, IN CONST CHAR8 *SearchString)
CHAR8 EFIAPI AsciiCharToUpper(IN CHAR8 Chr)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINTN HttpIoHexCharToUintn(IN CHAR8 Char)
EFI_STATUS EFIAPI HttpSetFieldNameAndValue(IN OUT EFI_HTTP_HEADER *HttpHeader, IN CONST CHAR8 *FieldName, IN CONST CHAR8 *FieldValue)
BOOLEAN HttpIoNoMessageBody(IN EFI_HTTP_METHOD Method, IN EFI_HTTP_STATUS_CODE StatusCode)
EFI_STATUS EFIAPI HttpUrlGetHostName(IN CHAR8 *Url, IN VOID *UrlParser, OUT CHAR8 **HostName)
EFI_STATUS EFIAPI HttpInitMsgParser(IN EFI_HTTP_METHOD Method, IN EFI_HTTP_STATUS_CODE StatusCode, IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers, IN HTTP_BODY_PARSER_CALLBACK Callback, IN VOID *Context, OUT VOID **MsgParser)
VOID HttpIoFreeHeader(IN HTTP_IO_HEADER *HttpIoHeader)
EFI_STATUS EFIAPI UriPercentDecode(IN CHAR8 *Buffer, IN UINT32 BufferLength, OUT CHAR8 *ResultBuffer, OUT UINT32 *ResultLength)
EFI_STATUS EFIAPI HttpUrlGetPort(IN CHAR8 *Url, IN VOID *UrlParser, OUT UINT16 *Port)
HTTP_URL_PARSE_STATE NetHttpParseAuthorityChar(IN CHAR8 Char, IN HTTP_URL_PARSE_STATE State, IN BOOLEAN *IsRightBracket)
BOOLEAN HttpIoIsChunked(IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers)
EFI_STATUS NetHttpParseAuthority(IN CHAR8 *Url, IN BOOLEAN FoundAt, IN OUT HTTP_URL_PARSER *UrlParser)
HTTP_URL_PARSE_STATE NetHttpParseUrlChar(IN CHAR8 Char, IN HTTP_URL_PARSE_STATE State)
HTTP_IO_HEADER * HttpIoCreateHeader(UINTN MaxHeaderCount)
EFI_HTTP_HEADER *EFIAPI HttpFindHeader(IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers, IN CHAR8 *FieldName)
EFI_STATUS EFIAPI HttpUrlGetPath(IN CHAR8 *Url, IN VOID *UrlParser, OUT CHAR8 **Path)
VOID EFIAPI HttpFreeHeaderFields(IN EFI_HTTP_HEADER *HeaderFields, IN UINTN FieldCount)
CHAR8 *EFIAPI HttpGetFieldNameAndValue(IN CHAR8 *String, OUT CHAR8 **FieldName, OUT CHAR8 **FieldValue)
EFI_STATUS EFIAPI HttpUrlGetIp4(IN CHAR8 *Url, IN VOID *UrlParser, OUT EFI_IPv4_ADDRESS *Ip4Address)
EFI_STATUS EFIAPI HttpUrlGetIp6(IN CHAR8 *Url, IN VOID *UrlParser, OUT EFI_IPv6_ADDRESS *Ip6Address)
EFI_STATUS EFIAPI HttpGenRequestMessage(IN CONST EFI_HTTP_MESSAGE *Message, IN CONST CHAR8 *Url, OUT CHAR8 **RequestMsg, OUT UINTN *RequestMsgSize)
EFI_STATUS EFIAPI HttpParseMessageBody(IN OUT VOID *MsgParser, IN UINTN BodyLength, IN CHAR8 *Body)
EFI_STATUS HttpIoSetHeader(IN HTTP_IO_HEADER *HttpIoHeader, IN CHAR8 *FieldName, IN CHAR8 *FieldValue)
BOOLEAN EFIAPI HttpIsValidHttpHeader(IN CHAR8 *DeleteList[], IN UINTN DeleteCount, IN CHAR8 *FieldName)
CHAR8 * AsciiStrGetNextToken(IN CONST CHAR8 *String, IN CHAR8 Separator)
EFI_STATUS EFIAPI HttpGetEntityLength(IN VOID *MsgParser, OUT UINTN *ContentLength)
EFI_STATUS HttpIoParseContentLengthHeader(IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers, OUT UINTN *ContentLength)
VOID EFIAPI HttpFreeMsgParser(IN VOID *MsgParser)
VOID EFIAPI HttpUrlFreeParser(IN VOID *UrlParser)
EFI_STATUS EFIAPI HttpParseUrl(IN CHAR8 *Url, IN UINT32 Length, IN BOOLEAN IsConnectMethod, OUT VOID **UrlParser)
BOOLEAN EFIAPI HttpIsMessageComplete(IN VOID *MsgParser)
EFI_HTTP_STATUS_CODE EFIAPI HttpMappingToStatusCode(IN UINTN StatusCode)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define HTTP_HEADER_CONTENT_LENGTH
#define HTTP_HEADER_TRANSFER_ENCODING
#define HTTP_METHOD_MAXIMUM_LEN
EFI_STATUS(EFIAPI * HTTP_BODY_PARSER_CALLBACK)(IN HTTP_BODY_PARSE_EVENT EventType, IN CHAR8 *Data, IN UINTN Length, IN VOID *Context)
#define DEBUG(Expression)
EFI_STATUS EFIAPI NetLibAsciiStrToIp4(IN CONST CHAR8 *String, OUT EFI_IPv4_ADDRESS *Ip4Address)
EFI_STATUS EFIAPI NetLibAsciiStrToIp6(IN CONST CHAR8 *String, OUT EFI_IPv6_ADDRESS *Ip6Address)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID EFIAPI Exit(IN EFI_STATUS Status)