ReactOS 0.4.15-dev-7988-g06a3508
infhost.h File Reference
#include "infcommon.h"
Include dependency graph for infhost.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int InfHostOpenBufferedFile (PHINF InfHandle, void *Buffer, ULONG BufferSize, LANGID LanguageId, ULONG *ErrorLine)
 
int InfHostOpenFile (PHINF InfHandle, const CHAR *FileName, LANGID LanguageId, ULONG *ErrorLine)
 
int InfHostWriteFile (HINF InfHandle, const CHAR *FileName, const CHAR *HeaderComment)
 
void InfHostCloseFile (HINF InfHandle)
 
int InfHostFindFirstLine (HINF InfHandle, const WCHAR *Section, const WCHAR *Key, PINFCONTEXT *Context)
 
int InfHostFindNextLine (PINFCONTEXT ContextIn, PINFCONTEXT ContextOut)
 
int InfHostFindFirstMatchLine (PINFCONTEXT ContextIn, const WCHAR *Key, PINFCONTEXT ContextOut)
 
int InfHostFindNextMatchLine (PINFCONTEXT ContextIn, const WCHAR *Key, PINFCONTEXT ContextOut)
 
LONG InfHostGetLineCount (HINF InfHandle, const WCHAR *Section)
 
LONG InfHostGetFieldCount (PINFCONTEXT Context)
 
int InfHostGetBinaryField (PINFCONTEXT Context, ULONG FieldIndex, UCHAR *ReturnBuffer, ULONG ReturnBufferSize, ULONG *RequiredSize)
 
int InfHostGetIntField (PINFCONTEXT Context, ULONG FieldIndex, INT *IntegerValue)
 
int InfHostGetMultiSzField (PINFCONTEXT Context, ULONG FieldIndex, WCHAR *ReturnBuffer, ULONG ReturnBufferSize, ULONG *RequiredSize)
 
int InfHostGetStringField (PINFCONTEXT Context, ULONG FieldIndex, WCHAR *ReturnBuffer, ULONG ReturnBufferSize, ULONG *RequiredSize)
 
int InfHostGetData (PINFCONTEXT Context, WCHAR **Key, WCHAR **Data)
 
int InfHostGetDataField (PINFCONTEXT Context, ULONG FieldIndex, WCHAR **Data)
 
int InfHostFindOrAddSection (HINF InfHandle, const WCHAR *Section, PINFCONTEXT *Context)
 
int InfHostAddLine (PINFCONTEXT Context, const WCHAR *Key)
 
int InfHostAddField (PINFCONTEXT Context, const WCHAR *Data)
 
void InfHostFreeContext (PINFCONTEXT Context)
 

Function Documentation

◆ InfHostAddField()

int InfHostAddField ( PINFCONTEXT  Context,
const WCHAR Data 
)

Definition at line 99 of file infhostput.c.

100{
102
104 if (INF_SUCCESS(Status))
105 {
106 return 0;
107 }
108 else
109 {
110 errno = Status;
111 return -1;
112 }
113}
#define INF_SUCCESS(x)
Definition: builddep.h:82
Status
Definition: gdiplustypes.h:25
int INFSTATUS
Definition: infpriv.h:77
INFSTATUS InfpAddField(PINFCONTEXT Context, PCWSTR Data)
Definition: infput.c:254
#define errno
Definition: errno.h:18

◆ InfHostAddLine()

int InfHostAddLine ( PINFCONTEXT  Context,
const WCHAR Key 
)

Definition at line 82 of file infhostput.c.

83{
85
88 {
89 return 0;
90 }
91 else
92 {
93 errno = Status;
94 return -1;
95 }
96}
INFSTATUS InfpAddLineWithKey(PINFCONTEXT Context, PCWSTR Key)
Definition: infput.c:224

◆ InfHostCloseFile()

void InfHostCloseFile ( HINF  InfHandle)

Definition at line 283 of file infhostgen.c.

