2 This library parses the INI configuration file.
4 The INI file format is:
11 1) SectionName is an ASCII string. The valid format is [A-Za-z0-9_]+
12 2) EntryName is an ASCII string. The valid format is [A-Za-z0-9_]+
14 3.1) an ASCII String. The valid format is [A-Za-z0-9_]+
15 3.2) a GUID. The valid format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where x is [A-Fa-f0-9]
16 3.3) a decimal value. The valid format is [0-9]+
17 3.4) a heximal value. The valid format is 0x[A-Fa-f0-9]+
18 4) '#' or ';' can be used as comment at anywhere.
19 5) TAB(0x20) or SPACE(0x9) can be used as separator.
20 6) LF(\n, 0xA) or CR(\r, 0xD) can be used as line break.
22 Caution: This module requires additional review when modified.
23 This driver will have external input - INI data file.
25 OpenIniFile(), PreProcessDataFile(), ProfileGetSection(), ProfileGetEntry()
26 will receive untrusted input and do basic validation.
28 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
30 SPDX-License-Identifier: BSD-2-Clause-Patent
35 #include <Library/BaseLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/DebugLib.h>
38 #include <Library/MemoryAllocationLib.h>
40 #define IS_HYPHEN(a) ((a) == '-')
41 #define IS_NULL(a) ((a) == '\0')
43 // This is default allocation. Reallocation will happen if it is not enough.
44 #define MAX_LINE_LENGTH 512
46 typedef struct _INI_SECTION_ITEM SECTION_ITEM
;
47 struct _INI_SECTION_ITEM
{
52 SECTION_ITEM
*PtrNext
;
55 typedef struct _INI_COMMENT_LINE COMMENT_LINE
;
56 struct _INI_COMMENT_LINE
{
58 COMMENT_LINE
*PtrNext
;
62 SECTION_ITEM
*SectionHead
;
63 COMMENT_LINE
*CommentHead
;
64 } INI_PARSING_LIB_CONTEXT
;
67 Return if the digital char is valid.
69 @param[in] DigitalChar The digital char to be checked.
70 @param[in] IncludeHex If it include HEX char.
72 @retval TRUE The digital char is valid.
73 @retval FALSE The digital char is invalid.
81 if (DigitalChar
>= '0' && DigitalChar
<= '9') {
85 if (DigitalChar
>= 'a' && DigitalChar
<= 'f') {
88 if (DigitalChar
>= 'A' && DigitalChar
<= 'F') {
96 Return if the name char is valid.
98 @param[in] NameChar The name char to be checked.
100 @retval TRUE The name char is valid.
101 @retval FALSE The name char is invalid.
108 if (NameChar
>= 'a' && NameChar
<= 'z') {
111 if (NameChar
>= 'A' && NameChar
<= 'Z') {
114 if (NameChar
>= '0' && NameChar
<= '9') {
117 if (NameChar
== '_') {
124 Return if the digital string is valid.
126 @param[in] Digital The digital to be checked.
127 @param[in] Length The length of digital string in bytes.
128 @param[in] IncludeHex If it include HEX char.
130 @retval TRUE The digital string is valid.
131 @retval FALSE The digital string is invalid.
137 IN BOOLEAN IncludeHex
141 for (Index
= 0; Index
< Length
; Index
++) {
142 if (!IsValidDigitalChar(Digital
[Index
], IncludeHex
)) {
150 Return if the decimal string is valid.
152 @param[in] Decimal The decimal string to be checked.
153 @param[in] Length The length of decimal string in bytes.
155 @retval TRUE The decimal string is valid.
156 @retval FALSE The decimal string is invalid.
159 IsValidDecimalString (
164 return IsValidDigital(Decimal
, Length
, FALSE
);
168 Return if the heximal string is valid.
170 @param[in] Hex The heximal string to be checked.
171 @param[in] Length The length of heximal string in bytes.
173 @retval TRUE The heximal string is valid.
174 @retval FALSE The heximal string is invalid.
188 if (Hex
[1] != 'x' && Hex
[1] != 'X') {
191 return IsValidDigital(&Hex
[2], Length
- 2, TRUE
);
195 Return if the name string is valid.
197 @param[in] Name The name to be checked.
198 @param[in] Length The length of name string in bytes.
200 @retval TRUE The name string is valid.
201 @retval FALSE The name string is invalid.
210 for (Index
= 0; Index
< Length
; Index
++) {
211 if (!IsValidNameChar(Name
[Index
])) {
219 Return if the value string is valid GUID.
221 @param[in] Value The value to be checked.
222 @param[in] Length The length of value string in bytes.
224 @retval TRUE The value string is valid GUID.
225 @retval FALSE The value string is invalid GUID.
233 if (Length
!= sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") - 1) {
236 if (!IS_HYPHEN(Value
[8])) {
239 if (!IS_HYPHEN(Value
[13])) {
242 if (!IS_HYPHEN(Value
[18])) {
245 if (!IS_HYPHEN(Value
[23])) {
248 if (!IsValidDigital(&Value
[0], 8, TRUE
)) {
251 if (!IsValidDigital(&Value
[9], 4, TRUE
)) {
254 if (!IsValidDigital(&Value
[14], 4, TRUE
)) {
257 if (!IsValidDigital(&Value
[19], 4, TRUE
)) {
260 if (!IsValidDigital(&Value
[24], 12, TRUE
)) {
267 Return if the value string is valid.
269 @param[in] Value The value to be checked.
270 @param[in] Length The length of value string in bytes.
272 @retval TRUE The name string is valid.
273 @retval FALSE The name string is invalid.
281 if (IsValidName(Value
, Length
) || IsValidGuid(Value
, Length
)) {
288 Dump an INI config file context.
290 @param[in] Context INI Config file context.
297 INI_PARSING_LIB_CONTEXT
*IniContext
;
298 SECTION_ITEM
*PtrSection
;
299 SECTION_ITEM
*Section
;
301 if (Context
== NULL
) {
305 IniContext
= Context
;
306 Section
= IniContext
->SectionHead
;
308 while (Section
!= NULL
) {
309 PtrSection
= Section
;
310 Section
= Section
->PtrNext
;
311 if (PtrSection
->PtrSection
!= NULL
) {
312 DEBUG((DEBUG_VERBOSE
, "Section - %a\n", PtrSection
->PtrSection
));
314 if (PtrSection
->PtrEntry
!= NULL
) {
315 DEBUG ((DEBUG_VERBOSE
, " Entry - %a\n", PtrSection
->PtrEntry
));
317 if (PtrSection
->PtrValue
!= NULL
) {
318 DEBUG((DEBUG_VERBOSE
, " Value - %a\n", PtrSection
->PtrValue
));
324 Copy one line data from buffer data to the line buffer.
326 @param[in] Buffer Buffer data.
327 @param[in] BufferSize Buffer Size.
328 @param[in, out] LineBuffer Line buffer to store the found line data.
329 @param[in, out] LineSize On input, size of the input line buffer.
330 On output, size of the actual line buffer.
332 @retval EFI_BUFFER_TOO_SMALL The size of input line buffer is not enough.
333 @retval EFI_SUCCESS Copy line data into the line buffer.
340 IN OUT UINT8
*LineBuffer
,
341 IN OUT UINTN
*LineSize
349 PtrEnd
= (UINTN
)Buffer
+ BufferSize
;
352 // 0x0D indicates a line break. Otherwise there is no line break
354 while ((UINTN
)PtrBuf
< PtrEnd
) {
355 if (*PtrBuf
== 0x0D || *PtrBuf
== 0x0A) {
361 if ((UINTN
)PtrBuf
>= (PtrEnd
- 1)) {
363 // The buffer ends without any line break
364 // or it is the last character of the buffer
367 } else if (*(PtrBuf
+ 1) == 0x0A) {
369 // Further check if a 0x0A follows. If yes, count 0xA
371 Length
= (UINTN
) PtrBuf
- (UINTN
) Buffer
+ 2;
373 Length
= (UINTN
) PtrBuf
- (UINTN
) Buffer
+ 1;
376 if (Length
> (*LineSize
)) {
378 return EFI_BUFFER_TOO_SMALL
;
381 SetMem (LineBuffer
, *LineSize
, 0x0);
383 CopyMem (LineBuffer
, Buffer
, Length
);
389 Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.
391 @param[in, out] Buffer On input, buffer data to be trimed.
392 On output, the trimmed buffer.
393 @param[in, out] BufferSize On input, size of original buffer data.
394 On output, size of the trimmed buffer.
399 IN OUT UINT8
*Buffer
,
400 IN OUT UINTN
*BufferSize
407 if (*BufferSize
== 0) {
412 // Trim the tail first, include CR, LF, TAB, and SPACE.
414 Length
= *BufferSize
;
415 PtrBuf
= (UINT8
*) ((UINTN
) Buffer
+ Length
- 1);
416 while (PtrBuf
>= Buffer
) {
417 if ((*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A )
418 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09)) {
425 // all spaces, a blank line, return directly;
427 if (PtrBuf
< Buffer
) {
432 Length
= (UINTN
)PtrBuf
- (UINTN
)Buffer
+ 1;
437 // Now skip the heading CR, LF, TAB and SPACE
439 while (PtrBuf
<= PtrEnd
) {
440 if ((*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A )
441 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09)) {
448 // If no heading CR, LF, TAB or SPACE, directly return
450 if (PtrBuf
== Buffer
) {
451 *BufferSize
= Length
;
455 *BufferSize
= (UINTN
)PtrEnd
- (UINTN
)PtrBuf
+ 1;
458 // The first Buffer..PtrBuf characters are CR, LF, TAB or SPACE.
459 // Now move out all these characters.
461 while (PtrBuf
<= PtrEnd
) {
471 Insert new comment item into comment head.
473 @param[in] Buffer Comment buffer to be added.
474 @param[in] BufferSize Size of comment buffer.
475 @param[in, out] CommentHead Comment Item head entry.
477 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
478 @retval EFI_SUCCESS New comment item is inserted.
485 IN OUT COMMENT_LINE
**CommentHead
488 COMMENT_LINE
*CommentItem
;
491 CommentItem
= AllocatePool (sizeof (COMMENT_LINE
));
492 if (CommentItem
== NULL
) {
493 return EFI_OUT_OF_RESOURCES
;
496 CommentItem
->PtrNext
= *CommentHead
;
497 *CommentHead
= CommentItem
;
500 // Add a trailing '\0'
502 CommentItem
->PtrComment
= AllocatePool (BufferSize
+ 1);
503 if (CommentItem
->PtrComment
== NULL
) {
504 FreePool (CommentItem
);
505 return EFI_OUT_OF_RESOURCES
;
507 CopyMem (CommentItem
->PtrComment
, Buffer
, BufferSize
);
508 *(CommentItem
->PtrComment
+ BufferSize
) = '\0';
514 Add new section item into Section head.
516 @param[in] Buffer Section item data buffer.
517 @param[in] BufferSize Size of section item.
518 @param[in, out] SectionHead Section item head entry.
520 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
521 @retval EFI_SUCCESS Section item is NULL or Section item is added.
528 IN OUT SECTION_ITEM
**SectionHead
531 SECTION_ITEM
*SectionItem
;
536 ASSERT(BufferSize
>= 1);
538 // The first character of Buffer is '[', now we want for ']'
540 PtrEnd
= (UINT8
*)((UINTN
)Buffer
+ BufferSize
- 1);
541 PtrBuf
= (UINT8
*)((UINTN
)Buffer
+ 1);
542 while (PtrBuf
<= PtrEnd
) {
543 if (*PtrBuf
== ']') {
548 if (PtrBuf
> PtrEnd
) {
550 // Not found. Invalid line
552 return EFI_NOT_FOUND
;
554 if (PtrBuf
<= Buffer
+ 1) {
556 return EFI_NOT_FOUND
;
560 // excluding the heading '[' and tailing ']'
562 Length
= PtrBuf
- Buffer
- 1;
569 // Invalid line if the section name is null
572 return EFI_NOT_FOUND
;
575 if (!IsValidName((CHAR8
*)Buffer
+ 1, Length
)) {
576 return EFI_INVALID_PARAMETER
;
579 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
580 if (SectionItem
== NULL
) {
581 return EFI_OUT_OF_RESOURCES
;
584 SectionItem
->PtrSection
= NULL
;
585 SectionItem
->SecNameLen
= Length
;
586 SectionItem
->PtrEntry
= NULL
;
587 SectionItem
->PtrValue
= NULL
;
588 SectionItem
->PtrNext
= *SectionHead
;
589 *SectionHead
= SectionItem
;
592 // Add a trailing '\0'
594 SectionItem
->PtrSection
= AllocatePool (Length
+ 1);
595 if (SectionItem
->PtrSection
== NULL
) {
596 return EFI_OUT_OF_RESOURCES
;
600 // excluding the heading '['
602 CopyMem (SectionItem
->PtrSection
, Buffer
+ 1, Length
);
603 *(SectionItem
->PtrSection
+ Length
) = '\0';
609 Add new section entry and entry value into Section head.
611 @param[in] Buffer Section entry data buffer.
612 @param[in] BufferSize Size of section entry.
613 @param[in, out] SectionHead Section item head entry.
615 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
616 @retval EFI_SUCCESS Section entry is added.
617 @retval EFI_NOT_FOUND Section entry is not found.
618 @retval EFI_INVALID_PARAMETER Section entry is invalid.
625 IN OUT SECTION_ITEM
**SectionHead
629 SECTION_ITEM
*SectionItem
;
630 SECTION_ITEM
*PtrSection
;
635 Status
= EFI_SUCCESS
;
637 PtrEnd
= (UINT8
*) ((UINTN
)Buffer
+ BufferSize
- 1);
640 // First search for '='
642 while (PtrBuf
<= PtrEnd
) {
643 if (*PtrBuf
== '=') {
648 if (PtrBuf
> PtrEnd
) {
650 // Not found. Invalid line
652 return EFI_NOT_FOUND
;
654 if (PtrBuf
<= Buffer
) {
656 return EFI_NOT_FOUND
;
660 // excluding the tailing '='
662 Length
= PtrBuf
- Buffer
;
669 // Invalid line if the entry name is null
672 return EFI_NOT_FOUND
;
675 if (!IsValidName((CHAR8
*)Buffer
, Length
)) {
676 return EFI_INVALID_PARAMETER
;
680 // Omit this line if no section header has been found before
682 if (*SectionHead
== NULL
) {
685 PtrSection
= *SectionHead
;
687 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
688 if (SectionItem
== NULL
) {
689 return EFI_OUT_OF_RESOURCES
;
692 SectionItem
->PtrSection
= NULL
;
693 SectionItem
->PtrEntry
= NULL
;
694 SectionItem
->PtrValue
= NULL
;
695 SectionItem
->SecNameLen
= PtrSection
->SecNameLen
;
696 SectionItem
->PtrNext
= *SectionHead
;
697 *SectionHead
= SectionItem
;
700 // SectionName, add a trailing '\0'
702 SectionItem
->PtrSection
= AllocatePool (PtrSection
->SecNameLen
+ 1);
703 if (SectionItem
->PtrSection
== NULL
) {
704 return EFI_OUT_OF_RESOURCES
;
706 CopyMem (SectionItem
->PtrSection
, PtrSection
->PtrSection
, PtrSection
->SecNameLen
+ 1);
709 // EntryName, add a trailing '\0'
711 SectionItem
->PtrEntry
= AllocatePool (Length
+ 1);
712 if (SectionItem
->PtrEntry
== NULL
) {
713 FreePool(SectionItem
->PtrSection
);
714 return EFI_OUT_OF_RESOURCES
;
716 CopyMem (SectionItem
->PtrEntry
, Buffer
, Length
);
717 *(SectionItem
->PtrEntry
+ Length
) = '\0';
720 // Next search for '#' or ';'
724 while (PtrBuf
<= PtrEnd
) {
725 if (*PtrBuf
== '#' || *PtrBuf
== ';') {
730 if (PtrBuf
<= Buffer
) {
732 FreePool(SectionItem
->PtrEntry
);
733 FreePool(SectionItem
->PtrSection
);
734 return EFI_NOT_FOUND
;
736 Length
= PtrBuf
- Buffer
;
743 // Invalid line if the entry value is null
746 FreePool(SectionItem
->PtrEntry
);
747 FreePool(SectionItem
->PtrSection
);
748 return EFI_NOT_FOUND
;
751 if (!IsValidValue((CHAR8
*)Buffer
, Length
)) {
752 FreePool(SectionItem
->PtrEntry
);
753 FreePool(SectionItem
->PtrSection
);
754 return EFI_INVALID_PARAMETER
;
758 // EntryValue, add a trailing '\0'
760 SectionItem
->PtrValue
= AllocatePool (Length
+ 1);
761 if (SectionItem
->PtrValue
== NULL
) {
762 FreePool(SectionItem
->PtrEntry
);
763 FreePool(SectionItem
->PtrSection
);
764 return EFI_OUT_OF_RESOURCES
;
766 CopyMem (SectionItem
->PtrValue
, Buffer
, Length
);
767 *(SectionItem
->PtrValue
+ Length
) = '\0';
773 Free all comment entry and section entry.
775 @param[in] Section Section entry list.
776 @param[in] Comment Comment entry list.
781 IN SECTION_ITEM
*Section
,
782 IN COMMENT_LINE
*Comment
785 SECTION_ITEM
*PtrSection
;
786 COMMENT_LINE
*PtrComment
;
788 while (Section
!= NULL
) {
789 PtrSection
= Section
;
790 Section
= Section
->PtrNext
;
791 if (PtrSection
->PtrEntry
!= NULL
) {
792 FreePool (PtrSection
->PtrEntry
);
794 if (PtrSection
->PtrSection
!= NULL
) {
795 FreePool (PtrSection
->PtrSection
);
797 if (PtrSection
->PtrValue
!= NULL
) {
798 FreePool (PtrSection
->PtrValue
);
800 FreePool (PtrSection
);
803 while (Comment
!= NULL
) {
804 PtrComment
= Comment
;
805 Comment
= Comment
->PtrNext
;
806 if (PtrComment
->PtrComment
!= NULL
) {
807 FreePool (PtrComment
->PtrComment
);
809 FreePool (PtrComment
);
816 Get section entry value.
818 @param[in] Section Section entry list.
819 @param[in] SectionName Section name.
820 @param[in] EntryName Section entry name.
821 @param[out] EntryValue Point to the got entry value.
823 @retval EFI_NOT_FOUND Section is not found.
824 @retval EFI_SUCCESS Section entry value is got.
828 UpdateGetProfileString (
829 IN SECTION_ITEM
*Section
,
830 IN CHAR8
*SectionName
,
832 OUT CHAR8
**EntryValue
837 while (Section
!= NULL
) {
838 if (AsciiStrCmp ((CONST CHAR8
*) Section
->PtrSection
, (CONST CHAR8
*) SectionName
) == 0) {
839 if (Section
->PtrEntry
!= NULL
) {
840 if (AsciiStrCmp ((CONST CHAR8
*) Section
->PtrEntry
, (CONST CHAR8
*) EntryName
) == 0) {
845 Section
= Section
->PtrNext
;
848 if (Section
== NULL
) {
849 return EFI_NOT_FOUND
;
852 *EntryValue
= Section
->PtrValue
;
858 Pre process config data buffer into Section entry list and Comment entry list.
860 @param[in] DataBuffer Config raw file buffer.
861 @param[in] BufferSize Size of raw buffer.
862 @param[in, out] SectionHead Pointer to the section entry list.
863 @param[in, out] CommentHead Pointer to the comment entry list.
865 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
866 @retval EFI_SUCCESS Config data buffer is preprocessed.
867 @retval EFI_NOT_FOUND Config data buffer is invalid, because Section or Entry is not found.
868 @retval EFI_INVALID_PARAMETER Config data buffer is invalid, because Section or Entry is invalid.
873 IN UINT8
*DataBuffer
,
875 IN OUT SECTION_ITEM
**SectionHead
,
876 IN OUT COMMENT_LINE
**CommentHead
890 BufferEnd
= (CHAR8
*) ( (UINTN
) DataBuffer
+ BufferSize
);
891 CurrentPtr
= (CHAR8
*) DataBuffer
;
892 MaxLineLength
= MAX_LINE_LENGTH
;
893 Status
= EFI_SUCCESS
;
895 PtrLine
= AllocatePool (MaxLineLength
);
896 if (PtrLine
== NULL
) {
897 return EFI_OUT_OF_RESOURCES
;
900 while (CurrentPtr
< BufferEnd
) {
902 SourceLength
= (UINTN
)BufferEnd
- (UINTN
)CurrentPtr
;
903 LineLength
= MaxLineLength
;
905 // With the assumption that line length is less than 512
906 // characters. Otherwise BUFFER_TOO_SMALL will be returned.
908 Status
= ProfileGetLine (
914 if (EFI_ERROR (Status
)) {
915 if (Status
== EFI_BUFFER_TOO_SMALL
) {
917 // If buffer too small, re-allocate the buffer according
918 // to the returned LineLength and try again.
922 PtrLine
= AllocatePool (LineLength
);
923 if (PtrLine
== NULL
) {
924 Status
= EFI_OUT_OF_RESOURCES
;
927 SourceLength
= LineLength
;
928 Status
= ProfileGetLine (
934 if (EFI_ERROR (Status
)) {
937 MaxLineLength
= LineLength
;
942 CurrentPtr
= (CHAR8
*) ( (UINTN
) CurrentPtr
+ LineLength
);
945 // Line got. Trim the line before processing it.
955 if (LineLength
== 0) {
959 if (PtrLine
[0] == '#' || PtrLine
[0] == ';') {
960 Status
= ProfileGetComments (
965 } else if (PtrLine
[0] == '[') {
966 Status
= ProfileGetSection (
972 Status
= ProfileGetEntry (
979 if (EFI_ERROR (Status
)) {
993 Open an INI config file and return a context.
995 @param[in] DataBuffer Config raw file buffer.
996 @param[in] BufferSize Size of raw buffer.
998 @return Config data buffer is opened and context is returned.
999 @retval NULL No enough memory is allocated.
1000 @retval NULL Config data buffer is invalid.
1005 IN UINT8
*DataBuffer
,
1010 INI_PARSING_LIB_CONTEXT
*IniContext
;
1012 if (DataBuffer
== NULL
|| BufferSize
== 0) {
1016 IniContext
= AllocateZeroPool(sizeof(INI_PARSING_LIB_CONTEXT
));
1017 if (IniContext
== NULL
) {
1022 // First process the data buffer and get all sections and entries
1024 Status
= PreProcessDataFile (
1027 &IniContext
->SectionHead
,
1028 &IniContext
->CommentHead
1030 if (EFI_ERROR(Status
)) {
1031 FreePool(IniContext
);
1034 DEBUG_CODE_BEGIN ();
1035 DumpIniSection(IniContext
);
1041 Get section entry string value.
1043 @param[in] Context INI Config file context.
1044 @param[in] SectionName Section name.
1045 @param[in] EntryName Section entry name.
1046 @param[out] EntryValue Point to the got entry string value.
1048 @retval EFI_SUCCESS Section entry string value is got.
1049 @retval EFI_NOT_FOUND Section is not found.
1053 GetStringFromDataFile(
1055 IN CHAR8
*SectionName
,
1056 IN CHAR8
*EntryName
,
1057 OUT CHAR8
**EntryValue
1060 INI_PARSING_LIB_CONTEXT
*IniContext
;
1063 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| EntryValue
== NULL
) {
1064 return EFI_INVALID_PARAMETER
;
1067 IniContext
= Context
;
1070 Status
= UpdateGetProfileString (
1071 IniContext
->SectionHead
,
1080 Get section entry GUID value.
1082 @param[in] Context INI Config file context.
1083 @param[in] SectionName Section name.
1084 @param[in] EntryName Section entry name.
1085 @param[out] Guid Point to the got GUID value.
1087 @retval EFI_SUCCESS Section entry GUID value is got.
1088 @retval EFI_NOT_FOUND Section is not found.
1092 GetGuidFromDataFile (
1094 IN CHAR8
*SectionName
,
1095 IN CHAR8
*EntryName
,
1101 RETURN_STATUS RStatus
;
1103 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Guid
== NULL
) {
1104 return EFI_INVALID_PARAMETER
;
1107 Status
= GetStringFromDataFile(
1113 if (EFI_ERROR(Status
)) {
1114 return EFI_NOT_FOUND
;
1116 ASSERT (Value
!= NULL
);
1117 RStatus
= AsciiStrToGuid (Value
, Guid
);
1118 if (RETURN_ERROR (RStatus
) || (Value
[GUID_STRING_LENGTH
] != '\0')) {
1119 return EFI_NOT_FOUND
;
1125 Get section entry decimal UINTN value.
1127 @param[in] Context INI Config file context.
1128 @param[in] SectionName Section name.
1129 @param[in] EntryName Section entry name.
1130 @param[out] Data Point to the got decimal UINTN value.
1132 @retval EFI_SUCCESS Section entry decimal UINTN value is got.
1133 @retval EFI_NOT_FOUND Section is not found.
1137 GetDecimalUintnFromDataFile (
1139 IN CHAR8
*SectionName
,
1140 IN CHAR8
*EntryName
,
1147 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1148 return EFI_INVALID_PARAMETER
;
1151 Status
= GetStringFromDataFile(
1157 if (EFI_ERROR(Status
)) {
1158 return EFI_NOT_FOUND
;
1160 ASSERT (Value
!= NULL
);
1161 if (!IsValidDecimalString(Value
, AsciiStrLen(Value
))) {
1162 return EFI_NOT_FOUND
;
1164 *Data
= AsciiStrDecimalToUintn(Value
);
1169 Get section entry heximal UINTN value.
1171 @param[in] Context INI Config file context.
1172 @param[in] SectionName Section name.
1173 @param[in] EntryName Section entry name.
1174 @param[out] Data Point to the got heximal UINTN value.
1176 @retval EFI_SUCCESS Section entry heximal UINTN value is got.
1177 @retval EFI_NOT_FOUND Section is not found.
1181 GetHexUintnFromDataFile (
1183 IN CHAR8
*SectionName
,
1184 IN CHAR8
*EntryName
,
1191 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1192 return EFI_INVALID_PARAMETER
;
1195 Status
= GetStringFromDataFile(
1201 if (EFI_ERROR(Status
)) {
1202 return EFI_NOT_FOUND
;
1204 ASSERT (Value
!= NULL
);
1205 if (!IsValidHexString(Value
, AsciiStrLen(Value
))) {
1206 return EFI_NOT_FOUND
;
1208 *Data
= AsciiStrHexToUintn(Value
);
1213 Get section entry heximal UINT64 value.
1215 @param[in] Context INI Config file context.
1216 @param[in] SectionName Section name.
1217 @param[in] EntryName Section entry name.
1218 @param[out] Data Point to the got heximal UINT64 value.
1220 @retval EFI_SUCCESS Section entry heximal UINT64 value is got.
1221 @retval EFI_NOT_FOUND Section is not found.
1225 GetHexUint64FromDataFile (
1227 IN CHAR8
*SectionName
,
1228 IN CHAR8
*EntryName
,
1235 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1236 return EFI_INVALID_PARAMETER
;
1239 Status
= GetStringFromDataFile(
1245 if (EFI_ERROR(Status
)) {
1246 return EFI_NOT_FOUND
;
1248 ASSERT (Value
!= NULL
);
1249 if (!IsValidHexString(Value
, AsciiStrLen(Value
))) {
1250 return EFI_NOT_FOUND
;
1252 *Data
= AsciiStrHexToUint64(Value
);
1257 Close an INI config file and free the context.
1259 @param[in] Context INI Config file context.
1267 INI_PARSING_LIB_CONTEXT
*IniContext
;
1269 if (Context
== NULL
) {
1273 IniContext
= Context
;
1274 FreeAllList(IniContext
->SectionHead
, IniContext
->CommentHead
);