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.

360 lines
10 KiB

  1. #pragma once
  2. #if !defined(NT_INCLUDED) && defined(_WINDOWS_)
  3. #error You must not include windows.h before this.
  4. #endif
  5. #include "nt.h"
  6. #include "ntrtl.h"
  7. #include "nturtl.h"
  8. #include "windows.h"
  9. #include <limits.h>
  10. #include "debmacro.h"
  11. #include "FusionString.h"
  12. #include "messages.h"
  13. #include "numberof.h"
  14. #include <ole2.h>
  15. #include <xmlparser.h>
  16. #include "fusionbuffer.h"
  17. #include <sxstypes.h>
  18. #include "util.h"
  19. /*--------------------------------------------------------------------------
  20. --------------------------------------------------------------------------*/
  21. typedef struct _SXS_ASSEMBLY_IDENTITY_ATTRIBUTE_REFERENCE SXS_ASSEMBLY_IDENTITY_ATTRIBUTE_REFERENCE;
  22. BOOL
  23. FusionpEventLogMain(
  24. HINSTANCE,
  25. DWORD dwReason,
  26. PVOID pvReserved
  27. );
  28. HRESULT
  29. FusionpLogError(
  30. DWORD dwEventId,
  31. const UNICODE_STRING& s1,
  32. const UNICODE_STRING& s2 = g_strEmptyUnicodeString,
  33. const UNICODE_STRING& s3 = g_strEmptyUnicodeString,
  34. const UNICODE_STRING& s4 = g_strEmptyUnicodeString
  35. );
  36. HRESULT
  37. FusionpLogError(
  38. DWORD dwEventId,
  39. ULONG nStrings = 0,
  40. UNICODE_STRING const* const* rgps = NULL
  41. );
  42. HRESULT
  43. FusionpLogErrorToEventLog(
  44. DWORD dwEventId,
  45. const UNICODE_STRING& s1,
  46. const UNICODE_STRING& s2 = g_strEmptyUnicodeString,
  47. const UNICODE_STRING& s3 = g_strEmptyUnicodeString,
  48. const UNICODE_STRING& s4 = g_strEmptyUnicodeString
  49. );
  50. HRESULT
  51. FusionpLogErrorToEventLog(
  52. DWORD dwEventId,
  53. ULONG nStrings = 0,
  54. UNICODE_STRING const* const* rgps = NULL
  55. );
  56. HRESULT
  57. FusionpLogErrorToDebugger(
  58. DWORD dwEventId,
  59. const UNICODE_STRING& s1,
  60. const UNICODE_STRING& s2 = g_strEmptyUnicodeString,
  61. const UNICODE_STRING& s3 = g_strEmptyUnicodeString,
  62. const UNICODE_STRING& s4 = g_strEmptyUnicodeString
  63. );
  64. HRESULT
  65. FusionpLogErrorToDebugger(
  66. DWORD dwEventId,
  67. ULONG nStrings = 0,
  68. UNICODE_STRING const* const* rgps = NULL
  69. );
  70. HRESULT
  71. FusionpLogParseError(
  72. PCWSTR FilePath,
  73. SIZE_T FilePathCch,
  74. ULONG LineNumber,
  75. DWORD dwLastParseError,
  76. const UNICODE_STRING *p1 = NULL,
  77. const UNICODE_STRING *p2 = NULL,
  78. const UNICODE_STRING *p3 = NULL,
  79. const UNICODE_STRING *p4 = NULL,
  80. const UNICODE_STRING *p5 = NULL,
  81. const UNICODE_STRING *p6 = NULL,
  82. const UNICODE_STRING *p7 = NULL,
  83. const UNICODE_STRING *p8 = NULL,
  84. const UNICODE_STRING *p9 = NULL,
  85. const UNICODE_STRING *p10 = NULL,
  86. const UNICODE_STRING *p11 = NULL,
  87. const UNICODE_STRING *p12 = NULL,
  88. const UNICODE_STRING *p13 = NULL,
  89. const UNICODE_STRING *p14 = NULL,
  90. const UNICODE_STRING *p15 = NULL,
  91. const UNICODE_STRING *p16 = NULL,
  92. const UNICODE_STRING *p17 = NULL,
  93. const UNICODE_STRING *p18 = NULL,
  94. const UNICODE_STRING *p19 = NULL,
  95. const UNICODE_STRING *p20 = NULL
  96. );
  97. DWORD
  98. FusionpEventIdToError(
  99. DWORD dwEventId
  100. );
  101. VOID
  102. FusionpLogRequiredAttributeMissingParseError(
  103. PCWSTR SourceFilePath,
  104. SIZE_T SourceFileCch,
  105. ULONG LineNumber,
  106. PCWSTR ElementName,
  107. SIZE_T ElementNameCch,
  108. PCWSTR AttributeName,
  109. SIZE_T AttributeNameCch
  110. );
  111. VOID
  112. FusionpLogInvalidAttributeValueParseError(
  113. PCWSTR SourceFilePath,
  114. SIZE_T SourceFileCch,
  115. ULONG LineNumber,
  116. PCWSTR ElementName,
  117. SIZE_T ElementNameCch,
  118. PCWSTR AttributeName,
  119. SIZE_T AttributeNameCch
  120. );
  121. VOID
  122. FusionpLogInvalidAttributeValueParseError(
  123. PCWSTR SourceFilePath,
  124. SIZE_T SourceFileCch,
  125. ULONG LineNumber,
  126. PCWSTR ElementName,
  127. SIZE_T ElementNameCch,
  128. const SXS_ASSEMBLY_IDENTITY_ATTRIBUTE_REFERENCE &rAttribute
  129. );
  130. VOID
  131. FusionpLogAttributeNotAllowedParseError(
  132. PCWSTR SourceFilePath,
  133. SIZE_T SourceFileCch,
  134. ULONG LineNumber,
  135. PCWSTR ElementName,
  136. SIZE_T ElementNameCch,
  137. PCWSTR AttributeName,
  138. SIZE_T AttributeNameCch
  139. );
  140. VOID
  141. FusionpLogWin32ErrorToEventLog(
  142. );
  143. /*--------------------------------------------------------------------------
  144. --------------------------------------------------------------------------*/
  145. typedef CUnicodeString CEventLogString;
  146. /*--------------------------------------------------------------------------
  147. --------------------------------------------------------------------------*/
  148. // sizeof(__int64)*CHAR_BIT is big enough to format an __int64,
  149. // it's enough of an overestimate for negative decimals, 0x prefixed
  150. // hex, and the terminal nul; I don't know about octal.
  151. //
  152. // Using this to log GetLastError may truncate some characters,
  153. // but we'll always have a terminal nul.
  154. typedef CUnicodeStringN<sizeof(ULONGLONG)*CHAR_BIT> CEventLogBuffer;
  155. // but this size is not enough for LastError LogBuffer
  156. typedef CUnicodeStringN<160> CEventLogBufferLastError;
  157. /*--------------------------------------------------------------------------
  158. --------------------------------------------------------------------------*/
  159. class CEventLogInteger : public CEventLogBuffer
  160. {
  161. public:
  162. explicit CEventLogInteger(LONGLONG i);
  163. ~CEventLogInteger() { }
  164. private: // deliberately not implemented
  165. CEventLogInteger();
  166. CEventLogInteger(const CEventLogInteger&);
  167. void operator=(const CEventLogInteger&);
  168. };
  169. /*--------------------------------------------------------------------------
  170. --------------------------------------------------------------------------*/
  171. class CEventLogHex : public CEventLogBuffer
  172. {
  173. public:
  174. explicit CEventLogHex(LONGLONG i);
  175. ~CEventLogHex() { }
  176. LONGLONG m_i;
  177. private: // deliberately not implemented
  178. CEventLogHex();
  179. CEventLogHex(const CEventLogHex&);
  180. void operator=(const CEventLogHex&);
  181. };
  182. /*--------------------------------------------------------------------------
  183. --------------------------------------------------------------------------*/
  184. class CEventLogHResult : public CEventLogBuffer
  185. {
  186. public:
  187. explicit CEventLogHResult(HRESULT hr);
  188. ~CEventLogHResult() { }
  189. HRESULT m_hresult;
  190. private: // deliberately not implemented
  191. CEventLogHResult();
  192. CEventLogHResult(const CEventLogHResult&);
  193. void operator=(const CEventLogHResult&);
  194. };
  195. /*--------------------------------------------------------------------------
  196. --------------------------------------------------------------------------*/
  197. class CEventLogLastError : public CEventLogBufferLastError
  198. {
  199. public:
  200. CEventLogLastError();
  201. CEventLogLastError(DWORD dwLastError);
  202. ~CEventLogLastError() { }
  203. private: // deliberately not implemented
  204. CEventLogLastError(const CEventLogLastError&);
  205. void operator=(const CEventLogLastError&);
  206. };
  207. /*--------------------------------------------------------------------------
  208. --------------------------------------------------------------------------*/
  209. inline CEventLogInteger::CEventLogInteger(LONGLONG i)
  210. {
  211. _i64tow(i, m_rgchBuffer, 10);
  212. Sync();
  213. }
  214. /*--------------------------------------------------------------------------
  215. --------------------------------------------------------------------------*/
  216. inline CEventLogHex::CEventLogHex(LONGLONG i)
  217. {
  218. m_rgchBuffer[0] = '0';
  219. m_rgchBuffer[1] = 'x';
  220. _i64tow(i, &m_rgchBuffer[2], 16);
  221. // CONSIDER _wcsupr(m_psz+2);
  222. Sync();
  223. }
  224. /*--------------------------------------------------------------------------
  225. --------------------------------------------------------------------------*/
  226. inline CEventLogHResult::CEventLogHResult(HRESULT hr)
  227. {
  228. Format(L"hr = %#08lx", static_cast<ULONG>(hr));
  229. }
  230. /*--------------------------------------------------------------------------
  231. --------------------------------------------------------------------------*/
  232. class CEventLogProcessorArchitecture :
  233. public CUnicodeStringN<MAX_PATH + sizeof(int)*CHAR_BIT + 3>
  234. {
  235. public:
  236. ~CEventLogProcessorArchitecture() { }
  237. explicit CEventLogProcessorArchitecture(USHORT usProcessorArchitecture)
  238. {
  239. CSmallStringBuffer buffer;
  240. ::FusionpFormatProcessorArchitecture(usProcessorArchitecture, buffer);
  241. this->Format(L"%d(%ls)", usProcessorArchitecture, static_cast<PCWSTR>(buffer));
  242. }
  243. private:
  244. // deliberately not implemented
  245. CEventLogProcessorArchitecture();
  246. CEventLogProcessorArchitecture(const CEventLogProcessorArchitecture&);
  247. void operator=(const CEventLogProcessorArchitecture&);
  248. };
  249. /*--------------------------------------------------------------------------
  250. --------------------------------------------------------------------------*/
  251. class CEventLogAssemblyVersion : public CUnicodeStringN<4*sizeof(unsigned)*CHAR_BIT+4>
  252. {
  253. public:
  254. ~CEventLogAssemblyVersion() { }
  255. explicit CEventLogAssemblyVersion(const ASSEMBLY_VERSION& av)
  256. {
  257. unsigned major = av.Major;
  258. unsigned minor = av.Minor;
  259. unsigned revision = av.Revision;
  260. unsigned build = av.Build;
  261. Format(L"%u.%u.%u.%u", major, minor, revision, build);
  262. }
  263. private: // deliberately not implemented
  264. CEventLogAssemblyVersion();
  265. CEventLogAssemblyVersion(const CEventLogAssemblyVersion&);
  266. void operator=(const CEventLogAssemblyVersion&);
  267. };
  268. /*--------------------------------------------------------------------------
  269. --------------------------------------------------------------------------*/
  270. class CEventLogLanguageName : public CUnicodeString
  271. {
  272. private:
  273. typedef CUnicodeString base;
  274. public:
  275. ~CEventLogLanguageName() { }
  276. explicit CEventLogLanguageName(LANGID languageId)
  277. {
  278. ::FusionpFormatEnglishLanguageName(languageId, m_buffer);
  279. (*this) = static_cast<PCWSTR>(m_buffer);
  280. }
  281. void operator=(PCWSTR sz)
  282. {
  283. base::operator=(sz);
  284. }
  285. private:
  286. CSmallStringBuffer m_buffer;
  287. // deliberately not implemented
  288. CEventLogLanguageName();
  289. CEventLogLanguageName(const CEventLogLanguageName&);
  290. void operator=(const CEventLogLanguageName&);
  291. };
  292. /*--------------------------------------------------------------------------
  293. --------------------------------------------------------------------------*/
  294. class CEventLogFileCopyCallbackDisposition
  295. {
  296. public:
  297. };
  298. /*--------------------------------------------------------------------------
  299. --------------------------------------------------------------------------*/
  300. /*--------------------------------------------------------------------------
  301. --------------------------------------------------------------------------*/