284{
286
287 Cache = (PINFCACHE)InfHandle;
288
289 if (Cache == NULL)
290 {
291 return;
292 }
293
294 while (Cache->FirstSection != NULL)
295 {
296 Cache->FirstSection = InfpFreeSection(Cache->FirstSection);
297 }
298 Cache->LastSection = NULL;
299
300 FREE(Cache);
301}
#define FREE(ptr, size)
Definition: auth_des.c:64
#define NULL
Definition: types.h:112
PINFCACHESECTION InfpFreeSection(PINFCACHESECTION Section)
Definition: infcore.c:119
struct _INFCACHE * PINFCACHE
Definition: fatfs.h:173

Referenced by ImportRegistryFile().

◆ InfHostFindFirstLine()

int InfHostFindFirstLine ( HINF  InfHandle,
const WCHAR Section,
const WCHAR Key,
PINFCONTEXT Context 
)

Definition at line 18 of file infhostget.c.

22{
24
25 Status = InfpFindFirstLine(InfHandle, Section, Key, Context);
27 {
28 return 0;
29 }
30 else
31 {
32 errno = Status;
33 return -1;
34 }
35}
INFSTATUS InfpFindFirstLine(PINFCACHE Cache, PCWSTR Section, PCWSTR Key, PINFCONTEXT *Context)
Definition: infget.c:173

Referenced by registry_callback().

◆ InfHostFindFirstMatchLine()

int InfHostFindFirstMatchLine ( PINFCONTEXT  ContextIn,
const WCHAR Key,
PINFCONTEXT  ContextOut 
)

Definition at line 58 of file infhostget.c.

61{
63
64 Status = InfpFindFirstMatchLine(ContextIn, Key, ContextOut);
66 {
67 return 0;
68 }
69 else
70 {
71 errno = Status;
72 return -1;
73 }
74}
INFSTATUS InfpFindFirstMatchLine(PINFCONTEXT ContextIn, PCWSTR Key, PINFCONTEXT ContextOut)
Definition: infget.c:251

◆ InfHostFindNextLine()

int InfHostFindNextLine ( PINFCONTEXT  ContextIn,
PINFCONTEXT  ContextOut 
)

Definition at line 39 of file infhostget.c.

41{
43
44 Status = InfpFindNextLine(ContextIn, ContextOut);
46 {
47 return 0;
48 }
49 else
50 {
51 errno = Status;
52 return -1;
53 }
54}
INFSTATUS InfpFindNextLine(PINFCONTEXT ContextIn, PINFCONTEXT ContextOut)
Definition: infget.c:224

Referenced by registry_callback().

◆ InfHostFindNextMatchLine()

int InfHostFindNextMatchLine ( PINFCONTEXT  ContextIn,
const WCHAR Key,
PINFCONTEXT  ContextOut 
)

Definition at line 78 of file infhostget.c.

81{
83
84 Status = InfpFindNextMatchLine(ContextIn, Key, ContextOut);
86 {
87 return 0;
88 }
89 else
90 {
91 errno = Status;
92 return -1;
93 }
94}
INFSTATUS InfpFindNextMatchLine(PINFCONTEXT ContextIn, PCWSTR Key, PINFCONTEXT ContextOut)
Definition: infget.c:289

◆ InfHostFindOrAddSection()

int InfHostFindOrAddSection ( HINF  InfHandle,
const WCHAR Section,
PINFCONTEXT Context 
)

Definition at line 63 of file infhostput.c.

66{
68
69 Status = InfpFindOrAddSection((PINFCACHE) InfHandle, Section, Context);
71 {
72 return 0;
73 }
74 else
75 {
76 errno = Status;
77 return -1;
78 }
79}
INFSTATUS InfpFindOrAddSection(PINFCACHE Cache, PCWSTR Section, PINFCONTEXT *Context)
Definition: infput.c:190

◆ InfHostFreeContext()

void InfHostFreeContext ( PINFCONTEXT  Context)

Definition at line 244 of file infhostget.c.

245{
247}
VOID InfpFreeContext(PINFCONTEXT Context)
Definition: infget.c:679

Referenced by registry_callback().

◆ InfHostGetBinaryField()

int InfHostGetBinaryField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
UCHAR ReturnBuffer,
ULONG  ReturnBufferSize,
ULONG RequiredSize 
)

Definition at line 116 of file infhostget.c.

