Source code of Windows XP (NT5)
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.

636 lines
17 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: cs.h
  7. //
  8. // Contents: Cert Server common definitions
  9. //
  10. // History: 25-Jul-96 vich created
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef __CS_H__
  14. #define __CS_H__
  15. #ifndef __CERTLIB_H__
  16. # error -- cs.h should only be included from certlib.h!
  17. #endif
  18. #ifndef DBG
  19. # if defined _DEBUG
  20. # define DBG 1
  21. # else
  22. # define DBG 0
  23. # endif
  24. #endif
  25. #ifndef DBG_CERTSRV
  26. # define DBG_CERTSRV DBG
  27. #endif
  28. // Size of a fixed array:
  29. #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
  30. // _tcslen of a static string:
  31. #define _TSZARRAYSIZE(a) ((sizeof(a)/sizeof((a)[0])) - 1)
  32. #if DBG_CERTSRV
  33. # ifdef DBG_CERTSRV_MESSAGE
  34. # pragma message("building debug extensions\n")
  35. # endif
  36. # define DBG_CERTSRV_DEBUG_PRINT
  37. #endif //DBG_CERTSRV
  38. #define DBG_SS_ERROR 0x00000001
  39. #define DBG_SS_ASSERT 0x00000002
  40. #define DBG_SS_INFO 0x00000004 // or in with any of the below
  41. #define DBG_SS_MODLOAD 0x00000008
  42. #define DBG_SS_NOQUIET 0x00000010
  43. #define DBG_SS_CERTHIER 0x00000100
  44. #define DBG_SS_CERTREQ 0x00000200
  45. #define DBG_SS_CERTUTIL 0x00000400
  46. #define DBG_SS_CERTSRV 0x00000800
  47. #define DBG_SS_CERTADM 0x00001000
  48. #define DBG_SS_CERTCLI 0x00002000
  49. #define DBG_SS_CERTDB 0x00004000
  50. #define DBG_SS_CERTENC 0x00008000
  51. #define DBG_SS_CERTEXIT 0x00010000
  52. #define DBG_SS_CERTIF 0x00020000
  53. #define DBG_SS_CERTMMC 0x00040000
  54. #define DBG_SS_CERTOCM 0x00080000
  55. #define DBG_SS_CERTPOL 0x00100000
  56. #define DBG_SS_CERTVIEW 0x00200000
  57. #define DBG_SS_CERTBCLI 0x00400000
  58. #define DBG_SS_CERTJET 0x00800000
  59. #define DBG_SS_CERTLIBXE 0x10000000 // same as dbgdef.h's DBG_SS_APP
  60. #define DBG_SS_AUDIT 0x20000000
  61. #define DBG_SS_CERTLIB 0x40000000
  62. //#define DBG_SS_SIGN 0x80000000 // don't use: strtol won't set this bit
  63. #define DBG_SS_CERTHIERI (DBG_SS_CERTHIER | DBG_SS_INFO)
  64. #define DBG_SS_CERTREQI (DBG_SS_CERTREQ | DBG_SS_INFO)
  65. #define DBG_SS_CERTUTILI (DBG_SS_CERTUTIL | DBG_SS_INFO)
  66. #define DBG_SS_CERTSRVI (DBG_SS_CERTSRV | DBG_SS_INFO)
  67. #define DBG_SS_CERTADMI (DBG_SS_CERTADM | DBG_SS_INFO)
  68. #define DBG_SS_CERTCLII (DBG_SS_CERTCLI | DBG_SS_INFO)
  69. #define DBG_SS_CERTDBI (DBG_SS_CERTDB | DBG_SS_INFO)
  70. #define DBG_SS_CERTENCI (DBG_SS_CERTENC | DBG_SS_INFO)
  71. #define DBG_SS_CERTEXITI (DBG_SS_CERTEXIT | DBG_SS_INFO)
  72. #define DBG_SS_CERTIFI (DBG_SS_CERTIF | DBG_SS_INFO)
  73. #define DBG_SS_CERTMMCI (DBG_SS_CERTMMC | DBG_SS_INFO)
  74. #define DBG_SS_CERTOCMI (DBG_SS_CERTOCM | DBG_SS_INFO)
  75. #define DBG_SS_CERTPOLI (DBG_SS_CERTPOL | DBG_SS_INFO)
  76. #define DBG_SS_CERTVIEWI (DBG_SS_CERTVIEW | DBG_SS_INFO)
  77. #define DBG_SS_CERTBCLII (DBG_SS_CERTBCLI | DBG_SS_INFO)
  78. #define DBG_SS_CERTJETI (DBG_SS_CERTJET | DBG_SS_INFO)
  79. #define DBG_SS_CERTLIBI (DBG_SS_CERTLIB | DBG_SS_INFO)
  80. // begin_certsrv
  81. // VerifyRequest() return values
  82. #define VR_PENDING 0 // request will be accepted or denied later
  83. #define VR_INSTANT_OK 1 // request was accepted
  84. #define VR_INSTANT_BAD 2 // request was rejected
  85. // end_certsrv
  86. // Certificate types:
  87. #define CERT_TYPE_NONE 0 // cannot create certificates
  88. #define CERT_TYPE_X509 1 // CCITT x509 certificates
  89. #define CERT_TYPE_SDSI 2 // SDSI certificates
  90. #define CERT_TYPE_PGP 3 // PGP certificates
  91. #if DBG_CERTSRV
  92. # define DBGCODE(a) a
  93. # define DBGPARM0(parm) parm
  94. # define DBGPARM(parm) , parm
  95. #else // DBG_CERTSRV
  96. # define DBGCODE(a)
  97. # define DBGPARM0(parm)
  98. # define DBGPARM(parm)
  99. #endif // DBG_CERTSRV
  100. #define wprintf myConsolePrintf
  101. #define printf Use_wprintf_Instead_Of_printf
  102. #define LdapMapErrorToWin32 Use_myHLdapError_Instead_Of_LdapMapErrorToWin32
  103. #if 0 == i386
  104. # define IOBUNALIGNED(pf) ((sizeof(WCHAR) - 1) & (DWORD) (ULONG_PTR) (pf)->_ptr)
  105. # define ALIGNIOB(pf) \
  106. { \
  107. if (IOBUNALIGNED(pf)) \
  108. { \
  109. fflush(pf); /* fails when running as a service */ \
  110. } \
  111. if (IOBUNALIGNED(pf)) \
  112. { \
  113. fprintf(pf, " "); \
  114. fflush(pf); \
  115. } \
  116. }
  117. #else
  118. # define IOBUNALIGNED(pf) FALSE
  119. # define ALIGNIOB(pf)
  120. #endif
  121. HRESULT myHExceptionCode(IN EXCEPTION_POINTERS const *pep);
  122. #ifdef DBG_CERTSRV_DEBUG_PRINT
  123. typedef VOID (WINAPI FNPRINTERROR)(
  124. IN char const *pszMessage,
  125. OPTIONAL IN WCHAR const *pwszData,
  126. IN char const *pszFile,
  127. IN DWORD dwLine,
  128. IN HRESULT hr,
  129. IN HRESULT hrquiet);
  130. FNPRINTERROR CSPrintError;
  131. typedef VOID (WINAPI FNPRINTERRORINT)(
  132. IN char const *pszMessage,
  133. IN DWORD dwData,
  134. IN char const *pszFile,
  135. IN DWORD dwLine,
  136. IN HRESULT hr,
  137. IN HRESULT hrquiet);
  138. FNPRINTERRORINT CSPrintErrorInt;
  139. typedef VOID (WINAPI FNPRINTASSERT)(
  140. IN char const *pszFailedAssertion,
  141. IN char const *pszFileName,
  142. IN DWORD dwLine,
  143. IN char const *pszMessage);
  144. FNPRINTASSERT CSPrintAssert;
  145. #define __FILEDIR__ __DIR__ "\\" __FILE__
  146. # define CSASSERT(exp) CSASSERTMSG(NULL, exp)
  147. # define CSASSERTMSG(pszmsg, exp) \
  148. if (!(exp)) \
  149. CSPrintAssert(#exp, __FILEDIR__, __LINE__, (pszmsg))
  150. # define DBGERRORPRINT(pszMessage, pwszData, dwLine, hr, hrquiet) \
  151. CSPrintError((pszMessage), (pwszData), __FILEDIR__, (dwLine), (hr), (hrquiet))
  152. # define DBGERRORPRINTINT(pszMessage, dwData, dwLine, hr, hrquiet) \
  153. CSPrintErrorInt((pszMessage), (dwData), __FILEDIR__, (dwLine), (hr), (hrquiet))
  154. # define myHEXCEPTIONCODE() myHExceptionCodePrint(GetExceptionInformation(), __FILEDIR__, __dwFILE__, __LINE__)
  155. #else // DBG_CERTSRV_DEBUG_PRINT
  156. # define CSASSERT(exp)
  157. # define CSASSERTMSG(msg, exp)
  158. # define DBGERRORPRINT(pszMessage, pwszData, dwLine, hr, hrquiet)
  159. # define DBGERRORPRINTINT(pszMessage, dwData, dwLine, hr, hrquiet)
  160. # define myHEXCEPTIONCODE() myHExceptionCodePrint(GetExceptionInformation(), NULL, __dwFILE__, __LINE__)
  161. #endif // DBG_CERTSRV_DEBUG_PRINT
  162. typedef VOID (FNLOGSTRING)(
  163. IN char const *pszString);
  164. typedef VOID (FNLOGEXCEPTION)(
  165. IN HRESULT hrExcept,
  166. IN EXCEPTION_POINTERS const *pep,
  167. OPTIONAL IN char const *pszFileName,
  168. IN DWORD dwFile,
  169. IN DWORD dwLine);
  170. HRESULT myHExceptionCodePrint(
  171. IN EXCEPTION_POINTERS const *pep,
  172. OPTIONAL IN char const *pszFile,
  173. IN DWORD dwFile,
  174. IN DWORD dwLine);
  175. VOID myLogExceptionInit(
  176. IN FNLOGEXCEPTION *pfnLogException);
  177. #define CBLOGMAXAPPEND (512 * 1024)
  178. #ifdef DBG_CERTSRV_DEBUG_PRINT
  179. # define DBGPRINTINIT(pszFile) DbgPrintfInit(pszFile)
  180. # define DBGLOGSTRINGINIT(pfnLogString) DbgLogStringInit(pfnLogString)
  181. # define DBGPRINT(a) DbgPrintf a
  182. # define DBGDUMPHEX(a) mydbgDumpHex a
  183. # define CONSOLEPRINT0(a) DBGPRINT(a)
  184. # define CONSOLEPRINT1(a) DBGPRINT(a)
  185. # define CONSOLEPRINT2(a) DBGPRINT(a)
  186. # define CONSOLEPRINT3(a) DBGPRINT(a)
  187. # define CONSOLEPRINT4(a) DBGPRINT(a)
  188. # define CONSOLEPRINT5(a) DBGPRINT(a)
  189. # define CONSOLEPRINT6(a) DBGPRINT(a)
  190. # define CONSOLEPRINT7(a) DBGPRINT(a)
  191. # define CONSOLEPRINT8(a) DBGPRINT(a)
  192. int WINAPIV DbgPrintf(DWORD dwSubSysId, char const *pszfmt, ...);
  193. VOID DbgPrintfInit(OPTIONAL IN CHAR const *pszFile);
  194. BOOL DbgIsSSActive(DWORD dwSSIn);
  195. VOID DbgLogStringInit(FNLOGSTRING *pfnLog);
  196. #else
  197. # define DBGPRINTINIT(pszFile)
  198. # define DBGLOGSTRINGINIT(pfnLogString)
  199. # define DBGPRINT(a)
  200. # define DBGDUMPHEX(a)
  201. # define CONSOLEPRINT0(a) _CONSOLEPRINT0 a
  202. # define CONSOLEPRINT1(a) _CONSOLEPRINT1 a
  203. # define CONSOLEPRINT2(a) _CONSOLEPRINT2 a
  204. # define CONSOLEPRINT3(a) _CONSOLEPRINT3 a
  205. # define CONSOLEPRINT4(a) _CONSOLEPRINT4 a
  206. # define CONSOLEPRINT5(a) _CONSOLEPRINT5 a
  207. # define CONSOLEPRINT6(a) _CONSOLEPRINT6 a
  208. # define CONSOLEPRINT7(a) _CONSOLEPRINT7 a
  209. # define CONSOLEPRINT8(a) _CONSOLEPRINT8 a
  210. # define _CONSOLEPRINT0(mask, fmt) wprintf(TEXT(fmt))
  211. # define _CONSOLEPRINT1(mask, fmt, a1) wprintf(TEXT(fmt), (a1))
  212. # define _CONSOLEPRINT2(mask, fmt, a1, a2) wprintf(TEXT(fmt), (a1), (a2))
  213. # define _CONSOLEPRINT3(mask, fmt, a1, a2, a3) \
  214. wprintf(TEXT(fmt), (a1), (a2), (a3))
  215. # define _CONSOLEPRINT4(mask, fmt, a1, a2, a3, a4) \
  216. wprintf(TEXT(fmt), (a1), (a2), (a3), (a4))
  217. # define _CONSOLEPRINT5(mask, fmt, a1, a2, a3, a4, a5) \
  218. wprintf(TEXT(fmt), (a1), (a2), (a3), (a4), (a5))
  219. # define _CONSOLEPRINT6(mask, fmt, a1, a2, a3, a4, a5, a6) \
  220. wprintf(TEXT(fmt), (a1), (a2), (a3), (a4), (a5), (a6))
  221. # define _CONSOLEPRINT7(mask, fmt, a1, a2, a3, a4, a5, a6, a7) \
  222. wprintf(TEXT(fmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7))
  223. # define _CONSOLEPRINT8(mask, fmt, a1, a2, a3, a4, a5, a6, a7, a8) \
  224. wprintf(TEXT(fmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8))
  225. #endif
  226. #if 1 < DBG_CERTSRV
  227. # define DBGTRACE(a) DbgPrintf a
  228. #else
  229. # define DBGTRACE(a)
  230. #endif
  231. #define _LeaveError(hr, pszMessage) \
  232. _LeaveErrorStr2((hr), (pszMessage), NULL, 0)
  233. #define _LeaveError2(hr, pszMessage, hrquiet) \
  234. _LeaveErrorStr2((hr), (pszMessage), NULL, (hrquiet))
  235. #define _LeaveErrorStr(hr, pszMessage, pwszData) \
  236. _LeaveErrorStr2((hr), (pszMessage), (pwszData), 0)
  237. #define _LeaveError3(hr, pszMessage, hrquiet, hrquiet2) \
  238. _LeaveErrorStr3((hr), (pszMessage), NULL, (hrquiet), (hrquiet2))
  239. #define _LeaveErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  240. { \
  241. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  242. __leave; \
  243. }
  244. #define _LeaveErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  245. { \
  246. if ((hrquiet2) != (hr)) \
  247. { \
  248. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  249. } \
  250. __leave; \
  251. }
  252. #define _LeaveIfError(hr, pszMessage) \
  253. _LeaveIfErrorStr2((hr), (pszMessage), NULL, 0)
  254. #define _LeaveIfError2(hr, pszMessage, hrquiet) \
  255. _LeaveIfErrorStr2((hr), (pszMessage), NULL, (hrquiet))
  256. #define _LeaveIfErrorStr(hr, pszMessage, pwszData) \
  257. _LeaveIfErrorStr2((hr), (pszMessage), (pwszData), 0)
  258. #define _LeaveIfError3(hr, pszMessage, hrquiet, hrquiet2) \
  259. _LeaveIfErrorStr3((hr), (pszMessage), NULL, (hrquiet), (hrquiet2))
  260. #define _LeaveIfErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  261. { \
  262. if (S_OK != (hr)) \
  263. { \
  264. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  265. __leave; \
  266. } \
  267. }
  268. #define _LeaveIfErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  269. { \
  270. if (S_OK != (hr)) \
  271. { \
  272. if ((hrquiet2) != (hr)) \
  273. { \
  274. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  275. } \
  276. __leave; \
  277. } \
  278. }
  279. #define _PrintError(hr, pszMessage) \
  280. _PrintErrorStr2((hr), (pszMessage), NULL, 0)
  281. #define _PrintError2(hr, pszMessage, hrquiet) \
  282. _PrintErrorStr2((hr), (pszMessage), NULL, (hrquiet))
  283. #define _PrintErrorStr(hr, pszMessage, pwszData) \
  284. _PrintErrorStr2((hr), (pszMessage), (pwszData), 0)
  285. #define _PrintError3(hr, pszMessage, hrquiet, hrquiet2) \
  286. _PrintErrorStr3((hr), (pszMessage), NULL, (hrquiet), (hrquiet2))
  287. #define _PrintErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  288. { \
  289. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  290. }
  291. #define _PrintErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  292. { \
  293. if ((hrquiet2) != (hr)) \
  294. { \
  295. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  296. } \
  297. }
  298. #define _PrintIfError(hr, pszMessage) \
  299. _PrintIfErrorStr2((hr), (pszMessage), NULL, 0)
  300. #define _PrintIfError2(hr, pszMessage, hrquiet) \
  301. _PrintIfErrorStr2((hr), (pszMessage), NULL, (hrquiet))
  302. #define _PrintIfErrorStr(hr, pszMessage, pwszData) \
  303. _PrintIfErrorStr2((hr), (pszMessage), (pwszData), 0)
  304. #define _PrintIfError3(hr, pszMessage, hrquiet, hrquiet2) \
  305. _PrintIfErrorStr3((hr), (pszMessage), NULL, (hrquiet), (hrquiet2))
  306. #define _PrintIfError4(hr, pszMessage, hrquiet, hrquiet2, hrquiet3) \
  307. _PrintIfErrorStr4((hr), (pszMessage), NULL, (hrquiet), (hrquiet2), (hrquiet3))
  308. #define _PrintIfErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  309. { \
  310. if (S_OK != (hr)) \
  311. { \
  312. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  313. } \
  314. }
  315. #define _PrintIfErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  316. { \
  317. if (S_OK != (hr)) \
  318. { \
  319. if ((hrquiet2) != (hr)) \
  320. { \
  321. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  322. } \
  323. } \
  324. }
  325. #define _PrintIfErrorStr4(hr, pszMessage, pwszData, hrquiet, hrquiet2, hrquiet3) \
  326. { \
  327. if (S_OK != (hr)) \
  328. { \
  329. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  330. { \
  331. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  332. } \
  333. } \
  334. }
  335. #define _JumpError(hr, label, pszMessage) \
  336. _JumpErrorStr2((hr), label, (pszMessage), NULL, 0)
  337. #define _JumpError2(hr, label, pszMessage, hrquiet) \
  338. _JumpErrorStr2((hr), label, (pszMessage), NULL, (hrquiet))
  339. #define _JumpErrorStr(hr, label, pszMessage, pwszData) \
  340. _JumpErrorStr2((hr), label, (pszMessage), (pwszData), 0)
  341. #define _JumpErrorStr2(hr, label, pszMessage, pwszData, hrquiet) \
  342. { \
  343. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  344. goto label; \
  345. }
  346. #define _JumpErrorStr3(hr, label, pszMessage, pwszData, hrquiet, hrquiet2) \
  347. { \
  348. if ((hrquiet2) != (hr)) \
  349. { \
  350. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  351. } \
  352. goto label; \
  353. }
  354. #define _JumpIfError(hr, label, pszMessage) \
  355. _JumpIfErrorStr2((hr), label, (pszMessage), NULL, 0)
  356. #define _JumpIfError2(hr, label, pszMessage, hrquiet) \
  357. _JumpIfErrorStr2((hr), label, (pszMessage), NULL, (hrquiet))
  358. #define _JumpIfErrorStr(hr, label, pszMessage, pwszData) \
  359. _JumpIfErrorStr2((hr), label, (pszMessage), (pwszData), 0)
  360. #define _JumpIfError3(hr, label, pszMessage, hrquiet, hrquiet2) \
  361. _JumpIfErrorStr3((hr), label, (pszMessage), NULL, (hrquiet), (hrquiet2))
  362. #define _JumpIfError4(hr, label, pszMessage, hrquiet, hrquiet2, hrquiet3) \
  363. _JumpIfErrorStr4((hr), label, (pszMessage), NULL, (hrquiet), (hrquiet2), (hrquiet3))
  364. #define _JumpIfErrorStr2(hr, label, pszMessage, pwszData, hrquiet) \
  365. { \
  366. if (S_OK != (hr)) \
  367. { \
  368. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  369. goto label; \
  370. } \
  371. }
  372. #define _JumpIfErrorStr3(hr, label, pszMessage, pwszData, hrquiet, hrquiet2) \
  373. { \
  374. if (S_OK != (hr)) \
  375. { \
  376. if ((hrquiet2) != (hr)) \
  377. { \
  378. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  379. } \
  380. goto label; \
  381. } \
  382. }
  383. #define _JumpIfErrorStr4(hr, label, pszMessage, pwszData, hrquiet, hrquiet2, hrquiet3) \
  384. { \
  385. if (S_OK != (hr)) \
  386. { \
  387. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  388. { \
  389. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  390. } \
  391. goto label; \
  392. } \
  393. }
  394. #define _JumpIfWin32Error(err, label, pszMessage) \
  395. { \
  396. if (ERROR_SUCCESS != (err)) \
  397. { \
  398. hr = HRESULT_FROM_WIN32((err)); \
  399. DBGERRORPRINTLINESTR2((pszMessage), NULL, hr, 0); \
  400. goto label; \
  401. } \
  402. }
  403. #define _JumpIfErrorNotSpecific(hr, label, pszMessage, hrquiet) \
  404. { \
  405. if (S_OK != (hr)) \
  406. { \
  407. DBGERRORPRINTLINESTR2((pszMessage), NULL, (hr), (hrquiet)); \
  408. if ((hrquiet) != (hr)) \
  409. { \
  410. goto label; \
  411. } \
  412. } \
  413. }
  414. #define _JumpIfAllocFailed(ptr, label) \
  415. { \
  416. if ((ptr) == NULL) \
  417. { \
  418. hr = E_OUTOFMEMORY; \
  419. DBGERRORPRINTLINE("allocation error", (hr)) \
  420. goto label; \
  421. } \
  422. }
  423. #define DBGERRORPRINTLINE(pszMessage, hr) \
  424. DBGERRORPRINTLINESTR2((pszMessage), NULL, (hr), 0)
  425. #define DBGERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  426. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), 0)
  427. #define DBGERRORPRINTLINEINT(pszMessage, dwData, hr) \
  428. DBGERRORPRINTLINEINT2((pszMessage), (dwData), (hr), 0)
  429. #define DBGERRORPRINTLINESTR2(pszMessage, pwszData, hr, hrquiet) \
  430. { \
  431. DBGERRORPRINT((pszMessage), (pwszData), __LINE__, (hr), (hrquiet)); \
  432. }
  433. #define DBGERRORPRINTLINEINT2(pszMessage, dwData, hr, hrquiet) \
  434. { \
  435. DBGERRORPRINTINT((pszMessage), (dwData), __LINE__, (hr), (hrquiet)); \
  436. }
  437. #define Add2Ptr(pb, cb) ((VOID *) ((BYTE *) (pb) + (ULONG_PTR) (cb)))
  438. #define Add2ConstPtr(pb, cb) \
  439. ((VOID const *) ((BYTE const *) (pb) + (ULONG_PTR) (cb)))
  440. #define WSZARRAYSIZE(a) csWSZARRAYSIZE(a, _TSZARRAYSIZE(a))
  441. #define SZARRAYSIZE(a) csSZARRAYSIZE(a, _TSZARRAYSIZE(a))
  442. #ifdef UNICODE
  443. #define TSZARRAYSIZE(a) WSZARRAYSIZE(a)
  444. #else
  445. #define TSZARRAYSIZE(a) SZARRAYSIZE(a)
  446. #endif
  447. __inline DWORD
  448. csWSZARRAYSIZE(
  449. IN WCHAR const *pwsz,
  450. IN DWORD cwc)
  451. {
  452. CSASSERT(wcslen(pwsz) == cwc);
  453. return(cwc);
  454. }
  455. __inline DWORD
  456. csSZARRAYSIZE(
  457. IN CHAR const *psz,
  458. IN DWORD cch)
  459. {
  460. CSASSERT(strlen(psz) == cch);
  461. return(cch);
  462. }
  463. //
  464. // VOID
  465. // InitializeListHead(
  466. // PLIST_ENTRY ListHead
  467. // );
  468. //
  469. #define InitializeListHead(ListHead) (\
  470. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  471. //
  472. // VOID
  473. // InsertTailList(
  474. // PLIST_ENTRY ListHead,
  475. // PLIST_ENTRY Entry
  476. // );
  477. //
  478. #define InsertTailList(ListHead,Entry) {\
  479. PLIST_ENTRY _EX_Blink;\
  480. PLIST_ENTRY _EX_ListHead;\
  481. _EX_ListHead = (ListHead);\
  482. _EX_Blink = _EX_ListHead->Blink;\
  483. (Entry)->Flink = _EX_ListHead;\
  484. (Entry)->Blink = _EX_Blink;\
  485. _EX_Blink->Flink = (Entry);\
  486. _EX_ListHead->Blink = (Entry);\
  487. }
  488. //
  489. // VOID
  490. // RemoveEntryList(
  491. // PLIST_ENTRY Entry
  492. // );
  493. //
  494. #define RemoveEntryList(Entry) {\
  495. PLIST_ENTRY _EX_Blink;\
  496. PLIST_ENTRY _EX_Flink;\
  497. _EX_Flink = (Entry)->Flink;\
  498. _EX_Blink = (Entry)->Blink;\
  499. _EX_Blink->Flink = _EX_Flink;\
  500. _EX_Flink->Blink = _EX_Blink;\
  501. }
  502. #endif // __CS_H__