ReactOS 0.4.15-dev-8145-ga541a46
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 182 of file inifile.c.

183{
184 PINI_SECTION Section;
185
186 // Allocate a new section structure
187 Section = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
188 if (!Section)
189 {
190 return FALSE;
191 }
192
193 RtlZeroMemory(Section, sizeof(INI_SECTION));
194
195 // Allocate the section name buffer
196 Section->SectionName = FrLdrTempAlloc(strlen(SectionName) + sizeof(CHAR), TAG_INI_NAME);
197 if (!Section->SectionName)
198 {
200 return FALSE;
201 }
202
203 // Get the section name
204 strcpy(Section->SectionName, SectionName);
205 InitializeListHead(&Section->SectionItemList);
206
207 // Add it to the section list head
210
211 *SectionId = (ULONG_PTR)Section;
212
213 return TRUE;
214}
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: 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 255 of file inifile.c.

256{
257 PINI_SECTION Section = (PINI_SECTION)SectionId;
258 PINI_SECTION_ITEM SectionItem;
259
260 // Allocate a new item structure
262 if (!SectionItem)
263 {
264 return FALSE;
265 }
266
267 RtlZeroMemory(SectionItem, sizeof(INI_SECTION_ITEM));
268
269 // Allocate the setting name buffer
270 SectionItem->ItemName = FrLdrTempAlloc(strlen(SettingName) + 1, TAG_INI_NAME);
271 if (!SectionItem->ItemName)
272 {
274 return FALSE;
275 }
276
277 // Allocate the setting value buffer
278 SectionItem->ItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
279 if (!SectionItem->ItemValue)
280 {
281 FrLdrTempFree(SectionItem->ItemName, TAG_INI_NAME);
283 return FALSE;
284 }
285
286 strcpy(SectionItem->ItemName, SettingName);
287 strcpy(SectionItem->ItemValue, SettingValue);
288
289 // Add it to the current section
290 Section->SectionItemCount++;
291 InsertTailList(&Section->SectionItemList, &SectionItem->ListEntry);
292
293 return TRUE;
294}
#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 238 of file inifile.c.

239{
240 PLIST_ENTRY ListEntry;
241 PINI_SECTION Section;
242
243 // Loop while there are sections
245 {
246 // Remove the section
248 Section = CONTAINING_RECORD(ListEntry, INI_SECTION, ListEntry);
249
250 // Free it
251 IniFreeSection(Section);
252 }
253}
#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:216
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 216 of file inifile.c.

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

Referenced by IniCleanup().

◆ IniGetNumSectionItems()

ULONG IniGetNumSectionItems ( ULONG_PTR  SectionId)

Definition at line 55 of file inifile.c.

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

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

◆ IniGetSectionSettingNameSize()

ULONG IniGetSectionSettingNameSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 90 of file inifile.c.

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

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

Referenced by BuildArgvForOsLoader(), and UiShowMessageBoxesInSection().

◆ IniGetSettingByNumber()

PINI_SECTION_ITEM IniGetSettingByNumber ( ULONG_PTR  SectionId,
ULONG  SettingNumber 
)

Definition at line 65 of file inifile.c.

66{
67 PINI_SECTION Section = (PINI_SECTION)SectionId;
69 PINI_SECTION_ITEM SectionItem;
70
71 // Loop through each section item and find the one we want
72 for (Entry = Section->SectionItemList.Flink;
73 Entry != &Section->SectionItemList;
74 Entry = Entry->Flink)
75 {
76 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
77
78 // Check to see if this is the setting we want
79 if (SettingNumber == 0)
80 {
81 return SectionItem;
82 }
83
84 // Nope, keep going
85 SettingNumber--;
86 }
87 return NULL;
88}
#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 296 of file inifile.c.

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

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

◆ IniOpenSection()

BOOLEAN IniOpenSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 25 of file inifile.c.

26{
28 PINI_SECTION Section;
29
30 TRACE("IniOpenSection() SectionName = %s\n", SectionName);
31
32 // Loop through each section and find the one we want
35 Entry = Entry->Flink)
36 {
37 Section = CONTAINING_RECORD(Entry, INI_SECTION, ListEntry);
38
39 // Compare against the section name
40 if (_stricmp(SectionName, Section->SectionName) == 0)
41 {
42 // We found it
43 if (SectionId)
44 *SectionId = (ULONG_PTR)Section;
45 TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
46 return TRUE;
47 }
48 }
49
50 TRACE("IniOpenSection() Section not found.\n");
51
52 return FALSE;
53}
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 149 of file inifile.c.

150{
151 PINI_SECTION Section = (PINI_SECTION)SectionId;
153 PINI_SECTION_ITEM SectionItem;
154
155 TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
156
157 // Loop through each section item and find the one we want
158 for (Entry = Section->SectionItemList.Flink;
159 Entry != &Section->SectionItemList;
160 Entry = Entry->Flink)
161 {
162 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
163
164 // Check to see if this is the setting we want
165 if (_stricmp(SettingName, SectionItem->ItemName) == 0)
166 {
167 TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
168 TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
169
170 strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
171 Buffer[BufferSize - 1] = '\0';
172
173 return TRUE;
174 }
175 }
176
177 WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
178
179 return FALSE;
180}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define WARN(fmt,...)
Definition: debug.h:115
Definition: bufpool.h:45
_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 116 of file inifile.c.

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

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