121{
123
126 if (INF_SUCCESS(Status))
127 {
128 return 0;
129 }
130 else
131 {
132 errno = Status;
133 return -1;
134 }
135}
INFSTATUS InfpGetBinaryField(PINFCONTEXT Context, ULONG FieldIndex, PUCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infget.c:377
_In_ DWORD FieldIndex
Definition: setupapi.h:1895
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1897
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439

Referenced by do_reg_operation().

◆ InfHostGetData()

int InfHostGetData ( PINFCONTEXT  Context,
WCHAR **  Key,
WCHAR **  Data 
)

Definition at line 205 of file infhostget.c.

208{
210
212 if (INF_SUCCESS(Status))
213 {
214 return 0;
215 }
216 else
217 {
218 errno = Status;
219 return -1;
220 }
221}
INFSTATUS InfpGetData(PINFCONTEXT Context, PWCHAR *Key, PWCHAR *Data)
Definition: infget.c:610

◆ InfHostGetDataField()

int InfHostGetDataField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
WCHAR **  Data 
)

Definition at line 225 of file infhostget.c.

228{
230
232 if (INF_SUCCESS(Status))
233 {
234 return 0;
235 }
236 else
237 {
238 errno = Status;
239 return -1;
240 }
241}
INFSTATUS InfpGetDataField(PINFCONTEXT Context, ULONG FieldIndex, PWCHAR *Data)
Definition: infget.c:643

◆ InfHostGetFieldCount()

LONG InfHostGetFieldCount ( PINFCONTEXT  Context)

Definition at line 109 of file infhostget.c.

110{
112}
LONG InfpGetFieldCount(PINFCONTEXT Context)
Definition: infget.c:365

Referenced by do_reg_operation().

◆ InfHostGetIntField()

int InfHostGetIntField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
INT IntegerValue 
)

Definition at line 139 of file infhostget.c.

142{
144
145 Status = InfpGetIntField(Context, FieldIndex, IntegerValue);
146 if (INF_SUCCESS(Status))
147 {
148 return 0;
149 }
150 else
151 {
152 errno = Status;
153 return -1;
154 }
155}
INFSTATUS InfpGetIntField(PINFCONTEXT Context, ULONG FieldIndex, INT *IntegerValue)
Definition: infget.c:433

Referenced by registry_callback().

◆ InfHostGetLineCount()

LONG InfHostGetLineCount ( HINF  InfHandle,
const WCHAR Section 
)

◆ InfHostGetMultiSzField()

int InfHostGetMultiSzField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
WCHAR ReturnBuffer,
ULONG  ReturnBufferSize,
ULONG RequiredSize 
)

Definition at line 159 of file infhostget.c.

164{
166
169 if (INF_SUCCESS(Status))
170 {
171 return 0;
172 }
173 else
174 {
175 errno = Status;
176 return -1;
177 }
178}
INFSTATUS InfpGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infget.c:476

Referenced by do_reg_operation().

◆ InfHostGetStringField()

int InfHostGetStringField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
WCHAR ReturnBuffer,
ULONG  ReturnBufferSize,
ULONG RequiredSize 
)

Definition at line 182 of file infhostget.c.

187{
189
192 if (INF_SUCCESS(Status))
193 {
194 return 0;
195 }
196 else
197 {
198 errno = Status;
199 return -1;
200 }
201}
INFSTATUS InfpGetStringField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infget.c:545

Referenced by do_reg_operation(), and registry_callback().

◆ InfHostOpenBufferedFile()

int InfHostOpenBufferedFile ( PHINF  InfHandle,
void Buffer,
ULONG  BufferSize,
LANGID  LanguageId,
ULONG ErrorLine 
)

Definition at line 20 of file infhostgen.c.

