ReactOS 0.4.16-dev-1067-ge98bba2
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)
 
PLIST_ENTRY IniGetFileSectionListHead (VOID)
 
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 187 of file inifile.c.

188{
189 PINI_SECTION Section;
190
191 // Allocate a new section structure
192 Section = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
193 if (!Section)
194 {
195 return FALSE;
196 }
197
198 RtlZeroMemory(Section, sizeof(INI_SECTION));
199
200 // Allocate the section name buffer
201 Section->SectionName = FrLdrTempAlloc(strlen(SectionName) + sizeof(CHAR), TAG_INI_NAME);
202 if (!Section->SectionName)
203 {
205 return FALSE;
206 }
207
208 // Get the section name
209 strcpy(Section->SectionName, SectionName);
210 InitializeListHead(&Section->SectionItemList);
211
212 // Add it to the section list head
215
216 *SectionId = (ULONG_PTR)Section;
217
218 return TRUE;
219}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: heap.c:553
PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: heap.c:545
#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
strcpy
Definition: string.h:131
LIST_ENTRY ListEntry
Definition: inicache.h:21
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char CHAR
Definition: xmlstorage.h:175

◆ IniAddSettingValueToSection()

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

Definition at line 260 of file inifile.c.

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

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

◆ IniCleanup()

VOID IniCleanup ( VOID  )

Definition at line 243 of file inifile.c.

244{
245 PLIST_ENTRY ListEntry;
246 PINI_SECTION Section;
247
248 // Loop while there are sections
250 {
251 // Remove the section
253 Section = CONTAINING_RECORD(ListEntry, INI_SECTION, ListEntry);
254
255 // Free it
256 IniFreeSection(Section);
257 }
258}
#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:221
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 221 of file inifile.c.

222{
223 PLIST_ENTRY ListEntry;
224 PINI_SECTION_ITEM SectionItem;
225
226 // Loop while there are section items
227 while (!IsListEmpty(&Section->SectionItemList))
228 {
229 // Remove the section item
230 ListEntry = RemoveHeadList(&Section->SectionItemList);
231 SectionItem = CONTAINING_RECORD(ListEntry, INI_SECTION_ITEM, ListEntry);
232
233 // Free it
234 FrLdrTempFree(SectionItem->ItemName, TAG_INI_NAME);
237 }
238
239 FrLdrTempFree(Section->SectionName, TAG_INI_NAME);
241}

Referenced by IniCleanup().

◆ IniGetFileSectionListHead()

PLIST_ENTRY IniGetFileSectionListHead ( VOID  )

Definition at line 25 of file inifile.c.

26{
28}

Referenced by LoadSettings().

◆ IniGetNumSectionItems()

ULONG IniGetNumSectionItems ( ULONG_PTR  SectionId)

Definition at line 60 of file inifile.c.

61{
62 PINI_SECTION Section = (PINI_SECTION)SectionId;
63
64 TRACE("IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
65 TRACE("IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
66
67 return Section->SectionItemCount;
68}
#define TRACE(s)
Definition: solgame.cpp:4

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

◆ IniGetSectionSettingNameSize()

ULONG IniGetSectionSettingNameSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 95 of file inifile.c.

96{
97 PINI_SECTION_ITEM SectionItem;
98
99 // Retrieve requested setting
100 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
101 if (!SectionItem)
102 return 0;
103
104 // Return the size of the string plus 1 for the null-terminator
105 return (ULONG)(strlen(SectionItem->ItemName) + 1);
106}
PINI_SECTION_ITEM IniGetSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber)
Definition: inifile.c:70
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 108 of file inifile.c.

109{
110 PINI_SECTION_ITEM SectionItem;
111
112 // Retrieve requested setting
113 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
114 if (!SectionItem)
115 return 0;
116
117 // Return the size of the string plus 1 for the null-terminator
118 return (ULONG)(strlen(SectionItem->ItemValue) + 1);
119}

Referenced by BuildArgvForOsLoader(), and UiShowMessageBoxesInSection().

◆ IniGetSettingByNumber()

PINI_SECTION_ITEM IniGetSettingByNumber ( ULONG_PTR  SectionId,
ULONG  SettingNumber 
)

Definition at line 70 of file inifile.c.

71{
72 PINI_SECTION Section = (PINI_SECTION)SectionId;
74 PINI_SECTION_ITEM SectionItem;
75
76 // Loop through each section item and find the one we want
77 for (Entry = Section->SectionItemList.Flink;
78 Entry != &Section->SectionItemList;
79 Entry = Entry->Flink)
80 {
81 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
82
83 // Check to see if this is the setting we want
84 if (SettingNumber == 0)
85 {
86 return SectionItem;
87 }
88
89 // Nope, keep going
90 SettingNumber--;
91 }
92 return NULL;
93}
#define NULL
Definition: types.h:112
base of all file and directory entries
Definition: entries.h:83

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

◆ IniModifySettingValue()

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

Definition at line 301 of file inifile.c.

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

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

◆ IniOpenSection()

BOOLEAN IniOpenSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 30 of file inifile.c.

31{
33 PINI_SECTION Section;
34
35 TRACE("IniOpenSection() SectionName = %s\n", SectionName);
36
37 // Loop through each section and find the one we want
40 Entry = Entry->Flink)
41 {
42 Section = CONTAINING_RECORD(Entry, INI_SECTION, ListEntry);
43
44 // Compare against the section name
45 if (_stricmp(SectionName, Section->SectionName) == 0)
46 {
47 // We found it
48 if (SectionId)
49 *SectionId = (ULONG_PTR)Section;
50 TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
51 return TRUE;
52 }
53 }
54
55 TRACE("IniOpenSection() Section not found.\n");
56
57 return FALSE;
58}
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121

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

◆ IniReadSettingByName()

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

Definition at line 154 of file inifile.c.

155{
156 PINI_SECTION Section = (PINI_SECTION)SectionId;
158 PINI_SECTION_ITEM SectionItem;
159
160 TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
161
162 // Loop through each section item and find the one we want
163 for (Entry = Section->SectionItemList.Flink;
164 Entry != &Section->SectionItemList;
165 Entry = Entry->Flink)
166 {
167 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
168
169 // Check to see if this is the setting we want
170 if (_stricmp(SettingName, SectionItem->ItemName) == 0)
171 {
172 TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
173 TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
174
175 strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
176 Buffer[BufferSize - 1] = '\0';
177
178 return TRUE;
179 }
180 }
181
182 WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
183
184 return FALSE;
185}
#define WARN(fmt,...)
Definition: precomp.h:61
Definition: bufpool.h:45
strncpy
Definition: string.h:335
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by EditCustomBootReactOS(), GetOSLoadingMethod(), InitOperatingSystemList(), LoadSettings(), and UiInitialize().

◆ IniReadSettingByNumber()

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

Definition at line 121 of file inifile.c.

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

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