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 This program and the accompanying materials
31 are licensed and made available under the terms and conditions
32 of the BSD License which accompanies this distribution. The
33 full text of the license may be found at
34 http://opensource.org/licenses/bsd-license.php
36 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
37 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
42 #include <Library/BaseLib.h>
43 #include <Library/BaseMemoryLib.h>
44 #include <Library/DebugLib.h>
45 #include <Library/MemoryAllocationLib.h>
47 #define IS_HYPHEN(a) ((a) == '-')
48 #define IS_NULL(a) ((a) == '\0')
50 // This is default allocation. Reallocation will happen if it is not enough.
51 #define MAX_LINE_LENGTH 512
53 typedef struct _INI_SECTION_ITEM SECTION_ITEM
;
54 struct _INI_SECTION_ITEM
{
59 SECTION_ITEM
*PtrNext
;
62 typedef struct _INI_COMMENT_LINE COMMENT_LINE
;
63 struct _INI_COMMENT_LINE
{
65 COMMENT_LINE
*PtrNext
;
69 SECTION_ITEM
*SectionHead
;
70 COMMENT_LINE
*CommentHead
;
71 } INI_PARSING_LIB_CONTEXT
;
74 Return if the digital char is valid.
76 @param[in] DigitalChar The digital char to be checked.
77 @param[in] IncludeHex If it include HEX char.
79 @retval TRUE The digital char is valid.
80 @retval FALSE The digital char is invalid.
88 if (DigitalChar
>= '0' && DigitalChar
<= '9') {
92 if (DigitalChar
>= 'a' && DigitalChar
<= 'f') {
95 if (DigitalChar
>= 'A' && DigitalChar
<= 'F') {
103 Return if the name char is valid.
105 @param[in] NameChar The name char to be checked.
107 @retval TRUE The name char is valid.
108 @retval FALSE The name char is invalid.
115 if (NameChar
>= 'a' && NameChar
<= 'z') {
118 if (NameChar
>= 'A' && NameChar
<= 'Z') {
121 if (NameChar
>= '0' && NameChar
<= '9') {
124 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
148 for (Index
= 0; Index
< Length
; Index
++) {
149 if (!IsValidDigitalChar(Digital
[Index
], IncludeHex
)) {
157 Return if the decimal string is valid.
159 @param[in] Decimal The decimal string to be checked.
160 @param[in] Length The length of decimal string in bytes.
162 @retval TRUE The decimal string is valid.
163 @retval FALSE The decimal string is invalid.
166 IsValidDecimalString (
171 return IsValidDigital(Decimal
, Length
, FALSE
);
175 Return if the heximal string is valid.
177 @param[in] Hex The heximal string to be checked.
178 @param[in] Length The length of heximal string in bytes.
180 @retval TRUE The heximal string is valid.
181 @retval FALSE The heximal string is invalid.
195 if (Hex
[1] != 'x' && Hex
[1] != 'X') {
198 return IsValidDigital(&Hex
[2], Length
- 2, TRUE
);
202 Return if the name string is valid.
204 @param[in] Name The name to be checked.
205 @param[in] Length The length of name string in bytes.
207 @retval TRUE The name string is valid.
208 @retval FALSE The name string is invalid.
217 for (Index
= 0; Index
< Length
; Index
++) {
218 if (!IsValidNameChar(Name
[Index
])) {
226 Return if the value string is valid GUID.
228 @param[in] Value The value to be checked.
229 @param[in] Length The length of value string in bytes.
231 @retval TRUE The value string is valid GUID.
232 @retval FALSE The value string is invalid GUID.
240 if (Length
!= sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") - 1) {
243 if (!IS_HYPHEN(Value
[8])) {
246 if (!IS_HYPHEN(Value
[13])) {
249 if (!IS_HYPHEN(Value
[18])) {
252 if (!IS_HYPHEN(Value
[23])) {
255 if (!IsValidDigital(&Value
[0], 8, TRUE
)) {
258 if (!IsValidDigital(&Value
[9], 4, TRUE
)) {
261 if (!IsValidDigital(&Value
[14], 4, TRUE
)) {
264 if (!IsValidDigital(&Value
[19], 4, TRUE
)) {
267 if (!IsValidDigital(&Value
[24], 12, TRUE
)) {
274 Return if the value string is valid.
276 @param[in] Value The value to be checked.
277 @param[in] Length The length of value string in bytes.
279 @retval TRUE The name string is valid.
280 @retval FALSE The name string is invalid.
288 if (IsValidName(Value
, Length
) || IsValidGuid(Value
, Length
)) {
295 Dump an INI config file context.
297 @param[in] Context INI Config file context.
304 INI_PARSING_LIB_CONTEXT
*IniContext
;
305 SECTION_ITEM
*PtrSection
;
306 SECTION_ITEM
*Section
;
308 if (Context
== NULL
) {
312 IniContext
= Context
;
313 Section
= IniContext
->SectionHead
;
315 while (Section
!= NULL
) {
316 PtrSection
= Section
;
317 Section
= Section
->PtrNext
;
318 if (PtrSection
->PtrSection
!= NULL
) {
319 DEBUG((DEBUG_VERBOSE
, "Section - %a\n", PtrSection
->PtrSection
));
321 if (PtrSection
->PtrEntry
!= NULL
) {
322 DEBUG ((DEBUG_VERBOSE
, " Entry - %a\n", PtrSection
->PtrEntry
));
324 if (PtrSection
->PtrValue
!= NULL
) {
325 DEBUG((DEBUG_VERBOSE
, " Value - %a\n", PtrSection
->PtrValue
));
331 Copy one line data from buffer data to the line buffer.
333 @param[in] Buffer Buffer data.
334 @param[in] BufferSize Buffer Size.
335 @param[in, out] LineBuffer Line buffer to store the found line data.
336 @param[in, out] LineSize On input, size of the input line buffer.
337 On output, size of the actual line buffer.
339 @retval EFI_BUFFER_TOO_SMALL The size of input line buffer is not enough.
340 @retval EFI_SUCCESS Copy line data into the line buffer.
347 IN OUT UINT8
*LineBuffer
,
348 IN OUT UINTN
*LineSize
356 PtrEnd
= (UINTN
)Buffer
+ BufferSize
;
359 // 0x0D indicates a line break. Otherwise there is no line break
361 while ((UINTN
)PtrBuf
< PtrEnd
) {
362 if (*PtrBuf
== 0x0D || *PtrBuf
== 0x0A) {
368 if ((UINTN
)PtrBuf
>= (PtrEnd
- 1)) {
370 // The buffer ends without any line break
371 // or it is the last character of the buffer
374 } else if (*(PtrBuf
+ 1) == 0x0A) {
376 // Further check if a 0x0A follows. If yes, count 0xA
378 Length
= (UINTN
) PtrBuf
- (UINTN
) Buffer
+ 2;
380 Length
= (UINTN
) PtrBuf
- (UINTN
) Buffer
+ 1;
383 if (Length
> (*LineSize
)) {
385 return EFI_BUFFER_TOO_SMALL
;
388 SetMem (LineBuffer
, *LineSize
, 0x0);
390 CopyMem (LineBuffer
, Buffer
, Length
);
396 Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.
398 @param[in, out] Buffer On input, buffer data to be trimed.
399 On output, the trimmed buffer.
400 @param[in, out] BufferSize On input, size of original buffer data.
401 On output, size of the trimmed buffer.
406 IN OUT UINT8
*Buffer
,
407 IN OUT UINTN
*BufferSize
414 if (*BufferSize
== 0) {
419 // Trim the tail first, include CR, LF, TAB, and SPACE.
421 Length
= *BufferSize
;
422 PtrBuf
= (UINT8
*) ((UINTN
) Buffer
+ Length
- 1);
423 while (PtrBuf
>= Buffer
) {
424 if ((*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A )
425 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09)) {
432 // all spaces, a blank line, return directly;
434 if (PtrBuf
< Buffer
) {
439 Length
= (UINTN
)PtrBuf
- (UINTN
)Buffer
+ 1;
444 // Now skip the heading CR, LF, TAB and SPACE
446 while (PtrBuf
<= PtrEnd
) {
447 if ((*PtrBuf
!= 0x0D) && (*PtrBuf
!= 0x0A )
448 && (*PtrBuf
!= 0x20) && (*PtrBuf
!= 0x09)) {
455 // If no heading CR, LF, TAB or SPACE, directly return
457 if (PtrBuf
== Buffer
) {
458 *BufferSize
= Length
;
462 *BufferSize
= (UINTN
)PtrEnd
- (UINTN
)PtrBuf
+ 1;
465 // The first Buffer..PtrBuf characters are CR, LF, TAB or SPACE.
466 // Now move out all these characters.
468 while (PtrBuf
<= PtrEnd
) {
478 Insert new comment item into comment head.
480 @param[in] Buffer Comment buffer to be added.
481 @param[in] BufferSize Size of comment buffer.
482 @param[in, out] CommentHead Comment Item head entry.
484 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
485 @retval EFI_SUCCESS New comment item is inserted.
492 IN OUT COMMENT_LINE
**CommentHead
495 COMMENT_LINE
*CommentItem
;
498 CommentItem
= AllocatePool (sizeof (COMMENT_LINE
));
499 if (CommentItem
== NULL
) {
500 return EFI_OUT_OF_RESOURCES
;
503 CommentItem
->PtrNext
= *CommentHead
;
504 *CommentHead
= CommentItem
;
507 // Add a trailing '\0'
509 CommentItem
->PtrComment
= AllocatePool (BufferSize
+ 1);
510 if (CommentItem
->PtrComment
== NULL
) {
511 FreePool (CommentItem
);
512 return EFI_OUT_OF_RESOURCES
;
514 CopyMem (CommentItem
->PtrComment
, Buffer
, BufferSize
);
515 *(CommentItem
->PtrComment
+ BufferSize
) = '\0';
521 Add new section item into Section head.
523 @param[in] Buffer Section item data buffer.
524 @param[in] BufferSize Size of section item.
525 @param[in, out] SectionHead Section item head entry.
527 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
528 @retval EFI_SUCCESS Section item is NULL or Section item is added.
535 IN OUT SECTION_ITEM
**SectionHead
538 SECTION_ITEM
*SectionItem
;
543 ASSERT(BufferSize
>= 1);
545 // The first character of Buffer is '[', now we want for ']'
547 PtrEnd
= (UINT8
*)((UINTN
)Buffer
+ BufferSize
- 1);
548 PtrBuf
= (UINT8
*)((UINTN
)Buffer
+ 1);
549 while (PtrBuf
<= PtrEnd
) {
550 if (*PtrBuf
== ']') {
555 if (PtrBuf
> PtrEnd
) {
557 // Not found. Invalid line
559 return EFI_NOT_FOUND
;
561 if (PtrBuf
<= Buffer
+ 1) {
563 return EFI_NOT_FOUND
;
567 // excluding the heading '[' and tailing ']'
569 Length
= PtrBuf
- Buffer
- 1;
576 // Invalid line if the section name is null
579 return EFI_NOT_FOUND
;
582 if (!IsValidName((CHAR8
*)Buffer
+ 1, Length
)) {
583 return EFI_INVALID_PARAMETER
;
586 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
587 if (SectionItem
== NULL
) {
588 return EFI_OUT_OF_RESOURCES
;
591 SectionItem
->PtrSection
= NULL
;
592 SectionItem
->SecNameLen
= Length
;
593 SectionItem
->PtrEntry
= NULL
;
594 SectionItem
->PtrValue
= NULL
;
595 SectionItem
->PtrNext
= *SectionHead
;
596 *SectionHead
= SectionItem
;
599 // Add a trailing '\0'
601 SectionItem
->PtrSection
= AllocatePool (Length
+ 1);
602 if (SectionItem
->PtrSection
== NULL
) {
603 return EFI_OUT_OF_RESOURCES
;
607 // excluding the heading '['
609 CopyMem (SectionItem
->PtrSection
, Buffer
+ 1, Length
);
610 *(SectionItem
->PtrSection
+ Length
) = '\0';
616 Add new section entry and entry value into Section head.
618 @param[in] Buffer Section entry data buffer.
619 @param[in] BufferSize Size of section entry.
620 @param[in, out] SectionHead Section item head entry.
622 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
623 @retval EFI_SUCCESS Section entry is added.
624 @retval EFI_NOT_FOUND Section entry is not found.
625 @retval EFI_INVALID_PARAMETER Section entry is invalid.
632 IN OUT SECTION_ITEM
**SectionHead
636 SECTION_ITEM
*SectionItem
;
637 SECTION_ITEM
*PtrSection
;
642 Status
= EFI_SUCCESS
;
644 PtrEnd
= (UINT8
*) ((UINTN
)Buffer
+ BufferSize
- 1);
647 // First search for '='
649 while (PtrBuf
<= PtrEnd
) {
650 if (*PtrBuf
== '=') {
655 if (PtrBuf
> PtrEnd
) {
657 // Not found. Invalid line
659 return EFI_NOT_FOUND
;
661 if (PtrBuf
<= Buffer
) {
663 return EFI_NOT_FOUND
;
667 // excluding the tailing '='
669 Length
= PtrBuf
- Buffer
;
676 // Invalid line if the entry name is null
679 return EFI_NOT_FOUND
;
682 if (!IsValidName((CHAR8
*)Buffer
, Length
)) {
683 return EFI_INVALID_PARAMETER
;
687 // Omit this line if no section header has been found before
689 if (*SectionHead
== NULL
) {
692 PtrSection
= *SectionHead
;
694 SectionItem
= AllocatePool (sizeof (SECTION_ITEM
));
695 if (SectionItem
== NULL
) {
696 return EFI_OUT_OF_RESOURCES
;
699 SectionItem
->PtrSection
= NULL
;
700 SectionItem
->PtrEntry
= NULL
;
701 SectionItem
->PtrValue
= NULL
;
702 SectionItem
->SecNameLen
= PtrSection
->SecNameLen
;
703 SectionItem
->PtrNext
= *SectionHead
;
704 *SectionHead
= SectionItem
;
707 // SectionName, add a trailing '\0'
709 SectionItem
->PtrSection
= AllocatePool (PtrSection
->SecNameLen
+ 1);
710 if (SectionItem
->PtrSection
== NULL
) {
711 return EFI_OUT_OF_RESOURCES
;
713 CopyMem (SectionItem
->PtrSection
, PtrSection
->PtrSection
, PtrSection
->SecNameLen
+ 1);
716 // EntryName, add a trailing '\0'
718 SectionItem
->PtrEntry
= AllocatePool (Length
+ 1);
719 if (SectionItem
->PtrEntry
== NULL
) {
720 FreePool(SectionItem
->PtrSection
);
721 return EFI_OUT_OF_RESOURCES
;
723 CopyMem (SectionItem
->PtrEntry
, Buffer
, Length
);
724 *(SectionItem
->PtrEntry
+ Length
) = '\0';
727 // Next search for '#' or ';'
731 while (PtrBuf
<= PtrEnd
) {
732 if (*PtrBuf
== '#' || *PtrBuf
== ';') {
737 if (PtrBuf
<= Buffer
) {
739 FreePool(SectionItem
->PtrEntry
);
740 FreePool(SectionItem
->PtrSection
);
741 return EFI_NOT_FOUND
;
743 Length
= PtrBuf
- Buffer
;
750 // Invalid line if the entry value is null
753 FreePool(SectionItem
->PtrEntry
);
754 FreePool(SectionItem
->PtrSection
);
755 return EFI_NOT_FOUND
;
758 if (!IsValidValue((CHAR8
*)Buffer
, Length
)) {
759 FreePool(SectionItem
->PtrEntry
);
760 FreePool(SectionItem
->PtrSection
);
761 return EFI_INVALID_PARAMETER
;
765 // EntryValue, add a trailing '\0'
767 SectionItem
->PtrValue
= AllocatePool (Length
+ 1);
768 if (SectionItem
->PtrValue
== NULL
) {
769 FreePool(SectionItem
->PtrEntry
);
770 FreePool(SectionItem
->PtrSection
);
771 return EFI_OUT_OF_RESOURCES
;
773 CopyMem (SectionItem
->PtrValue
, Buffer
, Length
);
774 *(SectionItem
->PtrValue
+ Length
) = '\0';
780 Free all comment entry and section entry.
782 @param[in] Section Section entry list.
783 @param[in] Comment Comment entry list.
788 IN SECTION_ITEM
*Section
,
789 IN COMMENT_LINE
*Comment
792 SECTION_ITEM
*PtrSection
;
793 COMMENT_LINE
*PtrComment
;
795 while (Section
!= NULL
) {
796 PtrSection
= Section
;
797 Section
= Section
->PtrNext
;
798 if (PtrSection
->PtrEntry
!= NULL
) {
799 FreePool (PtrSection
->PtrEntry
);
801 if (PtrSection
->PtrSection
!= NULL
) {
802 FreePool (PtrSection
->PtrSection
);
804 if (PtrSection
->PtrValue
!= NULL
) {
805 FreePool (PtrSection
->PtrValue
);
807 FreePool (PtrSection
);
810 while (Comment
!= NULL
) {
811 PtrComment
= Comment
;
812 Comment
= Comment
->PtrNext
;
813 if (PtrComment
->PtrComment
!= NULL
) {
814 FreePool (PtrComment
->PtrComment
);
816 FreePool (PtrComment
);
823 Get section entry value.
825 @param[in] Section Section entry list.
826 @param[in] SectionName Section name.
827 @param[in] EntryName Section entry name.
828 @param[out] EntryValue Point to the got entry value.
830 @retval EFI_NOT_FOUND Section is not found.
831 @retval EFI_SUCCESS Section entry value is got.
835 UpdateGetProfileString (
836 IN SECTION_ITEM
*Section
,
837 IN CHAR8
*SectionName
,
839 OUT CHAR8
**EntryValue
844 while (Section
!= NULL
) {
845 if (AsciiStrCmp ((CONST CHAR8
*) Section
->PtrSection
, (CONST CHAR8
*) SectionName
) == 0) {
846 if (Section
->PtrEntry
!= NULL
) {
847 if (AsciiStrCmp ((CONST CHAR8
*) Section
->PtrEntry
, (CONST CHAR8
*) EntryName
) == 0) {
852 Section
= Section
->PtrNext
;
855 if (Section
== NULL
) {
856 return EFI_NOT_FOUND
;
859 *EntryValue
= Section
->PtrValue
;
865 Pre process config data buffer into Section entry list and Comment entry list.
867 @param[in] DataBuffer Config raw file buffer.
868 @param[in] BufferSize Size of raw buffer.
869 @param[in, out] SectionHead Pointer to the section entry list.
870 @param[in, out] CommentHead Pointer to the comment entry list.
872 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
873 @retval EFI_SUCCESS Config data buffer is preprocessed.
874 @retval EFI_NOT_FOUND Config data buffer is invalid, because Section or Entry is not found.
875 @retval EFI_INVALID_PARAMETER Config data buffer is invalid, because Section or Entry is invalid.
880 IN UINT8
*DataBuffer
,
882 IN OUT SECTION_ITEM
**SectionHead
,
883 IN OUT COMMENT_LINE
**CommentHead
897 BufferEnd
= (CHAR8
*) ( (UINTN
) DataBuffer
+ BufferSize
);
898 CurrentPtr
= (CHAR8
*) DataBuffer
;
899 MaxLineLength
= MAX_LINE_LENGTH
;
900 Status
= EFI_SUCCESS
;
902 PtrLine
= AllocatePool (MaxLineLength
);
903 if (PtrLine
== NULL
) {
904 return EFI_OUT_OF_RESOURCES
;
907 while (CurrentPtr
< BufferEnd
) {
909 SourceLength
= (UINTN
)BufferEnd
- (UINTN
)CurrentPtr
;
910 LineLength
= MaxLineLength
;
912 // With the assumption that line length is less than 512
913 // characters. Otherwise BUFFER_TOO_SMALL will be returned.
915 Status
= ProfileGetLine (
921 if (EFI_ERROR (Status
)) {
922 if (Status
== EFI_BUFFER_TOO_SMALL
) {
924 // If buffer too small, re-allocate the buffer according
925 // to the returned LineLength and try again.
929 PtrLine
= AllocatePool (LineLength
);
930 if (PtrLine
== NULL
) {
931 Status
= EFI_OUT_OF_RESOURCES
;
934 SourceLength
= LineLength
;
935 Status
= ProfileGetLine (
941 if (EFI_ERROR (Status
)) {
944 MaxLineLength
= LineLength
;
949 CurrentPtr
= (CHAR8
*) ( (UINTN
) CurrentPtr
+ LineLength
);
952 // Line got. Trim the line before processing it.
962 if (LineLength
== 0) {
966 if (PtrLine
[0] == '#' || PtrLine
[0] == ';') {
967 Status
= ProfileGetComments (
972 } else if (PtrLine
[0] == '[') {
973 Status
= ProfileGetSection (
979 Status
= ProfileGetEntry (
986 if (EFI_ERROR (Status
)) {
1000 Open an INI config file and return a context.
1002 @param[in] DataBuffer Config raw file buffer.
1003 @param[in] BufferSize Size of raw buffer.
1005 @return Config data buffer is opened and context is returned.
1006 @retval NULL No enough memory is allocated.
1007 @retval NULL Config data buffer is invalid.
1012 IN UINT8
*DataBuffer
,
1017 INI_PARSING_LIB_CONTEXT
*IniContext
;
1019 if (DataBuffer
== NULL
|| BufferSize
== 0) {
1023 IniContext
= AllocateZeroPool(sizeof(INI_PARSING_LIB_CONTEXT
));
1024 if (IniContext
== NULL
) {
1029 // First process the data buffer and get all sections and entries
1031 Status
= PreProcessDataFile (
1034 &IniContext
->SectionHead
,
1035 &IniContext
->CommentHead
1037 if (EFI_ERROR(Status
)) {
1038 FreePool(IniContext
);
1041 DEBUG_CODE_BEGIN ();
1042 DumpIniSection(IniContext
);
1048 Get section entry string value.
1050 @param[in] Context INI Config file context.
1051 @param[in] SectionName Section name.
1052 @param[in] EntryName Section entry name.
1053 @param[out] EntryValue Point to the got entry string value.
1055 @retval EFI_SUCCESS Section entry string value is got.
1056 @retval EFI_NOT_FOUND Section is not found.
1060 GetStringFromDataFile(
1062 IN CHAR8
*SectionName
,
1063 IN CHAR8
*EntryName
,
1064 OUT CHAR8
**EntryValue
1067 INI_PARSING_LIB_CONTEXT
*IniContext
;
1070 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| EntryValue
== NULL
) {
1071 return EFI_INVALID_PARAMETER
;
1074 IniContext
= Context
;
1077 Status
= UpdateGetProfileString (
1078 IniContext
->SectionHead
,
1087 Get section entry GUID value.
1089 @param[in] Context INI Config file context.
1090 @param[in] SectionName Section name.
1091 @param[in] EntryName Section entry name.
1092 @param[out] Guid Point to the got GUID value.
1094 @retval EFI_SUCCESS Section entry GUID value is got.
1095 @retval EFI_NOT_FOUND Section is not found.
1099 GetGuidFromDataFile (
1101 IN CHAR8
*SectionName
,
1102 IN CHAR8
*EntryName
,
1108 RETURN_STATUS RStatus
;
1110 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Guid
== NULL
) {
1111 return EFI_INVALID_PARAMETER
;
1114 Status
= GetStringFromDataFile(
1120 if (EFI_ERROR(Status
)) {
1121 return EFI_NOT_FOUND
;
1123 ASSERT (Value
!= NULL
);
1124 RStatus
= AsciiStrToGuid (Value
, Guid
);
1125 if (RETURN_ERROR (RStatus
) || (Value
[GUID_STRING_LENGTH
] != '\0')) {
1126 return EFI_NOT_FOUND
;
1132 Get section entry decimal UINTN value.
1134 @param[in] Context INI Config file context.
1135 @param[in] SectionName Section name.
1136 @param[in] EntryName Section entry name.
1137 @param[out] Data Point to the got decimal UINTN value.
1139 @retval EFI_SUCCESS Section entry decimal UINTN value is got.
1140 @retval EFI_NOT_FOUND Section is not found.
1144 GetDecimalUintnFromDataFile (
1146 IN CHAR8
*SectionName
,
1147 IN CHAR8
*EntryName
,
1154 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1155 return EFI_INVALID_PARAMETER
;
1158 Status
= GetStringFromDataFile(
1164 if (EFI_ERROR(Status
)) {
1165 return EFI_NOT_FOUND
;
1167 ASSERT (Value
!= NULL
);
1168 if (!IsValidDecimalString(Value
, AsciiStrLen(Value
))) {
1169 return EFI_NOT_FOUND
;
1171 *Data
= AsciiStrDecimalToUintn(Value
);
1176 Get section entry heximal UINTN value.
1178 @param[in] Context INI Config file context.
1179 @param[in] SectionName Section name.
1180 @param[in] EntryName Section entry name.
1181 @param[out] Data Point to the got heximal UINTN value.
1183 @retval EFI_SUCCESS Section entry heximal UINTN value is got.
1184 @retval EFI_NOT_FOUND Section is not found.
1188 GetHexUintnFromDataFile (
1190 IN CHAR8
*SectionName
,
1191 IN CHAR8
*EntryName
,
1198 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1199 return EFI_INVALID_PARAMETER
;
1202 Status
= GetStringFromDataFile(
1208 if (EFI_ERROR(Status
)) {
1209 return EFI_NOT_FOUND
;
1211 ASSERT (Value
!= NULL
);
1212 if (!IsValidHexString(Value
, AsciiStrLen(Value
))) {
1213 return EFI_NOT_FOUND
;
1215 *Data
= AsciiStrHexToUintn(Value
);
1220 Get section entry heximal UINT64 value.
1222 @param[in] Context INI Config file context.
1223 @param[in] SectionName Section name.
1224 @param[in] EntryName Section entry name.
1225 @param[out] Data Point to the got heximal UINT64 value.
1227 @retval EFI_SUCCESS Section entry heximal UINT64 value is got.
1228 @retval EFI_NOT_FOUND Section is not found.
1232 GetHexUint64FromDataFile (
1234 IN CHAR8
*SectionName
,
1235 IN CHAR8
*EntryName
,
1242 if (Context
== NULL
|| SectionName
== NULL
|| EntryName
== NULL
|| Data
== NULL
) {
1243 return EFI_INVALID_PARAMETER
;
1246 Status
= GetStringFromDataFile(
1252 if (EFI_ERROR(Status
)) {
1253 return EFI_NOT_FOUND
;
1255 ASSERT (Value
!= NULL
);
1256 if (!IsValidHexString(Value
, AsciiStrLen(Value
))) {
1257 return EFI_NOT_FOUND
;
1259 *Data
= AsciiStrHexToUint64(Value
);
1264 Close an INI config file and free the context.
1266 @param[in] Context INI Config file context.
1274 INI_PARSING_LIB_CONTEXT
*IniContext
;
1276 if (Context
== NULL
) {
1280 IniContext
= Context
;
1281 FreeAllList(IniContext
->SectionHead
, IniContext
->CommentHead
);