Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

517 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. inf.h
  5. Abstract:
  6. Declares interface for INF wrapper routines. These routines simplify
  7. access of INFs by wrapping the setup APIs with routines that use
  8. pools or grow buffers.
  9. The INF wrapper routines also implement append and replace capabilities,
  10. so any INF used by the Win9x upgrade can be appended in the future, or
  11. completely replaced.
  12. Author:
  13. Marc R. Whitten (marcw) 20-Oct-1997
  14. Revision History:
  15. jimschm 05-Jan-1999 INF parser moved to migutil
  16. marcw 28-Oct-1998 Append/Replace capability
  17. marcw 08-Aug-1997 Pool/Growbuf routines
  18. --*/
  19. typedef enum {
  20. INF_USE_POOLHANDLE,
  21. INF_USE_GROWBUFFER,
  22. INF_USE_PRIVATE_GROWBUFFER,
  23. INF_USE_PRIVATE_POOLHANDLE
  24. } ALLOCATORTYPES;
  25. typedef struct {
  26. INFCONTEXT Context;
  27. GROWBUFFER GrowBuffer;
  28. POOLHANDLE PoolHandle;
  29. ALLOCATORTYPES Allocator;
  30. PCSTR KeyName;
  31. } INFSTRUCTA, *PINFSTRUCTA;
  32. typedef struct {
  33. INFCONTEXT Context;
  34. GROWBUFFER GrowBuffer;
  35. POOLHANDLE PoolHandle;
  36. ALLOCATORTYPES Allocator;
  37. PCWSTR KeyName;
  38. } INFSTRUCTW, *PINFSTRUCTW;
  39. #define INFCONTEXT_INIT {NULL,NULL,0,0}
  40. #define INITINFSTRUCT_GROWBUFFER {INFCONTEXT_INIT,GROWBUF_INIT,NULL,INF_USE_PRIVATE_GROWBUFFER,NULL}
  41. #define INITINFSTRUCT_POOLHANDLE {INFCONTEXT_INIT,GROWBUF_INIT,NULL,INF_USE_PRIVATE_POOLHANDLE,NULL}
  42. #define InfOpenAppendInfFile SetupOpenAppendInfFile
  43. BOOL
  44. InitInfReplaceTableA (
  45. IN PCSTR UpginfsDir OPTIONAL
  46. );
  47. BOOL
  48. InitInfReplaceTableW (
  49. IN PCWSTR UpginfsDir OPTIONAL
  50. );
  51. VOID
  52. InfCleanUpInfStructA (
  53. PINFSTRUCTA Context
  54. );
  55. VOID
  56. InfCleanUpInfStructW (
  57. PINFSTRUCTW Context
  58. );
  59. VOID
  60. InitInfStructA (
  61. OUT PINFSTRUCTA Context,
  62. IN PGROWBUFFER GrowBuffer, OPTIONAL
  63. IN POOLHANDLE PoolHandle OPTIONAL
  64. );
  65. VOID
  66. InitInfStructW (
  67. OUT PINFSTRUCTW Context,
  68. IN PGROWBUFFER GrowBuffer, OPTIONAL
  69. IN POOLHANDLE PoolHandle OPTIONAL
  70. );
  71. #define InfOpenInfFileA(f) SETTRACKCOMMENT(HINF,"InfOpenInfFile",__FILE__,__LINE__)\
  72. RealInfOpenInfFileA((f)/*,*/ ALLOCATION_TRACKING_CALL)\
  73. CLRTRACKCOMMENT
  74. #define InfOpenInfFileW(f) SETTRACKCOMMENT(HINF,"InfOpenInfFile",__FILE__,__LINE__)\
  75. RealInfOpenInfFileW((f)/*,*/ ALLOCATION_TRACKING_CALL)\
  76. CLRTRACKCOMMENT
  77. HINF
  78. RealInfOpenInfFileA (
  79. IN PCSTR FileName /*,*/
  80. ALLOCATION_TRACKING_DEF
  81. );
  82. HINF
  83. RealInfOpenInfFileW (
  84. IN PCWSTR FileName /*,*/
  85. ALLOCATION_TRACKING_DEF
  86. );
  87. VOID
  88. InfCloseInfFile (HINF Inf);
  89. //
  90. // See the macros below before calling InfOpenInfInAllSourcesA or W.
  91. //
  92. HINF
  93. InfOpenInfInAllSourcesA (
  94. IN PCSTR InfSpecifier,
  95. IN DWORD SourceCount,
  96. IN PCSTR * SourceDirectories
  97. );
  98. HINF
  99. InfOpenInfInAllSourcesW (
  100. IN PCWSTR InfSpecifier,
  101. IN DWORD SourceCount,
  102. IN PCWSTR *SourceDirectories
  103. );
  104. PSTR
  105. InfGetLineTextA (
  106. IN OUT PINFSTRUCTA
  107. );
  108. PWSTR
  109. InfGetLineTextW (
  110. IN OUT PINFSTRUCTW
  111. );
  112. PSTR
  113. InfGetStringFieldA (
  114. IN OUT PINFSTRUCTA Context,
  115. IN UINT FieldIndex
  116. );
  117. PWSTR
  118. InfGetStringFieldW (
  119. IN OUT PINFSTRUCTW Context,
  120. IN UINT FieldIndex
  121. );
  122. PSTR
  123. InfGetMultiSzFieldA (
  124. IN OUT PINFSTRUCTA Context,
  125. IN UINT FieldIndex
  126. ) ;
  127. PWSTR
  128. InfGetMultiSzFieldW (
  129. IN OUT PINFSTRUCTW Context,
  130. IN UINT FieldIndex
  131. ) ;
  132. BOOL
  133. InfGetIntFieldA (
  134. IN PINFSTRUCTA Context,
  135. IN UINT FieldIndex,
  136. IN PINT Value
  137. );
  138. BOOL
  139. InfGetIntFieldW (
  140. IN PINFSTRUCTW Context,
  141. IN UINT FieldIndex,
  142. IN PINT Value
  143. );
  144. PBYTE
  145. InfGetBinaryFieldA (
  146. IN PINFSTRUCTA Context,
  147. IN UINT FieldIndex
  148. );
  149. PBYTE
  150. InfGetBinaryFieldW (
  151. IN PINFSTRUCTW Context,
  152. IN UINT FieldIndex
  153. );
  154. BOOL
  155. InfGetLineByIndexA (
  156. IN HINF InfHandle,
  157. IN PCSTR Section,
  158. IN DWORD Index,
  159. OUT PINFSTRUCTA Context
  160. );
  161. BOOL
  162. InfGetLineByIndexW (
  163. IN HINF InfHandle,
  164. IN PCWSTR Section,
  165. IN DWORD Index,
  166. OUT PINFSTRUCTW Context
  167. );
  168. BOOL
  169. InfFindFirstLineA (
  170. IN HINF InfHandle,
  171. IN PCSTR Section,
  172. IN PCSTR Key,
  173. OUT PINFSTRUCTA Context
  174. );
  175. BOOL
  176. InfFindFirstLineW (
  177. IN HINF InfHandle,
  178. IN PCWSTR Section,
  179. IN PCWSTR Key,
  180. OUT PINFSTRUCTW Context
  181. );
  182. BOOL
  183. InfFindNextLineA (
  184. IN OUT PINFSTRUCTA Context
  185. );
  186. BOOL
  187. InfFindNextLineW (
  188. IN OUT PINFSTRUCTW Context
  189. );
  190. UINT
  191. InfGetFieldCountA (
  192. IN PINFSTRUCTA Context
  193. );
  194. UINT
  195. InfGetFieldCountW (
  196. IN PINFSTRUCTW Context
  197. );
  198. PCSTR
  199. InfGetOemStringFieldA (
  200. IN PINFSTRUCTA Context,
  201. IN UINT Field
  202. );
  203. BOOL
  204. SetupGetOemStringFieldA (
  205. IN PINFCONTEXT Context,
  206. IN DWORD Index,
  207. IN PTSTR ReturnBuffer,
  208. IN DWORD ReturnBufferSize,
  209. OUT PDWORD RequiredSize
  210. );
  211. VOID
  212. InfResetInfStructA (
  213. IN OUT PINFSTRUCTA Context
  214. );
  215. VOID
  216. InfResetInfStructW (
  217. IN OUT PINFSTRUCTW Context
  218. );
  219. //
  220. // INF parser
  221. //
  222. typedef struct _tagINFLINE {
  223. PCWSTR Key; OPTIONAL
  224. PCWSTR Data;
  225. DWORD LineFlags;
  226. struct _tagINFLINE *Next, *Prev;
  227. struct _tagINFSECTION *Section;
  228. } INFLINE, *PINFLINE;
  229. #define LINEFLAG_KEY_QUOTED 0x0001
  230. #define LINEFLAG_ALL_COMMENTS 0x0002
  231. #define LINEFLAG_TRAILING_COMMENTS 0x0004
  232. typedef struct _tagINFSECTION {
  233. PCWSTR Name;
  234. PINFLINE FirstLine;
  235. PINFLINE LastLine;
  236. UINT LineCount;
  237. struct _tagINFSECTION *Next, *Prev;
  238. } INFSECTION, *PINFSECTION;
  239. PINFSECTION
  240. AddInfSectionToTableA (
  241. IN HINF Inf,
  242. IN PCSTR SectionName
  243. );
  244. PINFSECTION
  245. AddInfSectionToTableW (
  246. IN HINF Inf,
  247. IN PCWSTR SectionName
  248. );
  249. PINFSECTION
  250. FindInfSectionInTableA (
  251. IN HINF Inf,
  252. IN PCSTR SectionName
  253. );
  254. PINFSECTION
  255. GetFirstInfSectionInTable (
  256. IN HINF Inf
  257. );
  258. PINFSECTION
  259. GetNextInfSectionInTable (
  260. IN PINFSECTION Section
  261. );
  262. PINFSECTION
  263. FindInfSectionInTableW (
  264. IN HINF Inf,
  265. IN PCWSTR SectionName
  266. );
  267. PINFLINE
  268. AddInfLineToTableA (
  269. IN HINF Inf,
  270. IN PINFSECTION SectionPtr,
  271. IN PCSTR Key, OPTIONAL
  272. IN PCSTR Data,
  273. IN DWORD LineFlags
  274. );
  275. PINFLINE
  276. AddInfLineToTableW (
  277. IN HINF Inf,
  278. IN PINFSECTION SectionPtr,
  279. IN PCWSTR Key, OPTIONAL
  280. IN PCWSTR Data,
  281. IN DWORD LineFlags
  282. );
  283. PINFLINE
  284. FindLineInInfSectionA (
  285. IN HINF Inf,
  286. IN PINFSECTION Section,
  287. IN PCSTR Key
  288. );
  289. PINFLINE
  290. FindLineInInfSectionW (
  291. IN HINF Inf,
  292. IN PINFSECTION Section,
  293. IN PCWSTR Key
  294. );
  295. PINFLINE
  296. GetFirstLineInSectionStrA (
  297. IN HINF Inf,
  298. IN PCSTR Section
  299. );
  300. PINFLINE
  301. GetFirstLineInSectionStrW (
  302. IN HINF Inf,
  303. IN PCWSTR Section
  304. );
  305. PINFLINE
  306. GetFirstLineInSectionStruct (
  307. IN PINFSECTION Section
  308. );
  309. PINFLINE
  310. GetNextLineInSection (
  311. IN PINFLINE PrevLine
  312. );
  313. UINT
  314. GetInfSectionLineCount (
  315. IN PINFSECTION Section
  316. );
  317. BOOL
  318. DeleteSectionInInfFile (
  319. IN HINF Inf,
  320. IN PINFSECTION Section
  321. );
  322. BOOL
  323. DeleteLineInInfSection (
  324. IN HINF Inf,
  325. IN PINFLINE InfLine
  326. );
  327. HINF
  328. OpenInfFileExA (
  329. IN PCSTR InfFilePath,
  330. IN PSTR SectionList,
  331. IN BOOL KeepComments
  332. );
  333. #define OpenInfFileA(Path) OpenInfFileExA (Path, NULL, TRUE)
  334. HINF
  335. OpenInfFileExW (
  336. IN PCWSTR InfFilePath,
  337. IN PWSTR SectionList,
  338. IN BOOL KeepComments
  339. );
  340. #define OpenInfFileW(Path) OpenInfFileExW (Path, NULL, TRUE)
  341. VOID
  342. CloseInfFile (
  343. HINF InfFile
  344. );
  345. BOOL
  346. SaveInfFileA (
  347. IN HINF Inf,
  348. IN PCSTR SaveToFileSpec
  349. );
  350. BOOL
  351. SaveInfFileW (
  352. IN HINF Inf,
  353. IN PCWSTR SaveToFileSpec
  354. );
  355. VOID
  356. InitInfReplaceTable (
  357. VOID
  358. );
  359. //
  360. // ANSI/UNICODE mappings.
  361. //
  362. #ifdef UNICODE
  363. # define INFSTRUCT INFSTRUCTW
  364. # define PINFSTRUCT PINFSTRUCTW
  365. # define InfCleanUpInfStruct InfCleanUpInfStructW
  366. # define InitInfStruct InitInfStructW
  367. # define InfResetInfStruct InfResetInfStructW
  368. # define InfFindFirstLine InfFindFirstLineW
  369. # define InfFindNextLine InfFindNextLineW
  370. # define InfGetLineByIndex InfGetLineByIndexW
  371. # define InfGetStringField InfGetStringFieldW
  372. # define InfGetMultiSzField InfGetMultiSzFieldW
  373. # define InfGetLineText InfGetLineTextW
  374. # define InfOpenInfFile InfOpenInfFileW
  375. # define InfGetOemStringField InfGetStringFieldW
  376. # define InfGetIntField InfGetIntFieldW
  377. # define InfGetBinaryField InfGetBinaryFieldW
  378. # define InfGetFieldCount InfGetFieldCountW
  379. # define SetupGetOemStringField SetupGetStringFieldW
  380. # define InfOpenInfInAllSources(x) InfOpenInfInAllSourcesW((x),1,&g_SourceDirectory);
  381. # define AddInfSectionToTable AddInfSectionToTableW
  382. # define FindInfSectionInTable FindInfSectionInTableW
  383. # define AddInfLineToTable AddInfLineToTableW
  384. # define FindLineInInfSection FindLineInInfSectionW
  385. # define GetFirstLineInSectionStr GetFirstLineInSectionStrW
  386. # define OpenInfFileEx OpenInfFileExW
  387. # define OpenInfFile OpenInfFileW
  388. # define SaveInfFile SaveInfFileW
  389. # define InitInfReplaceTable InitInfReplaceTableW
  390. #else
  391. # define INFSTRUCT INFSTRUCTA
  392. # define PINFSTRUCT PINFSTRUCTA
  393. # define InfCleanUpInfStruct InfCleanUpInfStructA
  394. # define InitInfStruct InitInfStructA
  395. # define InfResetInfStruct InfResetInfStructA
  396. # define InfFindFirstLine InfFindFirstLineA
  397. # define InfFindNextLine InfFindNextLineA
  398. # define InfGetLineByIndex InfGetLineByIndexA
  399. # define InfGetStringField InfGetStringFieldA
  400. # define InfGetMultiSzField InfGetMultiSzFieldA
  401. # define InfGetLineText InfGetLineTextA
  402. # define InfOpenInfFile InfOpenInfFileA
  403. # define InfGetOemStringField InfGetOemStringFieldA
  404. # define InfGetIntField InfGetIntFieldA
  405. # define InfGetBinaryField InfGetBinaryFieldA
  406. # define InfGetFieldCount InfGetFieldCountA
  407. # define SetupGetOemStringField SetupGetOemStringFieldA
  408. # define InfOpenInfInAllSources(x) InfOpenInfInAllSourcesA((x),g_SourceDirectoryCount,g_SourceDirectories);
  409. # define AddInfSectionToTable AddInfSectionToTableA
  410. # define FindInfSectionInTable FindInfSectionInTableA
  411. # define AddInfLineToTable AddInfLineToTableA
  412. # define FindLineInInfSection FindLineInInfSectionA
  413. # define GetFirstLineInSectionStr GetFirstLineInSectionStrA
  414. # define OpenInfFileEx OpenInfFileExA
  415. # define OpenInfFile OpenInfFileA
  416. # define SaveInfFile SaveInfFileA
  417. # define InitInfReplaceTable InitInfReplaceTableA
  418. #endif