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.

402 lines
8.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: celib.h
  8. //
  9. // Contents: helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #ifndef __CELIB_H__
  13. #define __CELIB_H__
  14. #include <stdio.h>
  15. #define CENCODEMAX (64 * 1024)
  16. // Bitmap manipulation routines. Fetch or set a bit, given a base and index.
  17. #define GETBIT(pb, i) ((pb)[(i) / 8] & (1 << ((i) % 8)))
  18. #define SETBIT(pb, i) ((pb)[(i) / 8] |= (1 << ((i) % 8)))
  19. #define CLEARBIT(pb, i) ((pb)[(i) / 8] &= ~(1 << ((i) % 8)))
  20. #define BITSTOBYTES(b) ((int)(((b) + 7) / 8))
  21. // Size of a fixed array:
  22. #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
  23. // wcslen of a static string:
  24. #define WSZARRAYSIZE(a) ((sizeof(a)/sizeof((a)[0])) - 1)
  25. #define wszCERTENROLLSHAREPATH L"CertSrv\\CertEnroll"
  26. #define cwcHRESULTSTRING 40
  27. #define SAFE_SUBTRACT_POINTERS(p1, p2) \
  28. (assert(sizeof((*p1)) == sizeof(*(p2))), (DWORD)((p1) - (p2)))
  29. #define printf Use_wprintf_Instead_Of_printf
  30. #define _LeaveError(hr, pszMessage) \
  31. _LeaveErrorStr2((hr), (pszMessage), NULL, S_OK)
  32. #define _LeaveError2(hr, pszMessage, hr2) \
  33. _LeaveErrorStr2((hr), (pszMessage), NULL, (hr2))
  34. #define _LeaveErrorStr(hr, pszMessage, pwszData) \
  35. _LeaveErrorStr2((hr), (pszMessage), (pwszData), S_OK)
  36. #define _LeaveErrorStr2(hr, pszMessage, pwszData, hr2) \
  37. { \
  38. ceERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  39. __leave; \
  40. }
  41. #define _LeaveIfError(hr, pszMessage) \
  42. _LeaveIfErrorStr2((hr), (pszMessage), NULL, S_OK)
  43. #define _LeaveIfError2(hr, pszMessage, hr2) \
  44. _LeaveIfErrorStr2((hr), (pszMessage), NULL, (hr2))
  45. #define _LeaveIfErrorStr(hr, pszMessage, pwszData) \
  46. _LeaveIfErrorStr2((hr), (pszMessage), (pwszData), S_OK)
  47. #define _LeaveIfErrorStr2(hr, pszMessage, pwszData, hr2) \
  48. { \
  49. if (S_OK != (hr)) \
  50. { \
  51. ceERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  52. __leave; \
  53. } \
  54. }
  55. #define _PrintErrorStr(hr, pszMessage, pwsz) \
  56. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr))
  57. #define _PrintErrorStr2(hr, pszMessage, pwsz, hr2) \
  58. _PrintErrorStr((hr), (pszMessage), (pwsz))
  59. #define _PrintError2(hr, pszMessage, hr2) \
  60. _PrintErrorStr((hr), (pszMessage), NULL)
  61. #define _PrintError(hr, pszMessage) \
  62. _PrintErrorStr((hr), (pszMessage), NULL)
  63. #define _PrintIfErrorStr(hr, pszMessage, pwsz) \
  64. { \
  65. if (S_OK != (hr)) \
  66. { \
  67. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr)); \
  68. } \
  69. }
  70. #define _PrintIfErrorStr2(hr, pszMessage, pwsz, hr2) \
  71. _PrintIfErrorStr((hr), (pszMessage), (pwsz))
  72. #define _PrintIfError2(hr, pszMessage, hr2) \
  73. _PrintIfErrorStr((hr), (pszMessage), NULL)
  74. #define _PrintIfError(hr, pszMessage) \
  75. _PrintIfErrorStr((hr), (pszMessage), NULL)
  76. #define _JumpErrorStr(hr, label, pszMessage, pwsz) \
  77. _JumpError((hr), label, (pszMessage))
  78. #define _JumpError(hr, label, pszMessage) \
  79. { \
  80. ceERRORPRINTLINESTR((pszMessage), NULL, (hr)); \
  81. goto label; \
  82. }
  83. #define _JumpIfErrorStr(hr, label, pszMessage, pwsz) \
  84. { \
  85. if (S_OK != (hr)) \
  86. { \
  87. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr)); \
  88. goto label; \
  89. } \
  90. }
  91. #define _JumpIfErrorStr2(hr, label, pszMessage, pwsz, hr2) \
  92. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  93. #define _JumpIfError2(hr, label, pszMessage, hr2) \
  94. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  95. #define _JumpIfError(hr, label, pszMessage) \
  96. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  97. #define ceERRORPRINTLINE(pszMessage, hr) \
  98. ceErrorPrintLine(__FILE__, __LINE__, (pszMessage), NULL, (hr))
  99. #define ceERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  100. ceErrorPrintLine(__FILE__, __LINE__, (pszMessage), (pwszData), (hr))
  101. #define DBGPRINT(a) ceDbgPrintf a
  102. int WINAPIV ceDbgPrintf(BOOL fDebug, char const *pszfmt, ...);
  103. VOID
  104. ceErrorPrintLine(
  105. IN char const *pszFile,
  106. IN DWORD line,
  107. IN char const *pszMessage,
  108. IN WCHAR const *pwszData,
  109. IN HRESULT hr);
  110. HRESULT
  111. ceHLastError(VOID);
  112. HRESULT
  113. ceHError(
  114. IN HRESULT hr);
  115. #define chLBRACE '{'
  116. #define chRBRACE '}'
  117. #define szLBRACE "{"
  118. #define szRBRACE "}"
  119. #define wcLBRACE L'{'
  120. #define wcRBRACE L'}'
  121. #define wszLBRACE L"{"
  122. #define wszRBRACE L"}"
  123. #define chLPAREN '('
  124. #define chRPAREN ')'
  125. #define szLPAREN "("
  126. #define szRPAREN ")"
  127. #define wcLPAREN L'('
  128. #define wcRPAREN L')'
  129. #define wszLPAREN L"("
  130. #define wszRPAREN L")"
  131. // Constants chosen to avoid DWORD overflow:
  132. #define CVT_WEEKS (7 * CVT_DAYS)
  133. #define CVT_DAYS (24 * CVT_HOURS)
  134. #define CVT_HOURS (60 * CVT_MINUTES)
  135. #define CVT_MINUTES (60 * CVT_SECONDS)
  136. #define CVT_SECONDS (1)
  137. #define CVT_BASE (1000 * 1000 * 10)
  138. enum ENUM_PERIOD
  139. {
  140. ENUM_PERIOD_INVALID = -1,
  141. ENUM_PERIOD_SECONDS = 0,
  142. ENUM_PERIOD_MINUTES,
  143. ENUM_PERIOD_HOURS,
  144. ENUM_PERIOD_DAYS,
  145. ENUM_PERIOD_WEEKS,
  146. ENUM_PERIOD_MONTHS,
  147. ENUM_PERIOD_YEARS
  148. };
  149. typedef struct _LLFILETIME
  150. {
  151. union {
  152. LONGLONG ll;
  153. FILETIME ft;
  154. };
  155. } LLFILETIME;
  156. __inline VOID
  157. ceAddToFileTime(
  158. IN OUT FILETIME *pft,
  159. IN LONGLONG ll)
  160. {
  161. LLFILETIME llft;
  162. llft.ft = *pft;
  163. llft.ll += ll;
  164. *pft = llft.ft;
  165. }
  166. __inline LONGLONG
  167. ceSubtractFileTimes(
  168. IN FILETIME const *pft1,
  169. IN FILETIME const *pft2)
  170. {
  171. LLFILETIME llft1;
  172. LLFILETIME llft2;
  173. llft1.ft = *pft1;
  174. llft2.ft = *pft2;
  175. return(llft1.ll - llft2.ll);
  176. }
  177. HRESULT
  178. ceMakeExprDate(
  179. IN OUT DATE *pDate,
  180. IN LONG lDelta,
  181. IN enum ENUM_PERIOD enumPeriod);
  182. HRESULT
  183. ceTranslatePeriodUnits(
  184. IN WCHAR const *pwszPeriod,
  185. IN LONG lCount,
  186. OUT enum ENUM_PERIOD *penumPeriod,
  187. OUT LONG *plCount);
  188. WCHAR const *
  189. ceGetOIDNameA(
  190. IN char const *pszObjId);
  191. WCHAR const *
  192. ceGetOIDName(
  193. IN WCHAR const *pwszObjId);
  194. BOOL
  195. ceDecodeObject(
  196. IN DWORD dwEncodingType,
  197. IN LPCSTR lpszStructType,
  198. IN BYTE const *pbEncoded,
  199. IN DWORD cbEncoded,
  200. IN BOOL fCoTaskMemAlloc,
  201. OUT VOID **ppvStructInfo,
  202. OUT DWORD *pcbStructInfo);
  203. BOOL
  204. ceEncodeObject(
  205. DWORD dwEncodingType,
  206. IN LPCSTR lpszStructType,
  207. IN VOID const *pvStructInfo,
  208. IN DWORD dwFlags,
  209. IN BOOL fCoTaskMemAlloc,
  210. OUT BYTE **ppbEncoded,
  211. OUT DWORD *pcbEncoded);
  212. WCHAR *
  213. ceDuplicateString(
  214. IN WCHAR const *pwsz);
  215. BOOL
  216. ceConvertWszToSz(
  217. OUT char **ppsz,
  218. IN WCHAR const *pwc,
  219. IN LONG cb);
  220. BOOL
  221. ceConvertWszToBstr(
  222. OUT BSTR *pbstr,
  223. IN WCHAR const *pwc,
  224. IN LONG cb);
  225. BOOL
  226. ceConvertSzToWsz(
  227. OUT WCHAR **ppwsz,
  228. IN char const *pch,
  229. IN LONG cch);
  230. BOOL
  231. ceConvertSzToBstr(
  232. OUT BSTR *pbstr,
  233. IN CHAR const *pch,
  234. IN LONG cch);
  235. VOID
  236. ceFreeBstr(
  237. IN OUT BSTR *pstr);
  238. HRESULT
  239. ceDateToFileTime(
  240. IN DATE const *pDate,
  241. OUT FILETIME *pft);
  242. HRESULT
  243. ceFileTimeToDate(
  244. IN FILETIME const *pft,
  245. OUT DATE *pDate);
  246. HRESULT
  247. ceVerifyObjId(
  248. IN WCHAR const *pwszObjId);
  249. HRESULT
  250. ceVerifyAltNameString(
  251. IN LONG NameChoice,
  252. IN WCHAR const *pwszName);
  253. HRESULT
  254. ceDispatchSetErrorInfo(
  255. IN HRESULT hrError,
  256. IN WCHAR const *pwszDescription,
  257. OPTIONAL IN WCHAR const *pwszProgId,
  258. OPTIONAL IN IID const *piid);
  259. VOID
  260. ceInitErrorMessageText(
  261. IN HMODULE hMod,
  262. IN DWORD idsUnexpected,
  263. IN DWORD idsUnknownErrorCode); // L"Error %ws %ws"
  264. WCHAR *
  265. ceGetErrorMessageText(
  266. IN HRESULT hr,
  267. IN BOOL fHResultString);
  268. WCHAR const *
  269. ceHResultToString(
  270. IN OUT WCHAR *awchr,
  271. IN HRESULT hr);
  272. #define cwcFILENAMESUFFIXMAX 20
  273. #define cwcSUFFIXMAX (1 + 5 + 1) // five decimal digits plus parentheses
  274. #define wszFCSAPARM_SERVERDNSNAME L"%1"
  275. #define wszFCSAPARM_SERVERSHORTNAME L"%2"
  276. #define wszFCSAPARM_SANITIZEDCANAME L"%3"
  277. #define wszFCSAPARM_CERTFILENAMESUFFIX L"%4"
  278. #define wszFCSAPARM_DOMAINDN L"%5"
  279. #define wszFCSAPARM_CONFIGDN L"%6"
  280. #define wszFCSAPARM_SANITIZEDCANAMEHASH L"%7"
  281. #define wszFCSAPARM_CRLFILENAMESUFFIX L"%8"
  282. #define wszFCSAPARM_CRLDELTAFILENAMESUFFIX L"%9"
  283. #define wszFCSAPARM_DSCRLATTRIBUTE L"%10"
  284. #define wszFCSAPARM_DSCACERTATTRIBUTE L"%11"
  285. HRESULT
  286. ceFormatCertsrvStringArray(
  287. IN BOOL fURL,
  288. IN LPCWSTR pwszServerName_p1_2,
  289. IN LPCWSTR pwszSanitizedName_p3_7,
  290. IN DWORD iCert_p4,
  291. IN LPCWSTR pwszDomainDN_p5,
  292. IN LPCWSTR pwszConfigDN_p6,
  293. IN DWORD iCRL_p8,
  294. IN BOOL fDeltaCRL_p9,
  295. IN BOOL fDSAttrib_p10_11,
  296. IN DWORD cStrings,
  297. IN LPCWSTR *apwszStringsIn,
  298. OUT LPWSTR *apwszStringsOut);
  299. HRESULT
  300. ceInternetCanonicalizeUrl(
  301. IN WCHAR const *pwszIn,
  302. OUT WCHAR **ppwszOut);
  303. int
  304. ceWtoI(
  305. IN WCHAR const *pwszDigitString,
  306. OUT BOOL *pfValid);
  307. HRESULT
  308. ceIsConfigLocal(
  309. IN WCHAR const *pwszConfig,
  310. OPTIONAL OUT WCHAR **ppwszMachine,
  311. OUT BOOL *pfLocal);
  312. #endif // __CELIB_H__