25{
28 WCHAR *FileBuffer;
29 ULONG FileBufferSize;
30
31 *InfHandle = NULL;
32 *ErrorLine = (ULONG)-1;
33
34 /* Allocate file buffer */
35 FileBufferSize = BufferSize + 2;
36 FileBuffer = MALLOC(FileBufferSize);
37 if (FileBuffer == NULL)
38 {
39 DPRINT1("MALLOC() failed\n");
41 }
42
43 MEMCPY(FileBuffer, Buffer, BufferSize);
44
45 /* Append string terminator */
46 FileBuffer[BufferSize] = 0;
47 FileBuffer[BufferSize + 1] = 0;
48
49 /* Allocate infcache header */
50 Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
51 if (Cache == NULL)
52 {
53 DPRINT1("MALLOC() failed\n");
54 FREE(FileBuffer);
56 }
57
58 /* Initialize inicache header */
60 sizeof(INFCACHE));
61
62 Cache->LanguageId = LanguageId;
63
64 /* Parse the inf buffer */
65 if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferSize, NULL))
66 {
67// static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
68 WCHAR *new_buff;
69// UINT codepage = CP_ACP;
70 UINT offset = 0;
71
72// if (BufferSize > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
73// {
74// codepage = CP_UTF8;
75// offset = sizeof(utf8_bom);
76// }
77
78 new_buff = MALLOC(FileBufferSize * sizeof(WCHAR));
79 if (new_buff != NULL)
80 {
81 ULONG len;
83 FileBufferSize * sizeof(WCHAR),
84 &len,
85 (char *)FileBuffer + offset,
86 FileBufferSize - offset);
87
89 new_buff,
90 new_buff + len / sizeof(WCHAR),
91 ErrorLine);
92 FREE(new_buff);
93 }
94 else
96 }
97 else
98 {
99 WCHAR *new_buff = (WCHAR *)FileBuffer;
100 /* UCS-16 files should start with the Unicode BOM; we should skip it */
101 if (*new_buff == 0xfeff)
102 {
103 new_buff++;
104 FileBufferSize -= sizeof(WCHAR);
105 }
107 new_buff,
108 (WCHAR*)((char*)new_buff + FileBufferSize),
109 ErrorLine);
110 }
111
112 if (!INF_SUCCESS(Status))
113 {
114 FREE(Cache);
115 Cache = NULL;
116 }
117
118 /* Free file buffer */
119 FREE(FileBuffer);
120
121 *InfHandle = (HINF)Cache;
122
123 return INF_SUCCESS(Status) ? 0 : -1;
124}
#define DPRINT1
Definition: precomp.h:8
#define MALLOC(Size)
Definition: builddep.h:73
#define ZEROMEMORY(Area, Size)
Definition: builddep.h:74
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
static BOOLEAN InfpParseBuffer(PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
Definition: inffile.c:878
#define INF_STATUS_INSUFFICIENT_RESOURCES
Definition: infpriv.h:15
PVOID HINF
Definition: infsupp.h:21
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI BOOLEAN NTAPI RtlIsTextUnicode(_In_ CONST VOID *Buffer, _In_ INT Size, _Inout_opt_ INT *Flags)
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:62
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ InfHostOpenFile()

int InfHostOpenFile ( PHINF  InfHandle,
const CHAR FileName,
LANGID  LanguageId,
ULONG ErrorLine 
)

Definition at line 128 of file infhostgen.c.

132{
133 FILE *File;
134 CHAR *FileBuffer;
136 ULONG FileBufferLength;
139
140 *InfHandle = NULL;
141 *ErrorLine = (ULONG)-1;
142
143 /* Open the inf file */
144 File = fopen(FileName, "rb");
145 if (NULL == File)
146 {
147 DPRINT1("fopen() failed (errno %d)\n", errno);
148 return -1;
149 }
150
151 DPRINT("fopen() successful\n");
152
153 /* Query file size */
154 if (fseek(File, (size_t)0, SEEK_END))
155 {
156 DPRINT1("fseek() to EOF failed (errno %d)\n", errno);
157 fclose(File);
158 return -1;
159 }
160
162 if ((ULONG) -1 == FileLength)
163 {
164 DPRINT1("ftell() failed (errno %d)\n", errno);
165 fclose(File);
166 return -1;
167 }
168 DPRINT("File size: %u\n", (UINT)FileLength);
169
170 /* Rewind */
171 if (fseek(File, (size_t)0, SEEK_SET))
172 {
173 DPRINT1("fseek() to BOF failed (errno %d)\n", errno);
174 fclose(File);
175 return -1;
176 }
177
178 /* Allocate file buffer */
179 FileBufferLength = FileLength + 2;
180 FileBuffer = MALLOC(FileBufferLength);
181 if (FileBuffer == NULL)
182 {
183 DPRINT1("MALLOC() failed\n");
184 fclose(File);
185 return -1;
186 }
187
188 /* Read file */
189 if (FileLength != fread(FileBuffer, (size_t)1, (size_t)FileLength, File))
190 {
191 DPRINT1("fread() failed (errno %d)\n", errno);
192 FREE(FileBuffer);
193 fclose(File);
194 return -1;
195 }
196
197 fclose(File);
198
199 /* Append string terminator */
200 FileBuffer[FileLength] = 0;
201 FileBuffer[FileLength + 1] = 0;
202
203 /* Allocate infcache header */
204 Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
205 if (Cache == NULL)
206 {
207 DPRINT1("MALLOC() failed\n");
208 FREE(FileBuffer);
209 return -1;
210 }
211
212 /* Initialize inicache header */
214 sizeof(INFCACHE));
215
216 Cache->LanguageId = LanguageId;
217
218 /* Parse the inf buffer */
219 if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferLength, NULL))
220 {
221// static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
222 WCHAR *new_buff;
223// UINT codepage = CP_ACP;
224 UINT offset = 0;
225
226// if (FileLength > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
227// {
228// codepage = CP_UTF8;
229// offset = sizeof(utf8_bom);
230// }
231
232 new_buff = MALLOC(FileBufferLength * sizeof(WCHAR));
233 if (new_buff != NULL)
234 {
235 ULONG len;
237 FileBufferLength * sizeof(WCHAR),
238 &len,
239 (char *)FileBuffer + offset,
240 FileBufferLength - offset);
241
243 new_buff,
244 new_buff + len / sizeof(WCHAR),
245 ErrorLine);
246
247 FREE(new_buff);
248 }
249 else
251 }
252 else
253 {
254 WCHAR *new_buff = (WCHAR *)FileBuffer;
255 /* UCS-16 files should start with the Unicode BOM; we should skip it */
256 if (*new_buff == 0xfeff)
257 {
258 new_buff++;
259 FileBufferLength -= sizeof(WCHAR);
260 }
262 new_buff,
263 (WCHAR*)((char*)new_buff + FileBufferLength),
264 ErrorLine);
265 }
266
267 if (!INF_SUCCESS(Status))
268 {
269 FREE(Cache);
270 Cache = NULL;
271 }
272
273 /* Free file buffer */
274 FREE(FileBuffer);
275
276 *InfHandle = (HINF)Cache;
277
278 return INF_SUCCESS(Status) ? 0 : -1;
279}
#define INF_STATUS_SUCCESS
Definition: builddep.h:77
#define SEEK_END
Definition: cabinet.c:29
Definition: File.h:16
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
#define SEEK_SET
Definition: jmemansi.c:26
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228
#define DPRINT
Definition: sndvol32.h:71
char CHAR
Definition: xmlstorage.h:175

