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 hexadecimal 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')) {
86 if ((DigitalChar
>= 'a') && (DigitalChar
<= 'f')) {
90 if ((DigitalChar
>= 'A') && (DigitalChar
<= 'F')) {
99 Return if the name char is valid.
101 @param[in] NameChar The name char to be checked.
103 @retval TRUE The name char is valid.
104 @retval FALSE The name char is invalid.
111 if ((NameChar
>= 'a') && (NameChar
<= 'z')) {
115 if ((NameChar
>= 'A') && (NameChar
<= 'Z')) {
119 if ((NameChar
>= '0') && (NameChar
<= '9')) {
123 if (NameChar
== '_') {
131 Return if the digital string is valid.
133 @param[in] Digital The digital to be checked.
134 @param[in] Length The length of digital string in bytes.
135 @param[in] IncludeHex If it include HEX char.
137 @retval TRUE The digital string is valid.
138 @retval FALSE The digital string is invalid.
144 IN BOOLEAN IncludeHex
149 for (Index
= 0; Index
< Length
; Index
++) {
150 if (!IsValidDigitalChar (Digital
[Index
], IncludeHex
)) {
159 Return if the decimal string is valid.
161 @param[in] Decimal The decimal string to be checked.
162 @param[in] Length The length of decimal string in bytes.
164 @retval TRUE The decimal string is valid.
165 @retval FALSE The decimal string is invalid.
168 IsValidDecimalString (
173 return IsValidDigital (Decimal
, Length
, FALSE
);
177 Return if the hexadecimal string is valid.
179 @param[in] Hex The hexadecimal string to be checked.
180 @param[in] Length The length of hexadecimal string in bytes.
182 @retval TRUE The hexadecimal string is valid.
183 @retval FALSE The hexadecimal string is invalid.
199 if ((Hex
[1] != 'x') && (Hex
[1] != 'X')) {
203 return IsValidDigital (&Hex
[2], Length
- 2, TRUE
);
207 Return if the name string is valid.
209 @param[in] Name The name to be checked.
210 @param[in] Length The length of name string in bytes.
212 @retval TRUE The name string is valid.
213 @retval FALSE The name string is invalid.
223 for (Index
= 0; Index
< Length
; Index
++) {
224 if (!IsValidNameChar (Name
[Index
])) {
233 Return if the value string is valid GUID.
235 @param[in] Value The value to be checked.
236 @param[in] Length The length of value string in bytes.
238 @retval TRUE The value string is valid GUID.
239 @retval FALSE The value string is invalid GUID.
247 if (Length
!= sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") - 1) {
251 if (!IS_HYPHEN (Value
[8])) {
255 if (!IS_HYPHEN (Value
[13])) {
259 if (!IS_HYPHEN (Value
[18])) {
263 if (!IS_HYPHEN (Value
[23])) {
267 if (!IsValidDigital (&Value
[0], 8, TRUE
)) {
271 if (!IsValidDigital (&Value
[9], 4, TRUE
)) {
275 if (!IsValidDigital (&Value
[14], 4, TRUE
)) {
279 if (!IsValidDigital (&Value
[19], 4, TRUE
)) {
283 if (!IsValidDigital (&Value
[24], 12, TRUE
)) {
291 Return if the value string is valid.
293 @param[in] Value The value to be checked.
294 @param[in] Length The length of value string in bytes.
296 @retval TRUE The name string is valid.
297 @retval FALSE The name string is invalid.
305 if (IsValidName (Value
, Length
) || IsValidGuid (Value
, Length
)) {
313 Dump an INI config file context.
315 @param[in] Context INI Config file context.
322 INI_PARSING_LIB_CONTEXT
*IniContext
;
323 SECTION_ITEM
*PtrSection
;
324 SECTION_ITEM
*Section
;
326 if (Context
== NULL
) {
330 IniContext
= Context
;
331 Section
= IniContext
->SectionHead
;
333 while (Section
!= NULL
) {
334 PtrSection
= Section
;
335 Section
= Section
->PtrNext
;
336 if (PtrSection
->PtrSection
!= NULL
) {
337 DEBUG ((DEBUG_VERBOSE
, "Section - %a\n", PtrSection
->PtrSection
));
340 if (PtrSection
->PtrEntry
!= NULL
) {
341 DEBUG ((DEBUG_VERBOSE
, " Entry - %a\n", PtrSection
->PtrEntry
));
344 if (PtrSection
->PtrValue
!= NULL
) {
345 DEBUG ((DEBUG_VERBOSE
, " Value - %a\n", PtrSection
->PtrValue
));
351 Copy one line data from buffer data to the line buffer.
353 @param[in] Buffer Buffer data.
354 @param[in] BufferSize Buffer Size.
355 @param[in, out] LineBuffer Line buffer to store the found line data.
356 @param[in, out] LineSize On input, size of the input line buffer.
357 On output, size of the actual line buffer.
359 @retval EFI_BUFFER_TOO_SMALL The size of input line buffer is not enough.
360 @retval EFI_SUCCESS Copy line data into the line buffer.
367 IN OUT UINT8
*LineBuffer
,
368 IN OUT UINTN
*LineSize
376 PtrEnd
= (UINTN
)Buffer
+ BufferSize
;
379 // 0x0D indicates a line break. Otherwise there is no line break
381 while ((UINTN
)PtrBuf
< PtrEnd
) {
382 if ((*PtrBuf
== 0x0D) || (*PtrBuf
== 0x0A)) {
389 if ((UINTN
)PtrBuf
>= (PtrEnd
- 1)) {
391 // The buffer ends without any line break
392 // or it is the last character of the buffer
395 } else if (*(PtrBuf
+ 1) == 0x0A) {
397 // Further check if a 0x0A follows. If yes, count 0xA
399 Length
= (UINTN
)PtrBuf
- (UINTN
)Buffer
+ 2;
401 Length
= (UINTN
)PtrBuf
- (UINTN
)Buffer
+ 1;
404 if (Length
> (*LineSize
)) {
406 return EFI_BUFFER_TOO_SMALL
;
409 SetMem (LineBuffer
, *LineSize
, 0x0);
411 CopyMem (LineBuffer
, Buffer
, Length
);
417 Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.
419 @param[in, out] Buffer On input, buffer data to be trimmed.
420 On output, the trimmed buffer.
421 @param[in, out] BufferSize On input, size of original buffer data.
422 On output, size of the trimmed buffer.
427 IN OUT UINT8
*Buffer
,
428 IN OUT UINTN
*BufferSize
435 if (*BufferSize
== 0) {
440 // Trim the tail first, include CR, LF, TAB, and SPACE.
442 Length
= *BufferSize
;
443 PtrBuf
= (UINT8
*)((UINTN
)Buffer
+ Length
- 1);
444 while (PtrBuf
>= Buffer
) {
445 if ( (*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A)
446 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09))
455 // all spaces, a blank line, return directly;
457 if (PtrBuf
< Buffer
) {
462 Length
= (UINTN
)PtrBuf
- (UINTN
)Buffer
+ 1;
467 // Now skip the heading CR, LF, TAB and SPACE
469 while (PtrBuf
<= PtrEnd
) {
470 if ( (*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A)
471 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09))
480 // If no heading CR, LF, TAB or SPACE, directly return
482 if (PtrBuf
== Buffer
) {
483 *BufferSize
= Length
;
487 *BufferSize
= (UINTN
)PtrEnd
- (UINTN
)PtrBuf
+ 1;
490 // The first Buffer..PtrBuf characters are CR, LF, TAB or SPACE.
491 // Now move out all these characters.
493 while (PtrBuf
<= PtrEnd
) {
503 Insert new comment item into comment head.
505 @param[in] Buffer Comment buffer to be added.
506 @param[in] BufferSize Size of comment buffer.
507 @param[in, out] CommentHead Comment Item head entry.
509 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
510 @retval EFI_SUCCESS New comment item is inserted.
517 IN OUT COMMENT_LINE
**CommentHead
520 COMMENT_LINE
*CommentItem
;
523 CommentItem
= AllocatePool (sizeof (COMMENT_LINE
));
524 if (CommentItem
== NULL
) {
525 return EFI_OUT_OF_RESOURCES
;
528 CommentItem
->PtrNext
= *CommentHead
;
529 *CommentHead
= CommentItem
;
532 // Add a trailing '\0'
534 CommentItem
->PtrComment
= AllocatePool (BufferSize
+ 1);
535 if (CommentItem
->PtrComment
== NULL
) {
536 FreePool (CommentItem
);
537 return EFI_OUT_OF_RESOURCES
;
540 CopyMem (CommentItem
->PtrComment
, Buffer
, BufferSize
);
541 *(CommentItem
->PtrComment
+ BufferSize
) = '\0';
547 Add new section item into Section head.
549 @param[in] Buffer Section item data buffer.
550 @param[in] BufferSize Size of section item.
551 @param[in, out] SectionHead Section item head entry.
553 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
554 @retval EFI_SUCCESS Section item is NULL or Section item is added.
561 IN OUT SECTION_ITEM
**SectionHead
564 SECTION_ITEM
*SectionItem
;
569 ASSERT (BufferSize
>= 1);
571 // The first character of Buffer is '[', now we want for ']'
573 PtrEnd
= (UINT8
*)((UINTN
)Buffer
+ BufferSize
- 1);
574 PtrBuf
= (UINT8
*)((UINTN
)Buffer
+ 1);
575 while (PtrBuf
<= PtrEnd
) {
576 if (*PtrBuf
== ']') {
583 if (PtrBuf
> PtrEnd
) {
585 // Not found. Invalid line
587 return EFI_NOT_FOUND
;
590 if (PtrBuf
<= Buffer
+ 1) {
592 return EFI_NOT_FOUND
;
596 // excluding the heading '[' and tailing ']'
598 Length
= PtrBuf
- Buffer
- 1;
605 // Invalid line if the section name is null
608 return EFI_NOT_FOUND
;
611 if (!IsValidName ((CHAR8
*)Buffer
+ 1, Length
)) {
612 return EFI_INVALID_PARAMETER
;
615 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
616 if (SectionItem
== NULL
) {
617 return EFI_OUT_OF_RESOURCES
;
620 SectionItem
->PtrSection
= NULL
;
621 SectionItem
->SecNameLen
= Length
;
622 SectionItem
->PtrEntry
= NULL
;
623 SectionItem
->PtrValue
= NULL
;
624 SectionItem
->PtrNext
= *SectionHead
;
625 *SectionHead
= SectionItem
;
628 // Add a trailing '\0'
630 SectionItem
->PtrSection
= AllocatePool (Length
+ 1);
631 if (SectionItem
->PtrSection
== NULL
) {
632 return EFI_OUT_OF_RESOURCES
;
636 // excluding the heading '['
638 CopyMem (SectionItem
->PtrSection
, Buffer
+ 1, Length
);
639 *(SectionItem
->PtrSection
+ Length
) = '\0';
645 Add new section entry and entry value into Section head.
647 @param[in] Buffer Section entry data buffer.
648 @param[in] BufferSize Size of section entry.
649 @param[in, out] SectionHead Section item head entry.
651 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
652 @retval EFI_SUCCESS Section entry is added.
653 @retval EFI_NOT_FOUND Section entry is not found.
654 @retval EFI_INVALID_PARAMETER Section entry is invalid.
661 IN OUT SECTION_ITEM
**SectionHead
665 SECTION_ITEM
*SectionItem
;
666 SECTION_ITEM
*PtrSection
;
671 Status
= EFI_SUCCESS
;
673 PtrEnd
= (UINT8
*)((UINTN
)Buffer
+ BufferSize
- 1);
676 // First search for '='
678 while (PtrBuf
<= PtrEnd
) {
679 if (*PtrBuf
== '=') {
686 if (PtrBuf
> PtrEnd
) {
688 // Not found. Invalid line
690 return EFI_NOT_FOUND
;
693 if (PtrBuf
<= Buffer
) {
695 return EFI_NOT_FOUND
;
699 // excluding the tailing '='
701 Length
= PtrBuf
- Buffer
;
708 // Invalid line if the entry name is null
711 return EFI_NOT_FOUND
;
714 if (!IsValidName ((CHAR8
*)Buffer
, Length
)) {
715 return EFI_INVALID_PARAMETER
;
719 // Omit this line if no section header has been found before
721 if (*SectionHead
== NULL
) {
725 PtrSection
= *SectionHead
;
727 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
728 if (SectionItem
== NULL
) {
729 return EFI_OUT_OF_RESOURCES
;
732 SectionItem
->PtrSection
= NULL
;
733 SectionItem
->PtrEntry
= NULL
;
734 SectionItem
->PtrValue
= NULL
;
735 SectionItem
->SecNameLen
= PtrSection
->SecNameLen
;
736 SectionItem
->PtrNext
= *SectionHead
;
737 *SectionHead
= SectionItem
;
740 // SectionName, add a trailing '\0'
742 SectionItem
->PtrSection
= AllocatePool (PtrSection
->SecNameLen
+ 1);
743 if (SectionItem
->PtrSection
== NULL
) {
744 return EFI_OUT_OF_RESOURCES
;
747 CopyMem (SectionItem
->PtrSection
, PtrSection
->PtrSection
, PtrSection
->SecNameLen
+ 1);
750 // EntryName, add a trailing '\0'
752 SectionItem
->PtrEntry
= AllocatePool (Length
+ 1);
753 if (SectionItem
->PtrEntry
== NULL
) {
754 FreePool (SectionItem
->PtrSection
);
755 return EFI_OUT_OF_RESOURCES
;
758 CopyMem (SectionItem
->PtrEntry
, Buffer
, Length
);
759 *(SectionItem
->PtrEntry
+ Length
) = '\0';
762 // Next search for '#' or ';'
766 while (PtrBuf
<= PtrEnd
) {
767 if ((*PtrBuf
== '#') || (*PtrBuf
== ';')) {
774 if (PtrBuf
<= Buffer
) {
776 FreePool (SectionItem
->PtrEntry
);
777 FreePool (SectionItem
->PtrSection
);
778 return EFI_NOT_FOUND
;
781 Length
= PtrBuf
- Buffer
;
788 // Invalid line if the entry value is null
791 FreePool (SectionItem
->PtrEntry
);
792 FreePool (SectionItem
->PtrSection
);
793 return EFI_NOT_FOUND
;
796 if (!IsValidValue ((CHAR8
*)Buffer
, Length
)) {
797 FreePool (SectionItem
->PtrEntry
);
798 FreePool (SectionItem
->PtrSection
);
799 return EFI_INVALID_PARAMETER
;
803 // EntryValue, add a trailing '\0'
805 SectionItem
->PtrValue
= AllocatePool (Length
+ 1);
806 if (SectionItem
->PtrValue
== NULL
) {
807 FreePool (SectionItem
->PtrEntry
);
808 FreePool (SectionItem
->PtrSection
);
809 return EFI_OUT_OF_RESOURCES
;
812 CopyMem (SectionItem
->PtrValue
, Buffer
, Length
);
813 *(SectionItem
->PtrValue
+ Length
) = '\0';
819 Free all comment entry and section entry.
821 @param[in] Section Section entry list.
822 @param[in] Comment Comment entry list.
827 IN SECTION_ITEM
*Section
,
828 IN COMMENT_LINE
*Comment
831 SECTION_ITEM
*PtrSection
;
832 COMMENT_LINE
*PtrComment
;
834 while (Section
!= NULL
) {
835 PtrSection
= Section
;
836 Section
= Section
->PtrNext
;
837 if (PtrSection
->PtrEntry
!= NULL
) {
838 FreePool (PtrSection
->PtrEntry
);
841 if (PtrSection
->PtrSection
!= NULL
) {
842 FreePool (PtrSection
->PtrSection
);
845 if (PtrSection
->PtrValue
!= NULL
) {
846 FreePool (PtrSection
->PtrValue
);
849 FreePool (PtrSection
);
852 while (Comment
!= NULL
) {
853 PtrComment
= Comment
;
854 Comment
= Comment
->PtrNext
;
855 if (PtrComment
->PtrComment
!= NULL
) {
856 FreePool (PtrComment
->PtrComment
);
859 FreePool (PtrComment
);
866 Get section entry value.
868 @param[in] Section Section entry list.
869 @param[in] SectionName Section name.
870 @param[in] EntryName Section entry name.
871 @param[out] EntryValue Point to the got entry value.
873 @retval EFI_NOT_FOUND Section is not found.
874 @retval EFI_SUCCESS Section entry value is got.
878 UpdateGetProfileString (
879 IN SECTION_ITEM
*Section
,
880 IN CHAR8
*SectionName
,
882 OUT CHAR8
**EntryValue
887 while (Section
!= NULL
) {
888 if (AsciiStrCmp ((CONST CHAR8
*)Section
->PtrSection
, (CONST CHAR8
*)SectionName
) == 0) {
889 if (Section
->PtrEntry
!= NULL
) {
890 if (AsciiStrCmp ((CONST CHAR8
*)Section
->PtrEntry
, (CONST CHAR8
*)EntryName
) == 0) {
896 Section
= Section
->PtrNext
;
899 if (Section
== NULL
) {
900 return EFI_NOT_FOUND
;
903 *EntryValue
= Section
->PtrValue
;
909 Pre process config data buffer into Section entry list and Comment entry list.
911 @param[in] DataBuffer Config raw file buffer.
912 @param[in] BufferSize Size of raw buffer.
913 @param[in, out] SectionHead Pointer to the section entry list.
914 @param[in, out] CommentHead Pointer to the comment entry list.
916 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
917 @retval EFI_SUCCESS Config data buffer is preprocessed.
918 @retval EFI_NOT_FOUND Config data buffer is invalid, because Section or Entry is not found.
919 @retval EFI_INVALID_PARAMETER Config data buffer is invalid, because Section or Entry is invalid.
924 IN UINT8
*DataBuffer
,
926 IN OUT SECTION_ITEM
**SectionHead
,
927 IN OUT COMMENT_LINE
**CommentHead
941 BufferEnd
= (CHAR8
*)((UINTN
)DataBuffer
+ BufferSize
);
942 CurrentPtr
= (CHAR8
*)DataBuffer
;
943 MaxLineLength
= MAX_LINE_LENGTH
;
944 Status
= EFI_SUCCESS
;
946 PtrLine
= AllocatePool (MaxLineLength
);
947 if (PtrLine
== NULL
) {
948 return EFI_OUT_OF_RESOURCES
;
951 while (CurrentPtr
< BufferEnd
) {
953 SourceLength
= (UINTN
)BufferEnd
- (UINTN
)CurrentPtr
;
954 LineLength
= MaxLineLength
;
956 // With the assumption that line length is less than 512
957 // characters. Otherwise BUFFER_TOO_SMALL will be returned.
959 Status
= ProfileGetLine (
965 if (EFI_ERROR (Status
)) {
966 if (Status
== EFI_BUFFER_TOO_SMALL
) {
968 // If buffer too small, re-allocate the buffer according
969 // to the returned LineLength and try again.
973 PtrLine
= AllocatePool (LineLength
);
974 if (PtrLine
== NULL
) {
975 Status
= EFI_OUT_OF_RESOURCES
;
979 SourceLength
= LineLength
;
980 Status
= ProfileGetLine (
986 if (EFI_ERROR (Status
)) {
990 MaxLineLength
= LineLength
;
996 CurrentPtr
= (CHAR8
*)((UINTN
)CurrentPtr
+ LineLength
);
999 // Line got. Trim the line before processing it.
1009 if (LineLength
== 0) {
1013 if ((PtrLine
[0] == '#') || (PtrLine
[0] == ';')) {
1014 Status
= ProfileGetComments (
1019 } else if (PtrLine
[0] == '[') {
1020 Status
= ProfileGetSection (
1026 Status
= ProfileGetEntry (
1033 if (EFI_ERROR (Status
)) {
1047 Open an INI config file and return a context.
1049 @param[in] DataBuffer Config raw file buffer.
1050 @param[in] BufferSize Size of raw buffer.
1052 @return Config data buffer is opened and context is returned.
1053 @retval NULL No enough memory is allocated.
1054 @retval NULL Config data buffer is invalid.
1059 IN UINT8
*DataBuffer
,
1064 INI_PARSING_LIB_CONTEXT
*IniContext
;
1066 if ((DataBuffer
== NULL
) || (BufferSize
== 0)) {
1070 IniContext
= AllocateZeroPool (sizeof (INI_PARSING_LIB_CONTEXT
));
1071 if (IniContext
== NULL
) {
1076 // First process the data buffer and get all sections and entries
1078 Status
= PreProcessDataFile (
1081 &IniContext
->SectionHead
,
1082 &IniContext
->CommentHead
1084 if (EFI_ERROR (Status
)) {
1085 FreePool (IniContext
);
1089 DEBUG_CODE_BEGIN ();
1090 DumpIniSection (IniContext
);
1096 Get section entry string value.
1098 @param[in] Context INI Config file context.
1099 @param[in] SectionName Section name.
1100 @param[in] EntryName Section entry name.
1101 @param[out] EntryValue Point to the got entry string value.
1103 @retval EFI_SUCCESS Section entry string value is got.
1104 @retval EFI_NOT_FOUND Section is not found.
1108 GetStringFromDataFile (
1110 IN CHAR8
*SectionName
,
1111 IN CHAR8
*EntryName
,
1112 OUT CHAR8
**EntryValue
1115 INI_PARSING_LIB_CONTEXT
*IniContext
;
1118 if ((Context
== NULL
) || (SectionName
== NULL
) || (EntryName
== NULL
) || (EntryValue
== NULL
)) {
1119 return EFI_INVALID_PARAMETER
;
1122 IniContext
= Context
;
1125 Status
= UpdateGetProfileString (
1126 IniContext
->SectionHead
,
1135 Get section entry GUID value.
1137 @param[in] Context INI Config file context.
1138 @param[in] SectionName Section name.
1139 @param[in] EntryName Section entry name.
1140 @param[out] Guid Point to the got GUID value.
1142 @retval EFI_SUCCESS Section entry GUID value is got.
1143 @retval EFI_NOT_FOUND Section is not found.
1147 GetGuidFromDataFile (
1149 IN CHAR8
*SectionName
,
1150 IN CHAR8
*EntryName
,
1156 RETURN_STATUS RStatus
;
1158 if ((Context
== NULL
) || (SectionName
== NULL
) || (EntryName
== NULL
) || (Guid
== NULL
)) {
1159 return EFI_INVALID_PARAMETER
;
1162 Status
= GetStringFromDataFile (
1168 if (EFI_ERROR (Status
)) {
1169 return EFI_NOT_FOUND
;
1172 ASSERT (Value
!= NULL
);
1173 RStatus
= AsciiStrToGuid (Value
, Guid
);
1174 if (RETURN_ERROR (RStatus
) || (Value
[GUID_STRING_LENGTH
] != '\0')) {
1175 return EFI_NOT_FOUND
;
1182 Get section entry decimal UINTN value.
1184 @param[in] Context INI Config file context.
1185 @param[in] SectionName Section name.
1186 @param[in] EntryName Section entry name.
1187 @param[out] Data Point to the got decimal UINTN value.
1189 @retval EFI_SUCCESS Section entry decimal UINTN value is got.
1190 @retval EFI_NOT_FOUND Section is not found.
1194 GetDecimalUintnFromDataFile (
1196 IN CHAR8
*SectionName
,
1197 IN CHAR8
*EntryName
,
1204 if ((Context
== NULL
) || (SectionName
== NULL
) || (EntryName
== NULL
) || (Data
== NULL
)) {
1205 return EFI_INVALID_PARAMETER
;
1208 Status
= GetStringFromDataFile (
1214 if (EFI_ERROR (Status
)) {
1215 return EFI_NOT_FOUND
;
1218 ASSERT (Value
!= NULL
);
1219 if (!IsValidDecimalString (Value
, AsciiStrLen (Value
))) {
1220 return EFI_NOT_FOUND
;
1223 *Data
= AsciiStrDecimalToUintn (Value
);
1228 Get section entry hexadecimal UINTN value.
1230 @param[in] Context INI Config file context.
1231 @param[in] SectionName Section name.
1232 @param[in] EntryName Section entry name.
1233 @param[out] Data Point to the got hexadecimal UINTN value.
1235 @retval EFI_SUCCESS Section entry hexadecimal UINTN value is got.
1236 @retval EFI_NOT_FOUND Section is not found.
1240 GetHexUintnFromDataFile (
1242 IN CHAR8
*SectionName
,
1243 IN CHAR8
*EntryName
,
1250 if ((Context
== NULL
) || (SectionName
== NULL
) || (EntryName
== NULL
) || (Data
== NULL
)) {
1251 return EFI_INVALID_PARAMETER
;
1254 Status
= GetStringFromDataFile (
1260 if (EFI_ERROR (Status
)) {
1261 return EFI_NOT_FOUND
;
1264 ASSERT (Value
!= NULL
);
1265 if (!IsValidHexString (Value
, AsciiStrLen (Value
))) {
1266 return EFI_NOT_FOUND
;
1269 *Data
= AsciiStrHexToUintn (Value
);
1274 Get section entry hexadecimal UINT64 value.
1276 @param[in] Context INI Config file context.
1277 @param[in] SectionName Section name.
1278 @param[in] EntryName Section entry name.
1279 @param[out] Data Point to the got hexadecimal UINT64 value.
1281 @retval EFI_SUCCESS Section entry hexadecimal UINT64 value is got.
1282 @retval EFI_NOT_FOUND Section is not found.
1286 GetHexUint64FromDataFile (
1288 IN CHAR8
*SectionName
,
1289 IN CHAR8
*EntryName
,
1296 if ((Context
== NULL
) || (SectionName
== NULL
) || (EntryName
== NULL
) || (Data
== NULL
)) {
1297 return EFI_INVALID_PARAMETER
;
1300 Status
= GetStringFromDataFile (
1306 if (EFI_ERROR (Status
)) {
1307 return EFI_NOT_FOUND
;
1310 ASSERT (Value
!= NULL
);
1311 if (!IsValidHexString (Value
, AsciiStrLen (Value
))) {
1312 return EFI_NOT_FOUND
;
1315 *Data
= AsciiStrHexToUint64 (Value
);
1320 Close an INI config file and free the context.
1322 @param[in] Context INI Config file context.
1330 INI_PARSING_LIB_CONTEXT
*IniContext
;
1332 if (Context
== NULL
) {
1336 IniContext
= Context
;
1337 FreeAllList (IniContext
->SectionHead
, IniContext
->CommentHead
);