TianoCore EDK2 master
|
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
Go to the source code of this file.
Data Structures | |
struct | _INI_SECTION_ITEM |
struct | _INI_COMMENT_LINE |
struct | INI_PARSING_LIB_CONTEXT |
Macros | |
#define | IS_HYPHEN(a) ((a) == '-') |
#define | IS_NULL(a) ((a) == '\0') |
#define | MAX_LINE_LENGTH 512 |
Typedefs | |
typedef struct _INI_SECTION_ITEM | SECTION_ITEM |
typedef struct _INI_COMMENT_LINE | COMMENT_LINE |
Functions | |
BOOLEAN | IsValidDigitalChar (IN CHAR8 DigitalChar, IN BOOLEAN IncludeHex) |
BOOLEAN | IsValidNameChar (IN CHAR8 NameChar) |
BOOLEAN | IsValidDigital (IN CHAR8 *Digital, IN UINTN Length, IN BOOLEAN IncludeHex) |
BOOLEAN | IsValidDecimalString (IN CHAR8 *Decimal, IN UINTN Length) |
BOOLEAN | IsValidHexString (IN CHAR8 *Hex, IN UINTN Length) |
BOOLEAN | IsValidName (IN CHAR8 *Name, IN UINTN Length) |
BOOLEAN | IsValidGuid (IN CHAR8 *Value, IN UINTN Length) |
BOOLEAN | IsValidValue (IN CHAR8 *Value, IN UINTN Length) |
VOID | DumpIniSection (IN VOID *Context) |
EFI_STATUS | ProfileGetLine (IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT UINT8 *LineBuffer, IN OUT UINTN *LineSize) |
VOID | ProfileTrim (IN OUT UINT8 *Buffer, IN OUT UINTN *BufferSize) |
EFI_STATUS | ProfileGetComments (IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT COMMENT_LINE **CommentHead) |
EFI_STATUS | ProfileGetSection (IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT SECTION_ITEM **SectionHead) |
EFI_STATUS | ProfileGetEntry (IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT SECTION_ITEM **SectionHead) |
VOID | FreeAllList (IN SECTION_ITEM *Section, IN COMMENT_LINE *Comment) |
EFI_STATUS | UpdateGetProfileString (IN SECTION_ITEM *Section, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT CHAR8 **EntryValue) |
EFI_STATUS | PreProcessDataFile (IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT SECTION_ITEM **SectionHead, IN OUT COMMENT_LINE **CommentHead) |
VOID *EFIAPI | OpenIniFile (IN UINT8 *DataBuffer, IN UINTN BufferSize) |
EFI_STATUS EFIAPI | GetStringFromDataFile (IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT CHAR8 **EntryValue) |
EFI_STATUS EFIAPI | GetGuidFromDataFile (IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT EFI_GUID *Guid) |
EFI_STATUS EFIAPI | GetDecimalUintnFromDataFile (IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINTN *Data) |
EFI_STATUS EFIAPI | GetHexUintnFromDataFile (IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINTN *Data) |
EFI_STATUS EFIAPI | GetHexUint64FromDataFile (IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINT64 *Data) |
VOID EFIAPI | CloseIniFile (IN VOID *Context) |
This library parses the INI configuration file.
[SectionName]
Where: 1) SectionName is an ASCII string. The valid format is [A-Za-z0-9_]+ 2) EntryName is an ASCII string. The valid format is [A-Za-z0-9_]+ 3) EntryValue can be: 3.1) an ASCII String. The valid format is [A-Za-z0-9_]+ 3.2) a GUID. The valid format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where x is [A-Fa-f0-9] 3.3) a decimal value. The valid format is [0-9]+ 3.4) a hexadecimal value. The valid format is 0x[A-Fa-f0-9]+ 4) '#' or ';' can be used as comment at anywhere. 5) TAB(0x20) or SPACE(0x9) can be used as separator. 6) LF(
, 0xA) or CR(\r, 0xD) can be used as line break.
Caution: This module requires additional review when modified. This driver will have external input - INI data file.
OpenIniFile(), PreProcessDataFile(), ProfileGetSection(), ProfileGetEntry() will receive untrusted input and do basic validation.
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file IniParsingLib.c.
#define IS_HYPHEN | ( | a | ) | ((a) == '-') |
Definition at line 40 of file IniParsingLib.c.
#define IS_NULL | ( | a | ) | ((a) == '\0') |
Definition at line 41 of file IniParsingLib.c.
#define MAX_LINE_LENGTH 512 |
Definition at line 44 of file IniParsingLib.c.
typedef struct _INI_COMMENT_LINE COMMENT_LINE |
Definition at line 55 of file IniParsingLib.c.
typedef struct _INI_SECTION_ITEM SECTION_ITEM |
Definition at line 46 of file IniParsingLib.c.
VOID EFIAPI CloseIniFile | ( | IN VOID * | Context | ) |
Close an INI config file and free the context.
[in] | Context | INI Config file context. |
Definition at line 1326 of file IniParsingLib.c.
VOID DumpIniSection | ( | IN VOID * | Context | ) |
Dump an INI config file context.
[in] | Context | INI Config file context. |
Definition at line 318 of file IniParsingLib.c.
VOID FreeAllList | ( | IN SECTION_ITEM * | Section, |
IN COMMENT_LINE * | Comment | ||
) |
Free all comment entry and section entry.
[in] | Section | Section entry list. |
[in] | Comment | Comment entry list. |
Definition at line 826 of file IniParsingLib.c.
EFI_STATUS EFIAPI GetDecimalUintnFromDataFile | ( | IN VOID * | Context, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT UINTN * | Data | ||
) |
Get section entry decimal UINTN value.
[in] | Context | INI Config file context. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | Data | Point to the got decimal UINTN value. |
EFI_SUCCESS | Section entry decimal UINTN value is got. |
EFI_NOT_FOUND | Section is not found. |
Definition at line 1194 of file IniParsingLib.c.
EFI_STATUS EFIAPI GetGuidFromDataFile | ( | IN VOID * | Context, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT EFI_GUID * | Guid | ||
) |
Get section entry GUID value.
[in] | Context | INI Config file context. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | Guid | Point to the got GUID value. |
EFI_SUCCESS | Section entry GUID value is got. |
EFI_NOT_FOUND | Section is not found. |
Definition at line 1147 of file IniParsingLib.c.
EFI_STATUS EFIAPI GetHexUint64FromDataFile | ( | IN VOID * | Context, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT UINT64 * | Data | ||
) |
Get section entry hexadecimal UINT64 value.
[in] | Context | INI Config file context. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | Data | Point to the got hexadecimal UINT64 value. |
EFI_SUCCESS | Section entry hexadecimal UINT64 value is got. |
EFI_NOT_FOUND | Section is not found. |
Definition at line 1286 of file IniParsingLib.c.
EFI_STATUS EFIAPI GetHexUintnFromDataFile | ( | IN VOID * | Context, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT UINTN * | Data | ||
) |
Get section entry hexadecimal UINTN value.
[in] | Context | INI Config file context. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | Data | Point to the got hexadecimal UINTN value. |
EFI_SUCCESS | Section entry hexadecimal UINTN value is got. |
EFI_NOT_FOUND | Section is not found. |
Definition at line 1240 of file IniParsingLib.c.
EFI_STATUS EFIAPI GetStringFromDataFile | ( | IN VOID * | Context, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT CHAR8 ** | EntryValue | ||
) |
Get section entry string value.
[in] | Context | INI Config file context. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | EntryValue | Point to the got entry string value. |
EFI_SUCCESS | Section entry string value is got. |
EFI_NOT_FOUND | Section is not found. |
Definition at line 1108 of file IniParsingLib.c.
Return if the decimal string is valid.
[in] | Decimal | The decimal string to be checked. |
[in] | Length | The length of decimal string in bytes. |
TRUE | The decimal string is valid. |
FALSE | The decimal string is invalid. |
Definition at line 168 of file IniParsingLib.c.
Return if the digital string is valid.
[in] | Digital | The digital to be checked. |
[in] | Length | The length of digital string in bytes. |
[in] | IncludeHex | If it include HEX char. |
TRUE | The digital string is valid. |
FALSE | The digital string is invalid. |
Definition at line 141 of file IniParsingLib.c.
Return if the digital char is valid.
[in] | DigitalChar | The digital char to be checked. |
[in] | IncludeHex | If it include HEX char. |
TRUE | The digital char is valid. |
FALSE | The digital char is invalid. |
Definition at line 76 of file IniParsingLib.c.
Return if the value string is valid GUID.
[in] | Value | The value to be checked. |
[in] | Length | The length of value string in bytes. |
Definition at line 242 of file IniParsingLib.c.
Return if the hexadecimal string is valid.
[in] | Hex | The hexadecimal string to be checked. |
[in] | Length | The length of hexadecimal string in bytes. |
TRUE | The hexadecimal string is valid. |
FALSE | The hexadecimal string is invalid. |
Definition at line 186 of file IniParsingLib.c.
Return if the name string is valid.
[in] | Name | The name to be checked. |
[in] | Length | The length of name string in bytes. |
TRUE | The name string is valid. |
FALSE | The name string is invalid. |
Definition at line 216 of file IniParsingLib.c.
BOOLEAN IsValidNameChar | ( | IN CHAR8 | NameChar | ) |
Return if the name char is valid.
[in] | NameChar | The name char to be checked. |
TRUE | The name char is valid. |
FALSE | The name char is invalid. |
Definition at line 107 of file IniParsingLib.c.
Return if the value string is valid.
[in] | Value | The value to be checked. |
[in] | Length | The length of value string in bytes. |
TRUE | The name string is valid. |
FALSE | The name string is invalid. |
Definition at line 300 of file IniParsingLib.c.
Open an INI config file and return a context.
[in] | DataBuffer | Config raw file buffer. |
[in] | BufferSize | Size of raw buffer. |
NULL | No enough memory is allocated. |
NULL | Config data buffer is invalid. |
Definition at line 1058 of file IniParsingLib.c.
EFI_STATUS PreProcessDataFile | ( | IN UINT8 * | DataBuffer, |
IN UINTN | BufferSize, | ||
IN OUT SECTION_ITEM ** | SectionHead, | ||
IN OUT COMMENT_LINE ** | CommentHead | ||
) |
Pre process config data buffer into Section entry list and Comment entry list.
[in] | DataBuffer | Config raw file buffer. |
[in] | BufferSize | Size of raw buffer. |
[in,out] | SectionHead | Pointer to the section entry list. |
[in,out] | CommentHead | Pointer to the comment entry list. |
EFI_OUT_OF_RESOURCES | No enough memory is allocated. |
EFI_SUCCESS | Config data buffer is preprocessed. |
EFI_NOT_FOUND | Config data buffer is invalid, because Section or Entry is not found. |
EFI_INVALID_PARAMETER | Config data buffer is invalid, because Section or Entry is invalid. |
Definition at line 923 of file IniParsingLib.c.
EFI_STATUS ProfileGetComments | ( | IN UINT8 * | Buffer, |
IN UINTN | BufferSize, | ||
IN OUT COMMENT_LINE ** | CommentHead | ||
) |
Insert new comment item into comment head.
[in] | Buffer | Comment buffer to be added. |
[in] | BufferSize | Size of comment buffer. |
[in,out] | CommentHead | Comment Item head entry. |
EFI_OUT_OF_RESOURCES | No enough memory is allocated. |
EFI_SUCCESS | New comment item is inserted. |
Definition at line 514 of file IniParsingLib.c.
EFI_STATUS ProfileGetEntry | ( | IN UINT8 * | Buffer, |
IN UINTN | BufferSize, | ||
IN OUT SECTION_ITEM ** | SectionHead | ||
) |
Add new section entry and entry value into Section head.
[in] | Buffer | Section entry data buffer. |
[in] | BufferSize | Size of section entry. |
[in,out] | SectionHead | Section item head entry. |
EFI_OUT_OF_RESOURCES | No enough memory is allocated. |
EFI_SUCCESS | Section entry is added. |
EFI_NOT_FOUND | Section entry is not found. |
EFI_INVALID_PARAMETER | Section entry is invalid. |
Definition at line 658 of file IniParsingLib.c.
EFI_STATUS ProfileGetLine | ( | IN UINT8 * | Buffer, |
IN UINTN | BufferSize, | ||
IN OUT UINT8 * | LineBuffer, | ||
IN OUT UINTN * | LineSize | ||
) |
Copy one line data from buffer data to the line buffer.
[in] | Buffer | Buffer data. |
[in] | BufferSize | Buffer Size. |
[in,out] | LineBuffer | Line buffer to store the found line data. |
[in,out] | LineSize | On input, size of the input line buffer. On output, size of the actual line buffer. |
EFI_BUFFER_TOO_SMALL | The size of input line buffer is not enough. |
EFI_SUCCESS | Copy line data into the line buffer. |
Definition at line 364 of file IniParsingLib.c.
EFI_STATUS ProfileGetSection | ( | IN UINT8 * | Buffer, |
IN UINTN | BufferSize, | ||
IN OUT SECTION_ITEM ** | SectionHead | ||
) |
Add new section item into Section head.
[in] | Buffer | Section item data buffer. |
[in] | BufferSize | Size of section item. |
[in,out] | SectionHead | Section item head entry. |
EFI_OUT_OF_RESOURCES | No enough memory is allocated. |
EFI_SUCCESS | Section item is NULL or Section item is added. |
Definition at line 558 of file IniParsingLib.c.
Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.
[in,out] | Buffer | On input, buffer data to be trimmed. On output, the trimmed buffer. |
[in,out] | BufferSize | On input, size of original buffer data. On output, size of the trimmed buffer. |
Definition at line 426 of file IniParsingLib.c.
EFI_STATUS UpdateGetProfileString | ( | IN SECTION_ITEM * | Section, |
IN CHAR8 * | SectionName, | ||
IN CHAR8 * | EntryName, | ||
OUT CHAR8 ** | EntryValue | ||
) |
Get section entry value.
[in] | Section | Section entry list. |
[in] | SectionName | Section name. |
[in] | EntryName | Section entry name. |
[out] | EntryValue | Point to the got entry value. |
EFI_NOT_FOUND | Section is not found. |
EFI_SUCCESS | Section entry value is got. |
Definition at line 878 of file IniParsingLib.c.