edk2/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.h
Michael Kubacki 58de02af29 NetworkPkg: Replace include guards with #pragma once
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>
2026-02-23 21:01:28 +00:00

112 lines
4.5 KiB
C

/** @file
The header files of Http Utilities functions for HttpUtilities driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
#include <Uefi.h>
//
// Libraries
//
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/HttpLib.h>
//
// Consumed Protocols
//
#include <Protocol/HttpUtilities.h>
#include <Protocol/Http.h>
//
// Protocol instances
//
extern EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol;
/**
Create HTTP header based on a combination of seed header, fields
to delete, and fields to append.
The Build() function is used to manage the headers portion of an
HTTP message by providing the ability to add, remove, or replace
HTTP headers.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] SeedMessageSize Size of the initial HTTP header. This can be zero.
@param[in] SeedMessage Initial HTTP header to be used as a base for
building a new HTTP header. If NULL,
SeedMessageSize is ignored.
@param[in] DeleteCount Number of null-terminated HTTP header field names
in DeleteList.
@param[in] DeleteList List of null-terminated HTTP header field names to
remove from SeedMessage. Only the field names are
in this list because the field values are irrelevant
to this operation.
@param[in] AppendCount Number of header fields in AppendList.
@param[in] AppendList List of HTTP headers to populate NewMessage with.
If SeedMessage is not NULL, AppendList will be
appended to the existing list from SeedMessage in
NewMessage.
@param[out] NewMessageSize Pointer to number of header fields in NewMessage.
@param[out] NewMessage Pointer to a new list of HTTP headers based on.
@retval EFI_SUCCESS Add, remove, and replace operations succeeded.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL.
**/
EFI_STATUS
EFIAPI
HttpUtilitiesBuild (
IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN UINTN SeedMessageSize,
IN VOID *SeedMessage OPTIONAL,
IN UINTN DeleteCount,
IN CHAR8 *DeleteList[] OPTIONAL,
IN UINTN AppendCount,
IN EFI_HTTP_HEADER *AppendList[] OPTIONAL,
OUT UINTN *NewMessageSize,
OUT VOID **NewMessage
);
/**
Parses HTTP header and produces an array of key/value pairs.
The Parse() function is used to transform data stored in HttpHeader
into a list of fields paired with their corresponding values.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] HttpMessage Contains raw unformatted HTTP header string.
@param[in] HttpMessageSize Size of HTTP header.
@param[out] HeaderFields Array of key/value header pairs.
@param[out] FieldCount Number of headers in HeaderFields.
@retval EFI_SUCCESS Allocation succeeded.
@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
initialized.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL.
HttpMessage is NULL.
HeaderFields is NULL.
FieldCount is NULL.
**/
EFI_STATUS
EFIAPI
HttpUtilitiesParse (
IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN CHAR8 *HttpMessage,
IN UINTN HttpMessageSize,
OUT EFI_HTTP_HEADER **HeaderFields,
OUT UINTN *FieldCount
);