TianoCore EDK2 master
Loading...
Searching...
No Matches
IniParsingLib.c File Reference

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)
 

Detailed Description

This library parses the INI configuration file.

The INI file format is:

[SectionName]

EntryName=EntryValue

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.

Macro Definition Documentation

◆ IS_HYPHEN

#define IS_HYPHEN (   a)    ((a) == '-')

Definition at line 40 of file IniParsingLib.c.

◆ IS_NULL

#define IS_NULL (   a)    ((a) == '\0')

Definition at line 41 of file IniParsingLib.c.

◆ MAX_LINE_LENGTH

#define MAX_LINE_LENGTH   512

Definition at line 44 of file IniParsingLib.c.

Typedef Documentation

◆ COMMENT_LINE

Definition at line 55 of file IniParsingLib.c.

◆ SECTION_ITEM

Definition at line 46 of file IniParsingLib.c.

Function Documentation

◆ CloseIniFile()

VOID EFIAPI CloseIniFile ( IN VOID *  Context)

Close an INI config file and free the context.

Parameters
[in]ContextINI Config file context.

Definition at line 1326 of file IniParsingLib.c.

◆ DumpIniSection()

VOID DumpIniSection ( IN VOID *  Context)

Dump an INI config file context.

Parameters
[in]ContextINI Config file context.

Definition at line 318 of file IniParsingLib.c.

◆ FreeAllList()

VOID FreeAllList ( IN SECTION_ITEM Section,
IN COMMENT_LINE Comment 
)

Free all comment entry and section entry.

Parameters
[in]SectionSection entry list.
[in]CommentComment entry list.

Definition at line 826 of file IniParsingLib.c.

◆ GetDecimalUintnFromDataFile()

EFI_STATUS EFIAPI GetDecimalUintnFromDataFile ( IN VOID *  Context,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT UINTN Data 
)

Get section entry decimal UINTN value.

Parameters
[in]ContextINI Config file context.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]DataPoint to the got decimal UINTN value.
Return values
EFI_SUCCESSSection entry decimal UINTN value is got.
EFI_NOT_FOUNDSection is not found.

Definition at line 1194 of file IniParsingLib.c.

◆ GetGuidFromDataFile()

EFI_STATUS EFIAPI GetGuidFromDataFile ( IN VOID *  Context,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT EFI_GUID Guid 
)

Get section entry GUID value.

Parameters
[in]ContextINI Config file context.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]GuidPoint to the got GUID value.
Return values
EFI_SUCCESSSection entry GUID value is got.
EFI_NOT_FOUNDSection is not found.

Definition at line 1147 of file IniParsingLib.c.

◆ GetHexUint64FromDataFile()

EFI_STATUS EFIAPI GetHexUint64FromDataFile ( IN VOID *  Context,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT UINT64 *  Data 
)

Get section entry hexadecimal UINT64 value.

Parameters
[in]ContextINI Config file context.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]DataPoint to the got hexadecimal UINT64 value.
Return values
EFI_SUCCESSSection entry hexadecimal UINT64 value is got.
EFI_NOT_FOUNDSection is not found.

Definition at line 1286 of file IniParsingLib.c.

◆ GetHexUintnFromDataFile()

EFI_STATUS EFIAPI GetHexUintnFromDataFile ( IN VOID *  Context,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT UINTN Data 
)

Get section entry hexadecimal UINTN value.

Parameters
[in]ContextINI Config file context.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]DataPoint to the got hexadecimal UINTN value.
Return values
EFI_SUCCESSSection entry hexadecimal UINTN value is got.
EFI_NOT_FOUNDSection is not found.

Definition at line 1240 of file IniParsingLib.c.

◆ GetStringFromDataFile()

EFI_STATUS EFIAPI GetStringFromDataFile ( IN VOID *  Context,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT CHAR8 **  EntryValue 
)

Get section entry string value.

Parameters
[in]ContextINI Config file context.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]EntryValuePoint to the got entry string value.
Return values
EFI_SUCCESSSection entry string value is got.
EFI_NOT_FOUNDSection is not found.

