Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninfget.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: .inf file parser 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * PROGRAMMER: Royce Mitchell III 00005 * Eric Kohl 00006 * Ge van Geldorp <gvg@reactos.org> 00007 */ 00008 00009 /* INCLUDES *****************************************************************/ 00010 00011 #include "inflib.h" 00012 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 00017 INFSTATUS 00018 InfpFindFirstLine(PINFCACHE Cache, 00019 PCTSTR Section, 00020 PCTSTR Key, 00021 PINFCONTEXT *Context) 00022 { 00023 PINFCACHESECTION CacheSection; 00024 PINFCACHELINE CacheLine; 00025 00026 if (Cache == NULL || Section == NULL || Context == NULL) 00027 { 00028 DPRINT1("Invalid parameter\n"); 00029 return INF_STATUS_INVALID_PARAMETER; 00030 } 00031 00032 CacheSection = InfpFindSection(Cache, Section); 00033 if (NULL == CacheSection) 00034 { 00035 DPRINT("Section not found\n"); 00036 return INF_STATUS_NOT_FOUND; 00037 } 00038 00039 if (Key != NULL) 00040 { 00041 CacheLine = InfpFindKeyLine(CacheSection, Key); 00042 } 00043 else 00044 { 00045 CacheLine = CacheSection->FirstLine; 00046 } 00047 00048 if (NULL == CacheLine) 00049 { 00050 DPRINT("Key not found\n"); 00051 return INF_STATUS_NOT_FOUND; 00052 } 00053 00054 *Context = MALLOC(sizeof(INFCONTEXT)); 00055 if (NULL == *Context) 00056 { 00057 DPRINT1("MALLOC() failed\n"); 00058 return INF_STATUS_NO_MEMORY; 00059 } 00060 (*Context)->Inf = (PVOID)Cache; 00061 (*Context)->Section = (PVOID)CacheSection; 00062 (*Context)->Line = (PVOID)CacheLine; 00063 00064 return INF_STATUS_SUCCESS; 00065 } 00066 00067 00068 INFSTATUS 00069 InfpFindNextLine(PINFCONTEXT ContextIn, 00070 PINFCONTEXT ContextOut) 00071 { 00072 PINFCACHELINE CacheLine; 00073 00074 if (ContextIn == NULL || ContextOut == NULL) 00075 return INF_STATUS_INVALID_PARAMETER; 00076 00077 if (ContextIn->Line == NULL) 00078 return INF_STATUS_INVALID_PARAMETER; 00079 00080 CacheLine = (PINFCACHELINE)ContextIn->Line; 00081 if (CacheLine->Next == NULL) 00082 return INF_STATUS_NOT_FOUND; 00083 00084 if (ContextIn != ContextOut) 00085 { 00086 ContextOut->Inf = ContextIn->Inf; 00087 ContextOut->Section = ContextIn->Section; 00088 } 00089 ContextOut->Line = (PVOID)(CacheLine->Next); 00090 00091 return INF_STATUS_SUCCESS; 00092 } 00093 00094 00095 INFSTATUS 00096 InfpFindFirstMatchLine(PINFCONTEXT ContextIn, 00097 PCTSTR Key, 00098 PINFCONTEXT ContextOut) 00099 { 00100 PINFCACHELINE CacheLine; 00101 00102 if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0) 00103 return INF_STATUS_INVALID_PARAMETER; 00104 00105 if (ContextIn->Inf == NULL || ContextIn->Section == NULL) 00106 return INF_STATUS_INVALID_PARAMETER; 00107 00108 CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine; 00109 while (CacheLine != NULL) 00110 { 00111 if (CacheLine->Key != NULL && _tcsicmp (CacheLine->Key, Key) == 0) 00112 { 00113 00114 if (ContextIn != ContextOut) 00115 { 00116 ContextOut->Inf = ContextIn->Inf; 00117 ContextOut->Section = ContextIn->Section; 00118 } 00119 ContextOut->Line = (PVOID)CacheLine; 00120 00121 return INF_STATUS_SUCCESS; 00122 } 00123 00124 CacheLine = CacheLine->Next; 00125 } 00126 00127 return INF_STATUS_NOT_FOUND; 00128 } 00129 00130 00131 INFSTATUS 00132 InfpFindNextMatchLine(PINFCONTEXT ContextIn, 00133 PCTSTR Key, 00134 PINFCONTEXT ContextOut) 00135 { 00136 PINFCACHELINE CacheLine; 00137 00138 if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0) 00139 return INF_STATUS_INVALID_PARAMETER; 00140 00141 if (ContextIn->Inf == NULL || ContextIn->Section == NULL || ContextIn->Line == NULL) 00142 return INF_STATUS_INVALID_PARAMETER; 00143 00144 CacheLine = (PINFCACHELINE)ContextIn->Line; 00145 while (CacheLine != NULL) 00146 { 00147 if (CacheLine->Key != NULL && _tcsicmp (CacheLine->Key, Key) == 0) 00148 { 00149 00150 if (ContextIn != ContextOut) 00151 { 00152 ContextOut->Inf = ContextIn->Inf; 00153 ContextOut->Section = ContextIn->Section; 00154 } 00155 ContextOut->Line = (PVOID)CacheLine; 00156 00157 return INF_STATUS_SUCCESS; 00158 } 00159 00160 CacheLine = CacheLine->Next; 00161 } 00162 00163 return INF_STATUS_NOT_FOUND; 00164 } 00165 00166 00167 LONG 00168 InfpGetLineCount(HINF InfHandle, 00169 PCTSTR Section) 00170 { 00171 PINFCACHE Cache; 00172 PINFCACHESECTION CacheSection; 00173 00174 if (InfHandle == NULL || Section == NULL) 00175 { 00176 DPRINT("Invalid parameter\n"); 00177 return -1; 00178 } 00179 00180 Cache = (PINFCACHE)InfHandle; 00181 00182 /* Iterate through list of sections */ 00183 CacheSection = Cache->FirstSection; 00184 while (CacheSection != NULL) 00185 { 00186 /* Are the section names the same? */ 00187 if (_tcsicmp(CacheSection->Name, Section) == 0) 00188 { 00189 return CacheSection->LineCount; 00190 } 00191 00192 /* Get the next section */ 00193 CacheSection = CacheSection->Next; 00194 } 00195 00196 DPRINT("Section not found\n"); 00197 00198 return -1; 00199 } 00200 00201 00202 /* InfpGetLineText */ 00203 00204 00205 LONG 00206 InfpGetFieldCount(PINFCONTEXT Context) 00207 { 00208 if (Context == NULL || Context->Line == NULL) 00209 return 0; 00210 00211 return ((PINFCACHELINE)Context->Line)->FieldCount; 00212 } 00213 00214 00215 INFSTATUS 00216 InfpGetBinaryField(PINFCONTEXT Context, 00217 ULONG FieldIndex, 00218 PUCHAR ReturnBuffer, 00219 ULONG ReturnBufferSize, 00220 PULONG RequiredSize) 00221 { 00222 PINFCACHELINE CacheLine; 00223 PINFCACHEFIELD CacheField; 00224 ULONG Index; 00225 ULONG Size; 00226 PUCHAR Ptr; 00227 00228 if (Context == NULL || Context->Line == NULL || FieldIndex == 0) 00229 { 00230 DPRINT("Invalid parameter\n"); 00231 return INF_STATUS_INVALID_PARAMETER; 00232 } 00233 00234 if (RequiredSize != NULL) 00235 *RequiredSize = 0; 00236 00237 CacheLine = (PINFCACHELINE)Context->Line; 00238 00239 if (FieldIndex > (ULONG)CacheLine->FieldCount) 00240 return INF_STATUS_NOT_FOUND; 00241 00242 CacheField = CacheLine->FirstField; 00243 for (Index = 1; Index < FieldIndex; Index++) 00244 CacheField = CacheField->Next; 00245 00246 Size = (ULONG)CacheLine->FieldCount - FieldIndex + 1; 00247 00248 if (RequiredSize != NULL) 00249 *RequiredSize = Size; 00250 00251 if (ReturnBuffer != NULL) 00252 { 00253 if (ReturnBufferSize < Size) 00254 return INF_STATUS_BUFFER_OVERFLOW; 00255 00256 /* Copy binary data */ 00257 Ptr = ReturnBuffer; 00258 while (CacheField != NULL) 00259 { 00260 *Ptr = (UCHAR)_tcstoul (CacheField->Data, NULL, 16); 00261 00262 Ptr++; 00263 CacheField = CacheField->Next; 00264 } 00265 } 00266 00267 return INF_STATUS_SUCCESS; 00268 } 00269 00270 00271 INFSTATUS 00272 InfpGetIntField(PINFCONTEXT Context, 00273 ULONG FieldIndex, 00274 INT* IntegerValue) 00275 { 00276 PINFCACHELINE CacheLine; 00277 PINFCACHEFIELD CacheField; 00278 ULONG Index; 00279 PTCHAR Ptr; 00280 00281 if (Context == NULL || Context->Line == NULL || IntegerValue == NULL) 00282 { 00283 DPRINT("Invalid parameter\n"); 00284 return INF_STATUS_INVALID_PARAMETER; 00285 } 00286 00287 CacheLine = (PINFCACHELINE)Context->Line; 00288 00289 if (FieldIndex > (ULONG)CacheLine->FieldCount) 00290 { 00291 DPRINT("Invalid parameter\n"); 00292 return INF_STATUS_INVALID_PARAMETER; 00293 } 00294 00295 if (FieldIndex == 0) 00296 { 00297 Ptr = CacheLine->Key; 00298 } 00299 else 00300 { 00301 CacheField = CacheLine->FirstField; 00302 for (Index = 1; Index < FieldIndex; Index++) 00303 CacheField = CacheField->Next; 00304 00305 Ptr = CacheField->Data; 00306 } 00307 00308 *IntegerValue = (LONG)_tcstol(Ptr, NULL, 0); 00309 00310 return INF_STATUS_SUCCESS; 00311 } 00312 00313 00314 INFSTATUS 00315 InfpGetMultiSzField(PINFCONTEXT Context, 00316 ULONG FieldIndex, 00317 PTSTR ReturnBuffer, 00318 ULONG ReturnBufferSize, 00319 PULONG RequiredSize) 00320 { 00321 PINFCACHELINE CacheLine; 00322 PINFCACHEFIELD CacheField; 00323 PINFCACHEFIELD FieldPtr; 00324 ULONG Index; 00325 ULONG Size; 00326 PTCHAR Ptr; 00327 00328 if (Context == NULL || Context->Line == NULL || FieldIndex == 0) 00329 { 00330 DPRINT("Invalid parameter\n"); 00331 return INF_STATUS_INVALID_PARAMETER; 00332 } 00333 00334 if (RequiredSize != NULL) 00335 *RequiredSize = 0; 00336 00337 CacheLine = (PINFCACHELINE)Context->Line; 00338 00339 if (FieldIndex > (ULONG)CacheLine->FieldCount) 00340 return INF_STATUS_INVALID_PARAMETER; 00341 00342 CacheField = CacheLine->FirstField; 00343 for (Index = 1; Index < FieldIndex; Index++) 00344 CacheField = CacheField->Next; 00345 00346 /* Calculate the required buffer size */ 00347 FieldPtr = CacheField; 00348 Size = 0; 00349 while (FieldPtr != NULL) 00350 { 00351 Size += ((ULONG)_tcslen (FieldPtr->Data) + 1); 00352 FieldPtr = FieldPtr->Next; 00353 } 00354 Size++; 00355 00356 if (RequiredSize != NULL) 00357 *RequiredSize = Size; 00358 00359 if (ReturnBuffer != NULL) 00360 { 00361 if (ReturnBufferSize < Size) 00362 return INF_STATUS_BUFFER_OVERFLOW; 00363 00364 /* Copy multi-sz string */ 00365 Ptr = ReturnBuffer; 00366 FieldPtr = CacheField; 00367 while (FieldPtr != NULL) 00368 { 00369 Size = (ULONG)_tcslen (FieldPtr->Data) + 1; 00370 00371 _tcscpy (Ptr, FieldPtr->Data); 00372 00373 Ptr = Ptr + Size; 00374 FieldPtr = FieldPtr->Next; 00375 } 00376 *Ptr = 0; 00377 } 00378 00379 return INF_STATUS_SUCCESS; 00380 } 00381 00382 00383 INFSTATUS 00384 InfpGetStringField(PINFCONTEXT Context, 00385 ULONG FieldIndex, 00386 PTSTR ReturnBuffer, 00387 ULONG ReturnBufferSize, 00388 PULONG RequiredSize) 00389 { 00390 PINFCACHELINE CacheLine; 00391 PINFCACHEFIELD CacheField; 00392 ULONG Index; 00393 PTCHAR Ptr; 00394 ULONG Size; 00395 00396 if (Context == NULL || Context->Line == NULL || FieldIndex == 0) 00397 { 00398 DPRINT("Invalid parameter\n"); 00399 return INF_STATUS_INVALID_PARAMETER; 00400 } 00401 00402 if (RequiredSize != NULL) 00403 *RequiredSize = 0; 00404 00405 CacheLine = (PINFCACHELINE)Context->Line; 00406 00407 if (FieldIndex > (ULONG)CacheLine->FieldCount) 00408 return INF_STATUS_INVALID_PARAMETER; 00409 00410 if (FieldIndex == 0) 00411 { 00412 Ptr = CacheLine->Key; 00413 } 00414 else 00415 { 00416 CacheField = CacheLine->FirstField; 00417 for (Index = 1; Index < FieldIndex; Index++) 00418 CacheField = CacheField->Next; 00419 00420 Ptr = CacheField->Data; 00421 } 00422 00423 Size = (ULONG)_tcslen (Ptr) + 1; 00424 00425 if (RequiredSize != NULL) 00426 *RequiredSize = Size; 00427 00428 if (ReturnBuffer != NULL) 00429 { 00430 if (ReturnBufferSize < Size) 00431 return INF_STATUS_BUFFER_OVERFLOW; 00432 00433 _tcscpy (ReturnBuffer, Ptr); 00434 } 00435 00436 return INF_STATUS_SUCCESS; 00437 } 00438 00439 00440 INFSTATUS 00441 InfpGetData(PINFCONTEXT Context, 00442 PTCHAR *Key, 00443 PTCHAR *Data) 00444 { 00445 PINFCACHELINE CacheKey; 00446 00447 if (Context == NULL || Context->Line == NULL || Data == NULL) 00448 { 00449 DPRINT("Invalid parameter\n"); 00450 return INF_STATUS_INVALID_PARAMETER; 00451 } 00452 00453 CacheKey = (PINFCACHELINE)Context->Line; 00454 if (Key != NULL) 00455 *Key = CacheKey->Key; 00456 00457 if (Data != NULL) 00458 { 00459 if (CacheKey->FirstField == NULL) 00460 { 00461 *Data = NULL; 00462 } 00463 else 00464 { 00465 *Data = CacheKey->FirstField->Data; 00466 } 00467 } 00468 00469 return INF_STATUS_SUCCESS; 00470 } 00471 00472 00473 INFSTATUS 00474 InfpGetDataField(PINFCONTEXT Context, 00475 ULONG FieldIndex, 00476 PTCHAR *Data) 00477 { 00478 PINFCACHELINE CacheLine; 00479 PINFCACHEFIELD CacheField; 00480 ULONG Index; 00481 00482 if (Context == NULL || Context->Line == NULL || Data == NULL) 00483 { 00484 DPRINT("Invalid parameter\n"); 00485 return INF_STATUS_INVALID_PARAMETER; 00486 } 00487 00488 CacheLine = (PINFCACHELINE)Context->Line; 00489 00490 if (FieldIndex > (ULONG)CacheLine->FieldCount) 00491 return INF_STATUS_INVALID_PARAMETER; 00492 00493 if (FieldIndex == 0) 00494 { 00495 *Data = CacheLine->Key; 00496 } 00497 else 00498 { 00499 CacheField = CacheLine->FirstField; 00500 for (Index = 1; Index < FieldIndex; Index++) 00501 CacheField = CacheField->Next; 00502 00503 *Data = CacheField->Data; 00504 } 00505 00506 return INF_STATUS_SUCCESS; 00507 } 00508 00509 VOID 00510 InfpFreeContext(PINFCONTEXT Context) 00511 { 00512 FREE(Context); 00513 } 00514 00515 /* EOF */ Generated on Sun May 27 2012 04:36:14 for ReactOS by
1.7.6.1
|