mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
215 lines
6.3 KiB
C
215 lines
6.3 KiB
C
/** @file
|
|
Support functions declaration for UEFI HTTP boot driver.
|
|
|
|
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
|
|
(C) Copyright 2020 Hewlett-Packard Development Company, L.P.<BR>
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
/**
|
|
Get the Nic handle using any child handle in the IPv4 stack.
|
|
|
|
@param[in] ControllerHandle Pointer to child handle over IPv4.
|
|
|
|
@return NicHandle The pointer to the Nic handle.
|
|
@return NULL Can't find the Nic handle.
|
|
|
|
**/
|
|
EFI_HANDLE
|
|
HttpBootGetNicByIp4Children (
|
|
IN EFI_HANDLE ControllerHandle
|
|
);
|
|
|
|
/**
|
|
Get the Nic handle using any child handle in the IPv6 stack.
|
|
|
|
@param[in] ControllerHandle Pointer to child handle over IPv6.
|
|
|
|
@return NicHandle The pointer to the Nic handle.
|
|
@return NULL Can't find the Nic handle.
|
|
|
|
**/
|
|
EFI_HANDLE
|
|
HttpBootGetNicByIp6Children (
|
|
IN EFI_HANDLE ControllerHandle
|
|
);
|
|
|
|
/**
|
|
This function is to convert UINTN to ASCII string with the required formatting.
|
|
|
|
@param[in] Number Numeric value to be converted.
|
|
@param[in] Buffer The pointer to the buffer for ASCII string.
|
|
@param[in] Length The length of the required format.
|
|
|
|
**/
|
|
VOID
|
|
HttpBootUintnToAscDecWithFormat (
|
|
IN UINTN Number,
|
|
IN UINT8 *Buffer,
|
|
IN INTN Length
|
|
);
|
|
|
|
/**
|
|
This function is to display the IPv4 address.
|
|
|
|
@param[in] Ip The pointer to the IPv4 address.
|
|
|
|
**/
|
|
VOID
|
|
HttpBootShowIp4Addr (
|
|
IN EFI_IPv4_ADDRESS *Ip
|
|
);
|
|
|
|
/**
|
|
This function is to display the IPv6 address.
|
|
|
|
@param[in] Ip The pointer to the IPv6 address.
|
|
|
|
**/
|
|
VOID
|
|
HttpBootShowIp6Addr (
|
|
IN EFI_IPv6_ADDRESS *Ip
|
|
);
|
|
|
|
/**
|
|
This function is to display the HTTP error status.
|
|
|
|
@param[in] StatusCode The status code value in HTTP message.
|
|
|
|
**/
|
|
VOID
|
|
HttpBootPrintErrorMessage (
|
|
EFI_HTTP_STATUS_CODE StatusCode
|
|
);
|
|
|
|
/**
|
|
Retrieve the host address using the EFI_DNS6_PROTOCOL.
|
|
|
|
@param[in] Private The pointer to the driver's private data.
|
|
@param[in] HostName Pointer to buffer containing hostname.
|
|
@param[out] IpAddress On output, pointer to buffer containing IPv6 address.
|
|
|
|
@retval EFI_SUCCESS Operation succeeded.
|
|
@retval EFI_DEVICE_ERROR An unexpected network error occurred.
|
|
@retval Others Other errors as indicated.
|
|
**/
|
|
EFI_STATUS
|
|
HttpBootDns (
|
|
IN HTTP_BOOT_PRIVATE_DATA *Private,
|
|
IN CHAR16 *HostName,
|
|
OUT EFI_IPv6_ADDRESS *IpAddress
|
|
);
|
|
|
|
/**
|
|
Notify the callback function when an event is triggered.
|
|
|
|
@param[in] Event The triggered event.
|
|
@param[in] Context The opaque parameter to the function.
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
HttpBootCommonNotify (
|
|
IN EFI_EVENT Event,
|
|
IN VOID *Context
|
|
);
|
|
|
|
/**
|
|
This function checks the HTTP(S) URI scheme.
|
|
|
|
@param[in] Uri The pointer to the URI string.
|
|
|
|
@retval EFI_SUCCESS The URI scheme is valid.
|
|
@retval EFI_INVALID_PARAMETER The URI scheme is not HTTP or HTTPS.
|
|
@retval EFI_ACCESS_DENIED HTTP is disabled and the URI is HTTP.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
HttpBootCheckUriScheme (
|
|
IN CHAR8 *Uri
|
|
);
|
|
|
|
/**
|
|
Get the URI address string from the input device path.
|
|
|
|
Caller needs to free the buffers returned by this function.
|
|
|
|
@param[in] FilePath Pointer to the device path which contains a URI device path node.
|
|
@param[out] ProxyUriAddress The proxy URI address string extract from the device path (if it exists)
|
|
@param[out] EndPointUriAddress The endpoint URI address string for the endpoint host.
|
|
|
|
@retval EFI_SUCCESS The URI string is returned.
|
|
@retval EFI_INVALID_PARAMETER Parameters are NULL or device path is invalid.
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
HttpBootParseFilePath (
|
|
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
|
|
OUT CHAR8 **ProxyUriAddress,
|
|
OUT CHAR8 **EndPointUriAddress
|
|
);
|
|
|
|
/**
|
|
This function returns the image type according to server replied HTTP message
|
|
and also the image's URI info.
|
|
|
|
@param[in] Uri The pointer to the image's URI string.
|
|
@param[in] UriParser URI Parse result returned by NetHttpParseUrl().
|
|
@param[in] HeaderCount Number of HTTP header structures in Headers list.
|
|
@param[in] Headers Array containing list of HTTP headers.
|
|
@param[out] ImageType The image type of the downloaded file.
|
|
|
|
@retval EFI_SUCCESS The image type is returned in ImageType.
|
|
@retval EFI_INVALID_PARAMETER ImageType, Uri or UriParser is NULL.
|
|
@retval EFI_INVALID_PARAMETER HeaderCount is not zero, and Headers is NULL.
|
|
@retval EFI_NOT_FOUND Failed to identify the image type.
|
|
@retval Others Unexpected error happened.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
HttpBootCheckImageType (
|
|
IN CHAR8 *Uri,
|
|
IN VOID *UriParser,
|
|
IN UINTN HeaderCount,
|
|
IN EFI_HTTP_HEADER *Headers,
|
|
OUT HTTP_BOOT_IMAGE_TYPE *ImageType
|
|
);
|
|
|
|
/**
|
|
This function register the RAM disk info to the system.
|
|
|
|
@param[in] Private The pointer to the driver's private data.
|
|
@param[in] BufferSize The size of Buffer in bytes.
|
|
@param[in] Buffer The base address of the RAM disk.
|
|
@param[in] ImageType The image type of the file in Buffer.
|
|
|
|
@retval EFI_SUCCESS The RAM disk has been registered.
|
|
@retval EFI_NOT_FOUND No RAM disk protocol instances were found.
|
|
@retval EFI_UNSUPPORTED The ImageType is not supported.
|
|
@retval Others Unexpected error happened.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
HttpBootRegisterRamDisk (
|
|
IN HTTP_BOOT_PRIVATE_DATA *Private,
|
|
IN UINTN BufferSize,
|
|
IN VOID *Buffer,
|
|
IN HTTP_BOOT_IMAGE_TYPE ImageType
|
|
);
|
|
|
|
/**
|
|
Indicate if the HTTP status code indicates a redirection.
|
|
|
|
@param[in] StatusCode HTTP status code from server.
|
|
|
|
@return TRUE if it's redirection.
|
|
|
|
**/
|
|
BOOLEAN
|
|
HttpBootIsHttpRedirectStatusCode (
|
|
IN EFI_HTTP_STATUS_CODE StatusCode
|
|
);
|