Definition at line 1108 of file IniParsingLib.c.

◆ IsValidDecimalString()

BOOLEAN IsValidDecimalString ( IN CHAR8 *  Decimal,
IN UINTN  Length 
)

Return if the decimal string is valid.

Parameters
[in]DecimalThe decimal string to be checked.
[in]LengthThe length of decimal string in bytes.
Return values
TRUEThe decimal string is valid.
FALSEThe decimal string is invalid.

Definition at line 168 of file IniParsingLib.c.

◆ IsValidDigital()

BOOLEAN IsValidDigital ( IN CHAR8 *  Digital,
IN UINTN  Length,
IN BOOLEAN  IncludeHex 
)

Return if the digital string is valid.

Parameters
[in]DigitalThe digital to be checked.
[in]LengthThe length of digital string in bytes.
[in]IncludeHexIf it include HEX char.
Return values
TRUEThe digital string is valid.
FALSEThe digital string is invalid.

Definition at line 141 of file IniParsingLib.c.

◆ IsValidDigitalChar()

BOOLEAN IsValidDigitalChar ( IN CHAR8  DigitalChar,
IN BOOLEAN  IncludeHex 
)

Return if the digital char is valid.

Parameters
[in]DigitalCharThe digital char to be checked.
[in]IncludeHexIf it include HEX char.
Return values
TRUEThe digital char is valid.
FALSEThe digital char is invalid.

Definition at line 76 of file IniParsingLib.c.

◆ IsValidGuid()

BOOLEAN IsValidGuid ( IN CHAR8 *  Value,
IN UINTN  Length 
)

Return if the value string is valid GUID.

Parameters
[in]ValueThe value to be checked.
[in]LengthThe length of value string in bytes.
Return values
TRUEThe value string is valid GUID.
FALSEThe value string is invalid GUID.

Definition at line 242 of file IniParsingLib.c.

◆ IsValidHexString()

BOOLEAN IsValidHexString ( IN CHAR8 *  Hex,
IN UINTN  Length 
)

Return if the hexadecimal string is valid.

Parameters
[in]HexThe hexadecimal string to be checked.
[in]LengthThe length of hexadecimal string in bytes.
Return values
TRUEThe hexadecimal string is valid.
FALSEThe hexadecimal string is invalid.

Definition at line 186 of file IniParsingLib.c.

◆ IsValidName()

BOOLEAN IsValidName ( IN CHAR8 *  Name,
IN UINTN  Length 
)

Return if the name string is valid.

Parameters
[in]NameThe name to be checked.
[in]LengthThe length of name string in bytes.
Return values
TRUEThe name string is valid.
FALSEThe name string is invalid.

Definition at line 216 of file IniParsingLib.c.

◆ IsValidNameChar()

BOOLEAN IsValidNameChar ( IN CHAR8  NameChar)

Return if the name char is valid.

Parameters
[in]NameCharThe name char to be checked.
Return values
TRUEThe name char is valid.
FALSEThe name char is invalid.

Definition at line 107 of file IniParsingLib.c.

◆ IsValidValue()

BOOLEAN IsValidValue ( IN CHAR8 *  Value,
IN UINTN  Length 
)

Return if the value string is valid.

Parameters
[in]ValueThe value to be checked.
[in]LengthThe length of value string in bytes.
Return values
TRUEThe name string is valid.
FALSEThe name string is invalid.

Definition at line 300 of file IniParsingLib.c.

◆ OpenIniFile()

VOID *EFIAPI OpenIniFile ( IN UINT8 *  DataBuffer,
IN UINTN  BufferSize 
)

Open an INI config file and return a context.

Parameters
[in]DataBufferConfig raw file buffer.
[in]BufferSizeSize of raw buffer.
Returns
Config data buffer is opened and context is returned.
Return values
NULLNo enough memory is allocated.
NULLConfig data buffer is invalid.

Definition at line 1058 of file IniParsingLib.c.

