NetworkPkg: Use the New Functions from HttpLib

After submitting changes for HttpLib, other modules should be able to use
those functions
1 remove the private function and their calls
2 update it with the functions from httpLib

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ghazi Belaam <Ghazi.belaam@hpe.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Samer EL-Haj-Mahmoud <elhaj@hpe.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Ghazi Belaam
2016-03-05 06:07:50 +08:00
committed by Fu Siyuan
parent 558b99a6a3
commit f58554fc3f
8 changed files with 35 additions and 721 deletions

View File

@@ -1375,107 +1375,6 @@ HttpTransmitTcp (
return Status;
}
/**
Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
in UEFI 2.5 specification.
@param[in] StatusCode The status code value in HTTP message.
@return Value defined in EFI_HTTP_STATUS_CODE .
**/
EFI_HTTP_STATUS_CODE
HttpMappingToStatusCode (
IN UINTN StatusCode
)
{
switch (StatusCode) {
case 100:
return HTTP_STATUS_100_CONTINUE;
case 101:
return HTTP_STATUS_101_SWITCHING_PROTOCOLS;
case 200:
return HTTP_STATUS_200_OK;
case 201:
return HTTP_STATUS_201_CREATED;
case 202:
return HTTP_STATUS_202_ACCEPTED;
case 203:
return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION;
case 204:
return HTTP_STATUS_204_NO_CONTENT;
case 205:
return HTTP_STATUS_205_RESET_CONTENT;
case 206:
return HTTP_STATUS_206_PARTIAL_CONTENT;
case 300:
return HTTP_STATUS_300_MULTIPLE_CHIOCES;
case 301:
return HTTP_STATUS_301_MOVED_PERMANENTLY;
case 302:
return HTTP_STATUS_302_FOUND;
case 303:
return HTTP_STATUS_303_SEE_OTHER;
case 304:
return HTTP_STATUS_304_NOT_MODIFIED;
case 305:
return HTTP_STATUS_305_USE_PROXY;
case 307:
return HTTP_STATUS_307_TEMPORARY_REDIRECT;
case 400:
return HTTP_STATUS_400_BAD_REQUEST;
case 401:
return HTTP_STATUS_401_UNAUTHORIZED;
case 402:
return HTTP_STATUS_402_PAYMENT_REQUIRED;
case 403:
return HTTP_STATUS_403_FORBIDDEN;
case 404:
return HTTP_STATUS_404_NOT_FOUND;
case 405:
return HTTP_STATUS_405_METHOD_NOT_ALLOWED;
case 406:
return HTTP_STATUS_406_NOT_ACCEPTABLE;
case 407:
return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED;
case 408:
return HTTP_STATUS_408_REQUEST_TIME_OUT;
case 409:
return HTTP_STATUS_409_CONFLICT;
case 410:
return HTTP_STATUS_410_GONE;
case 411:
return HTTP_STATUS_411_LENGTH_REQUIRED;
case 412:
return HTTP_STATUS_412_PRECONDITION_FAILED;
case 413:
return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE;
case 414:
return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE;
case 415:
return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE;
case 416:
return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED;
case 417:
return HTTP_STATUS_417_EXPECTATION_FAILED;
case 500:
return HTTP_STATUS_500_INTERNAL_SERVER_ERROR;
case 501:
return HTTP_STATUS_501_NOT_IMPLEMENTED;
case 502:
return HTTP_STATUS_502_BAD_GATEWAY;
case 503:
return HTTP_STATUS_503_SERVICE_UNAVAILABLE;
case 504:
return HTTP_STATUS_504_GATEWAY_TIME_OUT;
case 505:
return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED;
default:
return HTTP_STATUS_UNSUPPORTED_STATUS;
}
}
/**
Check whether the user's token or event has already
been enqueue on HTTP Tx or Rx Token list.
@@ -1584,14 +1483,15 @@ HttpTcpTransmit (
//
// Create request message.
//
RequestStr = HttpGenRequestString (
ValueInItem->HttpInstance,
Status = HttpGenRequestString (
ValueInItem->HttpToken->Message,
Url
Url,
&RequestStr
);
FreePool (Url);
if (RequestStr == NULL) {
return EFI_OUT_OF_RESOURCES;
if (EFI_ERROR (Status)){
return Status;
}
//
@@ -1942,159 +1842,3 @@ HttpTcpTokenCleanup (
}
}
/**
Generate HTTP request string.
@param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
@param[in] Message Pointer to storage containing HTTP message data.
@param[in] Url The URL of a remote host.
@return Pointer to the created HTTP request string.
@return NULL if any error occured.
**/
CHAR8 *
HttpGenRequestString (
IN HTTP_PROTOCOL *HttpInstance,
IN EFI_HTTP_MESSAGE *Message,
IN CHAR8 *Url
)
{
EFI_STATUS Status;
UINTN StrLength;
UINT8 *Request;
UINT8 *RequestPtr;
UINTN HttpHdrSize;
UINTN MsgSize;
BOOLEAN Success;
VOID *HttpHdr;
EFI_HTTP_HEADER **AppendList;
UINTN Index;
ASSERT (HttpInstance != NULL);
ASSERT (Message != NULL);
DEBUG ((EFI_D_ERROR, "HttpMethod - %x\n", Message->Data.Request->Method));
Request = NULL;
Success = FALSE;
HttpHdr = NULL;
AppendList = NULL;
//
// Build AppendList
//
AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * (Message->HeaderCount));
if (AppendList == NULL) {
return NULL;
}
for(Index = 0; Index < Message->HeaderCount; Index++){
AppendList[Index] = &Message->Headers[Index];
}
//
// Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
//
if (mHttpUtilities == NULL) {
return NULL;
}
//
// Build raw unformatted HTTP headers.
//
Status = mHttpUtilities->Build (
mHttpUtilities,
0,
NULL,
0,
NULL,
Message->HeaderCount,
AppendList,
&HttpHdrSize,
&HttpHdr
);
FreePool (AppendList);
if (EFI_ERROR (Status) || HttpHdr == NULL) {
return NULL;
}
//
// Calculate HTTP message length.
//
MsgSize = Message->BodyLength + HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (Url) +
AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
Request = AllocateZeroPool (MsgSize);
if (Request == NULL) {
goto Exit;
}
RequestPtr = Request;
//
// Construct header request
//
switch (Message->Data.Request->Method) {
case HttpMethodGet:
StrLength = sizeof (HTTP_METHOD_GET) - 1;
CopyMem (RequestPtr, HTTP_METHOD_GET, StrLength);
RequestPtr += StrLength;
break;
case HttpMethodHead:
StrLength = sizeof (HTTP_METHOD_HEAD) - 1;
CopyMem (RequestPtr, HTTP_METHOD_HEAD, StrLength);
RequestPtr += StrLength;
break;
default:
ASSERT (FALSE);
goto Exit;
}
StrLength = AsciiStrLen(" ");
CopyMem (RequestPtr, " ", StrLength);
RequestPtr += StrLength;
StrLength = AsciiStrLen (Url);
CopyMem (RequestPtr, Url, StrLength);
RequestPtr += StrLength;
StrLength = sizeof (HTTP_VERSION_CRLF_STR) - 1;
CopyMem (RequestPtr, HTTP_VERSION_CRLF_STR, StrLength);
RequestPtr += StrLength;
//
// Construct header
//
CopyMem (RequestPtr, HttpHdr, HttpHdrSize);
RequestPtr += HttpHdrSize;
//
// Construct body
//
if (Message->Body != NULL) {
CopyMem (RequestPtr, Message->Body, Message->BodyLength);
RequestPtr += Message->BodyLength;
}
//
// Done
//
*RequestPtr = 0;
Success = TRUE;
Exit:
if (!Success) {
if (Request != NULL) {
FreePool (Request);
}
Request = NULL;
}
if (HttpHdr != NULL) {
FreePool (HttpHdr);
}
return (CHAR8*) Request;
}