ReactOS 0.4.15-dev-6056-gb29b268
inifile.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for inifile.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (INIFILE)
 
BOOLEAN IniOpenSection (PCSTR SectionName, ULONG_PTR *SectionId)
 
ULONG IniGetNumSectionItems (ULONG_PTR SectionId)
 
PINI_SECTION_ITEM IniGetSettingByNumber (ULONG_PTR SectionId, ULONG SettingNumber)
 
ULONG IniGetSectionSettingNameSize (ULONG_PTR SectionId, ULONG SettingIndex)
 
ULONG IniGetSectionSettingValueSize (ULONG_PTR SectionId, ULONG SettingIndex)
 
BOOLEAN IniReadSettingByNumber (ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
 
BOOLEAN IniReadSettingByName (ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
 
BOOLEAN IniAddSection (PCSTR SectionName, ULONG_PTR *SectionId)
 
VOID IniFreeSection (PINI_SECTION Section)
 
VOID IniCleanup (VOID)
 
BOOLEAN IniAddSettingValueToSection (ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
 
BOOLEAN IniModifySettingValue (ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( INIFILE  )

◆ IniAddSection()

BOOLEAN IniAddSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 179 of file inifile.c.

180{
181 PINI_SECTION Section;
182
183 // Allocate a new section structure
184 Section = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
185 if (!Section)
186 {
187 return FALSE;
188 }
189
190 RtlZeroMemory(Section, sizeof(INI_SECTION));
191
192 // Allocate the section name buffer
193 Section->SectionName = FrLdrTempAlloc(strlen(SectionName) + sizeof(CHAR), TAG_INI_NAME);
194 if (!Section->SectionName)
195 {
197 return FALSE;
198 }
199
200 // Get the section name
201 strcpy(Section->SectionName, SectionName);
203
204 // Add it to the section list head
207
208 *SectionId = (ULONG_PTR)Section;
209
210 return TRUE;
211}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define InsertHeadList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG IniFileSectionCount
Definition: parse.c:27
#define TAG_INI_SECTION
Definition: inifile.h:25
#define TAG_INI_NAME
Definition: inifile.h:27
LIST_ENTRY IniFileSectionListHead
Definition: parse.c:25
LIST_ENTRY ListEntry
Definition: inifile.h:48
LIST_ENTRY SectionItemList
Definition: inifile.h:51
PCHAR SectionName
Definition: inifile.h:49
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char CHAR
Definition: xmlstorage.h:175

Referenced by EditCustomBootReactOS(), and InitOperatingSystemList().

◆ IniAddSettingValueToSection()

BOOLEAN IniAddSettingValueToSection ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCSTR  SettingValue 
)

Definition at line 252 of file inifile.c.

253{
254 PINI_SECTION Section = (PINI_SECTION)SectionId;
255 PINI_SECTION_ITEM SectionItem;
256
257 // Allocate a new item structure
259 if (!SectionItem)
260 {
261 return FALSE;
262 }
263
264 RtlZeroMemory(SectionItem, sizeof(INI_SECTION_ITEM));
265
266 // Allocate the setting name buffer
267 SectionItem->ItemName = FrLdrTempAlloc(strlen(SettingName) + 1, TAG_INI_NAME);
268 if (!SectionItem->ItemName)
269 {
271 return FALSE;
272 }
273
274 // Allocate the setting value buffer
275 SectionItem->ItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
276 if (!SectionItem->ItemValue)
277 {
278 FrLdrTempFree(SectionItem->ItemName, TAG_INI_NAME);
280 return FALSE;
281 }
282
283 strcpy(SectionItem->ItemName, SettingName);
284 strcpy(SectionItem->ItemValue, SettingValue);
285
286 // Add it to the current section
287 Section->SectionItemCount++;
288 InsertTailList(&Section->SectionItemList, &SectionItem->ListEntry);
289
290 return TRUE;
291}
#define InsertTailList(ListHead, Entry)
#define TAG_INI_VALUE
Definition: inifile.h:28
#define TAG_INI_SECTION_ITEM
Definition: inifile.h:26
struct INI_SECTION * PINI_SECTION
LIST_ENTRY ListEntry
Definition: inifile.h:35
PCHAR ItemName
Definition: inifile.h:36
PCHAR ItemValue
Definition: inifile.h:37
ULONG SectionItemCount
Definition: inifile.h:50

Referenced by EditCustomBootReactOS(), IniModifySettingValue(), and InitOperatingSystemList().

◆ IniCleanup()

VOID IniCleanup ( VOID  )

Definition at line 235 of file inifile.c.

236{
237 PLIST_ENTRY ListEntry;
238 PINI_SECTION Section;
239
240 // Loop while there are sections
242 {
243 // Remove the section
245 Section = CONTAINING_RECORD(ListEntry, INI_SECTION, ListEntry);
246
247 // Free it
248 IniFreeSection(Section);
249 }
250}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
VOID IniFreeSection(PINI_SECTION Section)
Definition: inifile.c:213
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by LoadAndBootWindowsCommon(), and RunLoader().

◆ IniFreeSection()

VOID IniFreeSection ( PINI_SECTION  Section)

Definition at line 213 of file inifile.c.

214{
215 PLIST_ENTRY ListEntry;
216 PINI_SECTION_ITEM SectionItem;
217
218 // Loop while there are section items
219 while (!IsListEmpty(&Section->SectionItemList))
220 {
221 // Remove the section item
222 ListEntry = RemoveHeadList(&Section->SectionItemList);
223 SectionItem = CONTAINING_RECORD(ListEntry, INI_SECTION_ITEM, ListEntry);
224
225 // Free it
226 FrLdrTempFree(SectionItem->ItemName, TAG_INI_NAME);
229 }
230
233}

Referenced by IniCleanup().

◆ IniGetNumSectionItems()

ULONG IniGetNumSectionItems ( ULONG_PTR  SectionId)

Definition at line 54 of file inifile.c.

55{
56 PINI_SECTION Section = (PINI_SECTION)SectionId;
57
58 TRACE("IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
59 TRACE("IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
60
61 return Section->SectionItemCount;
62}
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by BuildArgvForOsLoader(), InitOperatingSystemList(), and UiShowMessageBoxesInSection().

◆ IniGetSectionSettingNameSize()

ULONG IniGetSectionSettingNameSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 88 of file inifile.c.

89{
90 PINI_SECTION_ITEM SectionItem;
91
92 // Retrieve requested setting
93 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
94 if (!SectionItem)
95 return 0;
96
97 // Return the size of the string plus 1 for the null-terminator
98 return (ULONG)(strlen(SectionItem->ItemName) + 1);
99}
PINI_SECTION_ITEM IniGetSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber)
Definition: inifile.c:64
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFUSBINTERFACE _In_ UCHAR SettingIndex
Definition: wdfusb.h:2303

Referenced by BuildArgvForOsLoader().

◆ IniGetSectionSettingValueSize()

ULONG IniGetSectionSettingValueSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 101 of file inifile.c.

102{
103 PINI_SECTION_ITEM SectionItem;
104
105 // Retrieve requested setting
106 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
107 if (!SectionItem)
108 return 0;
109
110 // Return the size of the string plus 1 for the null-terminator
111 return (ULONG)(strlen(SectionItem->ItemValue) + 1);
112}

Referenced by BuildArgvForOsLoader(), and UiShowMessageBoxesInSection().

◆ IniGetSettingByNumber()

PINI_SECTION_ITEM IniGetSettingByNumber ( ULONG_PTR  SectionId,
ULONG  SettingNumber 
)

Definition at line 64 of file inifile.c.

65{
66 PINI_SECTION Section = (PINI_SECTION)SectionId;
67 PINI_SECTION_ITEM SectionItem;
68
69 // Loop through each section item and find the one they want
70 SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
71 while (&SectionItem->ListEntry != &Section->SectionItemList)
72 {
73 // Check to see if this is the setting they want
74 if (SettingNumber == 0)
75 {
76 return SectionItem;
77 }
78
79 // Nope, keep going
80 SettingNumber--;
81
82 // Get the next section item in the list
83 SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
84 }
85 return NULL;
86}
#define NULL
Definition: types.h:112
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121

Referenced by IniGetSectionSettingNameSize(), IniGetSectionSettingValueSize(), and IniReadSettingByNumber().

◆ IniModifySettingValue()

BOOLEAN IniModifySettingValue ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCSTR  SettingValue 
)

Definition at line 293 of file inifile.c.

294{
295 PINI_SECTION Section = (PINI_SECTION)SectionId;
296 PINI_SECTION_ITEM SectionItem;
297 PCHAR NewItemValue;
298
299 // Loop through each section item and find the one we want
300 SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
301 while (&SectionItem->ListEntry != &Section->SectionItemList)
302 {
303 // Check to see if this is the setting we want
304 if (_stricmp(SectionItem->ItemName, SettingName) == 0)
305 {
306 break;
307 }
308
309 // Nope, keep going
310 // Get the next section item in the list
311 SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
312 }
313 // If the section item does not exist, create it
314 if (&SectionItem->ListEntry == &Section->SectionItemList)
315 {
316 return IniAddSettingValueToSection(SectionId, SettingName, SettingValue);
317 }
318
319 // Reallocate the new setting value buffer
320 NewItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
321 if (!NewItemValue)
322 {
323 // We failed, bail out
324 return FALSE;
325 }
327 SectionItem->ItemValue = NewItemValue;
328
329 strcpy(SectionItem->ItemValue, SettingValue);
330
331 return TRUE;
332}
#define _stricmp
Definition: cat.c:22
BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
Definition: inifile.c:252
char * PCHAR
Definition: typedefs.h:51

Referenced by EditCustomBootReactOS(), and InitOperatingSystemList().

◆ IniOpenSection()

BOOLEAN IniOpenSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 25 of file inifile.c.

26{
27 PINI_SECTION Section;
28
29 TRACE("IniOpenSection() SectionName = %s\n", SectionName);
30
31 // Loop through each section and find the one they want
33 while (&Section->ListEntry != &IniFileSectionListHead)
34 {
35 // Compare against the section name
36 if (_stricmp(SectionName, Section->SectionName) == 0)
37 {
38 // We found it
39 if (SectionId)
40 *SectionId = (ULONG_PTR)Section;
41 TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
42 return TRUE;
43 }
44
45 // Get the next section in the list
46 Section = CONTAINING_RECORD(Section->ListEntry.Flink, INI_SECTION, ListEntry);
47 }
48
49 TRACE("IniOpenSection() Section not found.\n");
50
51 return FALSE;
52}

Referenced by InitOperatingSystemList(), RunLoader(), and UiInitialize().

◆ IniReadSettingByName()

BOOLEAN IniReadSettingByName ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCHAR  Buffer,
ULONG  BufferSize 
)

Definition at line 147 of file inifile.c.

148{
149 PINI_SECTION Section = (PINI_SECTION)SectionId;
150 PINI_SECTION_ITEM SectionItem;
151
152 TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
153
154 // Loop through each section item and find the one they want
155 SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
156 while (&SectionItem->ListEntry != &Section->SectionItemList)
157 {
158 // Check to see if this is the setting they want
159 if (_stricmp(SettingName, SectionItem->ItemName) == 0)
160 {
161 TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
162 TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
163
164 strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
165 Buffer[BufferSize - 1] = '\0';
166
167 return TRUE;
168 }
169
170 // Get the next section item in the list
171 SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
172 }
173
174 WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
175
176 return FALSE;
177}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define WARN(fmt,...)
Definition: debug.h:112
Definition: bufpool.h:45
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by EditCustomBootReactOS(), GetTimeOut(), InitOperatingSystemList(), LoadOperatingSystem(), and UiInitialize().

◆ IniReadSettingByNumber()

BOOLEAN IniReadSettingByNumber ( ULONG_PTR  SectionId,
ULONG  SettingNumber,
PCHAR  SettingName,
ULONG  NameSize,
PCHAR  SettingValue,
ULONG  ValueSize 
)

Definition at line 114 of file inifile.c.

115{
116 PINI_SECTION_ITEM SectionItem;
117 TRACE(".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
118
119 TRACE("IniReadSettingByNumber() SectionId = 0x%x\n", SectionId);
120
121 // Retrieve requested setting
122 SectionItem = IniGetSettingByNumber(SectionId, SettingNumber);
123 if (!SectionItem)
124 {
125 TRACE("IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber);
126 return FALSE;
127 }
128
129 TRACE("IniReadSettingByNumber() Setting number %d found.\n", SettingNumber);
130 TRACE("IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName);
131 TRACE("IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue);
132
133 TRACE("1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
134 TRACE("2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
135 strncpy(SettingName, SectionItem->ItemName, NameSize - 1);
136 SettingName[NameSize - 1] = '\0';
137 TRACE("3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
138 strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1);
139 SettingValue[ValueSize - 1] = '\0';
140 TRACE("4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
141 DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize);
142 DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize);
143
144 return TRUE;
145}
#define DbgDumpBuffer(mask, buf, len)
Definition: debug.h:119
#define DPRINT_INIFILE
Definition: debug.h:27

Referenced by BuildArgvForOsLoader(), InitOperatingSystemList(), and UiShowMessageBoxesInSection().