◆ PreProcessDataFile()

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.

Parameters
[in]DataBufferConfig raw file buffer.
[in]BufferSizeSize of raw buffer.
[in,out]SectionHeadPointer to the section entry list.
[in,out]CommentHeadPointer to the comment entry list.
Return values
EFI_OUT_OF_RESOURCESNo enough memory is allocated.
EFI_SUCCESSConfig data buffer is preprocessed.
EFI_NOT_FOUNDConfig data buffer is invalid, because Section or Entry is not found.
EFI_INVALID_PARAMETERConfig data buffer is invalid, because Section or Entry is invalid.

Definition at line 923 of file IniParsingLib.c.

◆ ProfileGetComments()

EFI_STATUS ProfileGetComments ( IN UINT8 *  Buffer,
IN UINTN  BufferSize,
IN OUT COMMENT_LINE **  CommentHead 
)

Insert new comment item into comment head.

Parameters
[in]BufferComment buffer to be added.
[in]BufferSizeSize of comment buffer.
[in,out]CommentHeadComment Item head entry.
Return values
EFI_OUT_OF_RESOURCESNo enough memory is allocated.
EFI_SUCCESSNew comment item is inserted.

Definition at line 514 of file IniParsingLib.c.

◆ ProfileGetEntry()

EFI_STATUS ProfileGetEntry ( IN UINT8 *  Buffer,
IN UINTN  BufferSize,
IN OUT SECTION_ITEM **  SectionHead 
)

Add new section entry and entry value into Section head.

Parameters
[in]BufferSection entry data buffer.
[in]BufferSizeSize of section entry.
[in,out]SectionHeadSection item head entry.
Return values
EFI_OUT_OF_RESOURCESNo enough memory is allocated.
EFI_SUCCESSSection entry is added.
EFI_NOT_FOUNDSection entry is not found.
EFI_INVALID_PARAMETERSection entry is invalid.

Definition at line 658 of file IniParsingLib.c.

◆ ProfileGetLine()

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.

Parameters
[in]BufferBuffer data.
[in]BufferSizeBuffer Size.
[in,out]LineBufferLine buffer to store the found line data.
[in,out]LineSizeOn input, size of the input line buffer. On output, size of the actual line buffer.
Return values
EFI_BUFFER_TOO_SMALLThe size of input line buffer is not enough.
EFI_SUCCESSCopy line data into the line buffer.

Definition at line 364 of file IniParsingLib.c.

◆ ProfileGetSection()

EFI_STATUS ProfileGetSection ( IN UINT8 *  Buffer,
IN UINTN  BufferSize,
IN OUT SECTION_ITEM **  SectionHead 
)

Add new section item into Section head.

Parameters
[in]BufferSection item data buffer.
[in]BufferSizeSize of section item.
[in,out]SectionHeadSection item head entry.
Return values
EFI_OUT_OF_RESOURCESNo enough memory is allocated.
EFI_SUCCESSSection item is NULL or Section item is added.

Definition at line 558 of file IniParsingLib.c.

◆ ProfileTrim()

VOID ProfileTrim ( IN OUT UINT8 *  Buffer,
IN OUT UINTN BufferSize 
)

Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.

Parameters
[in,out]BufferOn input, buffer data to be trimmed. On output, the trimmed buffer.
[in,out]BufferSizeOn input, size of original buffer data. On output, size of the trimmed buffer.

Definition at line 426 of file IniParsingLib.c.

◆ UpdateGetProfileString()

EFI_STATUS UpdateGetProfileString ( IN SECTION_ITEM Section,
IN CHAR8 *  SectionName,
IN CHAR8 *  EntryName,
OUT CHAR8 **  EntryValue 
)

Get section entry value.

Parameters
[in]SectionSection entry list.
[in]SectionNameSection name.
[in]EntryNameSection entry name.
[out]EntryValuePoint to the got entry value.
Return values
EFI_NOT_FOUNDSection is not found.
EFI_SUCCESSSection entry value is got.

Definition at line 878 of file IniParsingLib.c.