Referenced by ImportRegistryFile().

◆ InfHostWriteFile()

int InfHostWriteFile ( HINF  InfHandle,
const CHAR FileName,
const CHAR HeaderComment 
)

Definition at line 16 of file infhostput.c.

19{
23 FILE *File;
24
26 if (! INF_SUCCESS(Status))
27 {
28 errno = Status;
29 return -1;
30 }
31
32 File = fopen(FileName, "wb");
33 if (NULL == File)
34 {
35 FREE(Buffer);
36 DPRINT1("fopen() failed (errno %d)\n", errno);
37 return -1;
38 }
39
40 DPRINT("fopen() successful\n");
41
42 if (NULL != HeaderComment && '\0' != *HeaderComment)
43 {
44// fprintf(File, "; %s\r\n\r\n", HeaderComment);
45 }
46
47 if (BufferSize != fwrite(Buffer, (size_t)1, (size_t)BufferSize, File))
48 {
49 DPRINT1("fwrite() failed (errno %d)\n", errno);
50 fclose(File);
51 FREE(Buffer);
52 return -1;
53 }
54
55 fclose(File);
56
57 FREE(Buffer);
58
59 return 0;
60}
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
INFSTATUS InfpBuildFileBuffer(PINFCACHE InfHandle, PWCHAR *Buffer, PULONG BufferSize)
Definition: infput.c:90