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.

190 lines
4.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. INFSCAN
  5. common.h
  6. Abstract:
  7. Common types/macros/constants
  8. History:
  9. Created July 2001 - JamieHun
  10. --*/
  11. #ifndef _INFSCAN_COMMON_H_
  12. #define _INFSCAN_COMMON_H_
  13. #define ASIZE(x) (sizeof(x)/sizeof((x)[0]))
  14. typedef vector<TCHAR> tcharbuffer;
  15. typedef map<SafeString,SafeString> StringToString;
  16. typedef map<int,int> IntToInt;
  17. typedef map<SafeString,int> StringToInt;
  18. typedef map<int,SafeString> IntToString;
  19. typedef list<SafeString> StringList;
  20. typedef set<SafeString> StringSet;
  21. typedef map<SafeString,StringSet> StringToStringset;
  22. #define PLATFORM_MASK_WIN (0x00000001)
  23. #define PLATFORM_MASK_NTX86 (0x00000002)
  24. #define PLATFORM_MASK_NTIA64 (0x00000004)
  25. #define PLATFORM_MASK_NTAMD64 (0x00000008)
  26. #define PLATFORM_MASK_NT (0x0000000E)
  27. #define PLATFORM_MASK_ALL_ARCHITECTS (0x0000ffff)
  28. #define PLATFORM_MASK_ALL_MAJOR_VER (0x00010000)
  29. #define PLATFORM_MASK_ALL_MINOR_VER (0x00020000)
  30. #define PLATFORM_MASK_ALL_TYPE (0x00040000)
  31. #define PLATFORM_MASK_ALL_SUITE (0x00080000)
  32. #define PLATFORM_MASK_ALL (0x00ffffff)
  33. #define PLATFORM_MASK_IGNORE (0x80000000) // indicates never do
  34. #define PLATFORM_MASK_MODIFIEDFILES (0x40000000) // for HasDependentFileChanged
  35. #define GUID_STRING_LEN (39)
  36. //
  37. // basic critical section
  38. //
  39. class CriticalSection {
  40. private:
  41. CRITICAL_SECTION critsect;
  42. public:
  43. CriticalSection()
  44. {
  45. InitializeCriticalSection(&critsect);
  46. }
  47. ~CriticalSection()
  48. {
  49. DeleteCriticalSection(&critsect);
  50. }
  51. void Enter()
  52. {
  53. EnterCriticalSection(&critsect);
  54. }
  55. void Leave()
  56. {
  57. LeaveCriticalSection(&critsect);
  58. }
  59. };
  60. //
  61. // use this inside a function to manage enter/leaving a critical section
  62. //
  63. class ProtectedSection {
  64. private:
  65. CriticalSection & CS;
  66. int count;
  67. public:
  68. ProtectedSection(CriticalSection & sect,BOOL enter=TRUE) : CS(sect)
  69. {
  70. count = 0;
  71. if(enter) {
  72. Enter();
  73. }
  74. }
  75. ~ProtectedSection()
  76. {
  77. if(count) {
  78. CS.Leave();
  79. }
  80. }
  81. void Enter()
  82. {
  83. count++;
  84. if(count == 1) {
  85. CS.Enter();
  86. }
  87. }
  88. void Leave()
  89. {
  90. if(count>0) {
  91. count--;
  92. if(count == 0) {
  93. CS.Leave();
  94. }
  95. }
  96. }
  97. };
  98. //
  99. // for string/product lookup tables
  100. //
  101. struct StringProdPair {
  102. PCTSTR String;
  103. DWORD ProductMask;
  104. };
  105. //
  106. // SourceDisksFiles tables
  107. //
  108. struct SourceDisksFilesEntry {
  109. BOOL Used; // indicates someone referenced it at least once
  110. DWORD Platform;
  111. int DiskId; // field 1
  112. SafeString SubDir; // field 2
  113. //
  114. // the following are specific to layout.inf
  115. //
  116. int TargetDirectory; // field 8
  117. int UpgradeDisposition; // field 9
  118. int TextModeDisposition; // field 10
  119. SafeString TargetName; // field 11
  120. };
  121. typedef list<SourceDisksFilesEntry> SourceDisksFilesList;
  122. typedef map<SafeString,SourceDisksFilesList> StringToSourceDisksFilesList;
  123. //
  124. // DestinationDirs tables
  125. //
  126. struct TargetDirectoryEntry {
  127. bool Used; // indicates someone referenced it at least once
  128. int DirId; // DIRID
  129. SafeString SubDir; // sub-directory
  130. };
  131. typedef map<SafeString,TargetDirectoryEntry> CopySectionToTargetDirectoryEntry;
  132. //
  133. // exception classes
  134. //
  135. class bad_pointer : public exception {
  136. public:
  137. bad_pointer(const char *_S = "bad pointer") : exception(_S) {}
  138. };
  139. //
  140. // globals.cpp and common.inl
  141. //
  142. VOID Usage(VOID);
  143. void FormatToStream(FILE * stream,DWORD fmt,DWORD flags,...);
  144. PTSTR CopyString(PCTSTR arg, int extra = 0);
  145. #ifdef UNICODE
  146. PTSTR CopyString(PCSTR arg, int extra = 0);
  147. #endif
  148. SafeString PathConcat(const SafeString & path,const SafeString & tail);
  149. int GetFullPathName(const SafeString & given,SafeString & target);
  150. bool MyGetStringField(PINFCONTEXT Context,DWORD FieldIndex,SafeString & result,bool downcase = true);
  151. bool MyIsAlpha(CHAR c);
  152. bool MyIsAlpha(WCHAR c);
  153. LPSTR MyCharNext(LPCSTR lpsz);
  154. LPWSTR MyCharNext(LPCWSTR lpsz);
  155. SafeString QuoteIt(const SafeString & val);
  156. int GeneratePnf(const SafeString & pnf);
  157. void Write(HANDLE hFile,const SafeStringW & str);
  158. void Write(HANDLE hFile,const SafeStringA & str);
  159. //
  160. // forward references
  161. //
  162. class InfScan;
  163. class GlobalScan;
  164. class InstallScan;
  165. class ParseInfContext;
  166. #endif //!_INFSCAN_COMMON_H_