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.

409 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. util.h
  5. Abstract:
  6. Header for util.cxx
  7. Author:
  8. Richard L Firth (rfirth) 31-Oct-1994
  9. Revision History:
  10. 31-Oct-1994 rfirth
  11. Created
  12. --*/
  13. #if !defined(__UTIL_H__)
  14. #define __UTIL_H__
  15. #if defined(__cplusplus)
  16. extern "C" {
  17. #endif
  18. //
  19. // manifests
  20. //
  21. #define PLATFORM_TYPE_UNKNOWN ((DWORD)(-1))
  22. #define PLATFORM_TYPE_WIN95 ((DWORD)(0))
  23. #define PLATFORM_TYPE_WINNT ((DWORD)(1))
  24. #define PLATFORM_TYPE_UNIX ((DWORD)(2))
  25. #define PLATFORM_SUPPORTS_UNICODE 0x00000001
  26. // max header allowed by wininet in the cache
  27. #define MAX_HEADER_SUPPORTED 2048
  28. #define MAX_USERNAME 128
  29. #define DEFAULT_MAX_EXTENSION_LENGTH 8
  30. //
  31. // types
  32. //
  33. //
  34. // TRI_STATE - for places where we need to differentiate between TRUE/FALSE and
  35. // uninitialized
  36. //
  37. typedef enum {
  38. TRI_STATE_UNKNOWN = -1,
  39. TRI_STATE_FALSE = 0,
  40. TRI_STATE_TRUE = 1
  41. } TRI_STATE;
  42. //
  43. // DLL_ENTRY_POINT - maps a name to an entry point in a DLL
  44. //
  45. typedef struct {
  46. LPSTR lpszProcedureName;
  47. FARPROC * lplpfnProcedure;
  48. } DLL_ENTRY_POINT, * LPDLL_ENTRY_POINT;
  49. //
  50. // DLL_INFO - used to dynamically load/unload libraries
  51. //
  52. typedef struct {
  53. LPSTR lpszDllName;
  54. HINSTANCE hModule;
  55. LONG LoadCount;
  56. DWORD dwNumberOfEntryPoints;
  57. LPDLL_ENTRY_POINT lpEntryPoints;
  58. } DLL_INFO, * LPDLL_INFO;
  59. //
  60. // macros
  61. //
  62. #define IsPlatformWin95() \
  63. (BOOL)((GlobalPlatformType == PLATFORM_TYPE_WIN95) ? TRUE : FALSE)
  64. #define IsPlatformWinNT() \
  65. (BOOL)((GlobalPlatformType == PLATFORM_TYPE_WINNT) ? TRUE : FALSE)
  66. //#define IsUnicodeSupported() \
  67. // (BOOL)((PlatformSupport() & PLATFORM_SUPPORTS_UNICODE) ? TRUE : FALSE)
  68. #define DLL_ENTRY_POINT_ELEMENT(name) \
  69. # name, (FARPROC *)&_I_ ## name
  70. #define DLL_INFO_INIT(name, entryPoints) { \
  71. name, \
  72. NULL, \
  73. 0, \
  74. ARRAY_ELEMENTS(entryPoints), \
  75. (LPDLL_ENTRY_POINT)&entryPoints \
  76. }
  77. #define CompareFileTime(ft1, ft2) ( ((*(LONGLONG *)&ft1) > (*(LONGLONG *)&ft2)) ? 1 : \
  78. ( ((*(LONGLONG *)&ft1) == (*(LONGLONG *)&ft2)) ? 0 : -1 ) )
  79. #define WRAP_REVERT_USER(fn, args, retVal) \
  80. { \
  81. HANDLE hThreadToken = NULL; \
  82. if (OpenThreadToken(GetCurrentThread(), (TOKEN_IMPERSONATE | TOKEN_READ), \
  83. FALSE, \
  84. &hThreadToken)) \
  85. { \
  86. INET_ASSERT(hThreadToken != 0); \
  87. RevertToSelf(); \
  88. } \
  89. retVal = fn args; \
  90. if (hThreadToken) \
  91. { \
  92. SetThreadToken(NULL, hThreadToken); \
  93. CloseHandle(hThreadToken); \
  94. } \
  95. }
  96. #define SAFE_WRAP_REVERT_USER(fn, args, retVal) \
  97. { \
  98. HANDLE hThreadToken = NULL; \
  99. if (OpenThreadToken(GetCurrentThread(), (TOKEN_IMPERSONATE | TOKEN_READ), \
  100. FALSE, \
  101. &hThreadToken)) \
  102. { \
  103. INET_ASSERT(hThreadToken != 0); \
  104. RevertToSelf(); \
  105. } \
  106. __try \
  107. { \
  108. retVal = fn args; \
  109. } \
  110. __except(EXCEPTION_EXECUTE_HANDLER) \
  111. { \
  112. } \
  113. ENDEXCEPT \
  114. if (hThreadToken) \
  115. { \
  116. SetThreadToken(NULL, hThreadToken); \
  117. CloseHandle(hThreadToken); \
  118. } \
  119. }
  120. #define WRAP_REVERT_USER_VOID(fn, args) \
  121. { \
  122. HANDLE hThreadToken = NULL; \
  123. if (OpenThreadToken(GetCurrentThread(), (TOKEN_IMPERSONATE | TOKEN_READ), \
  124. FALSE, \
  125. &hThreadToken)) \
  126. { \
  127. INET_ASSERT(hThreadToken != 0); \
  128. RevertToSelf(); \
  129. } \
  130. fn args; \
  131. if (hThreadToken) \
  132. { \
  133. SetThreadToken(NULL, hThreadToken); \
  134. CloseHandle(hThreadToken); \
  135. } \
  136. }
  137. #define SAFE_WRAP_REVERT_USER_VOID(fn, args) \
  138. { \
  139. HANDLE hThreadToken = NULL; \
  140. if (OpenThreadToken(GetCurrentThread(), (TOKEN_IMPERSONATE | TOKEN_READ), \
  141. FALSE, \
  142. &hThreadToken)) \
  143. { \
  144. INET_ASSERT(hThreadToken != 0); \
  145. RevertToSelf(); \
  146. } \
  147. __try \
  148. { \
  149. fn args; \
  150. } \
  151. __except(EXCEPTION_EXECUTE_HANDLER) \
  152. { \
  153. } \
  154. ENDEXCEPT \
  155. if (hThreadToken) \
  156. { \
  157. SetThreadToken(NULL, hThreadToken); \
  158. CloseHandle(hThreadToken); \
  159. } \
  160. }
  161. //
  162. // prototypes
  163. //
  164. LPSTR
  165. NewString(
  166. IN LPCSTR String,
  167. IN DWORD dwLen = 0
  168. );
  169. LPWSTR
  170. NewStringW(
  171. IN LPCWSTR String,
  172. IN DWORD dwLen = 0
  173. );
  174. LPSTR
  175. CatString (
  176. IN LPCSTR lpszLeft,
  177. IN LPCSTR lpszRight
  178. );
  179. HLOCAL
  180. ResizeBuffer(
  181. IN HLOCAL BufferHandle,
  182. IN DWORD Size,
  183. IN BOOL Moveable
  184. );
  185. LPSTR
  186. _memrchr(
  187. IN LPSTR lpString,
  188. IN CHAR cTarget,
  189. IN INT iLength
  190. );
  191. LPSTR
  192. strnistr(
  193. IN LPSTR str1,
  194. IN LPSTR str2,
  195. IN DWORD Length
  196. );
  197. LPSTR
  198. FASTCALL
  199. PrivateStrChr(
  200. IN LPCSTR lpStart,
  201. IN WORD wMatch
  202. );
  203. DWORD
  204. PlatformType(
  205. IN OUT LPDWORD lpdwVersion5os = NULL
  206. );
  207. DWORD
  208. PlatformSupport(
  209. VOID
  210. );
  211. DWORD
  212. GetTimeoutValue(
  213. IN DWORD TimeoutOption
  214. );
  215. DWORD
  216. ProbeWriteBuffer(
  217. IN LPVOID lpBuffer,
  218. IN DWORD dwBufferLength
  219. );
  220. DWORD
  221. ProbeReadBuffer(
  222. IN LPVOID lpBuffer,
  223. IN DWORD dwBufferLength
  224. );
  225. DWORD
  226. ProbeAndSetDword(
  227. IN LPDWORD lpDword,
  228. IN DWORD dwValue
  229. );
  230. DWORD
  231. ProbeString(
  232. IN LPSTR lpString,
  233. OUT LPDWORD lpdwStringLength
  234. );
  235. DWORD
  236. ProbeStringW(
  237. IN LPWSTR lpString,
  238. OUT LPDWORD lpdwStringLength
  239. );
  240. DWORD
  241. LoadDllEntryPoints(
  242. IN OUT LPDLL_INFO lpDllInfo,
  243. IN DWORD dwFlags
  244. );
  245. //
  246. // flags for LoadDllEntryPoints()
  247. //
  248. #define LDEP_PARTIAL_LOAD_OK 0x00000001 // ok if not all entry points can be loaded
  249. DWORD
  250. UnloadDllEntryPoints(
  251. IN OUT LPDLL_INFO lpDllInfo,
  252. IN BOOL bForce
  253. );
  254. DWORD
  255. MapInternetError(
  256. IN DWORD ErrorCode,
  257. IN LPDWORD lpdwStatus = NULL
  258. );
  259. DWORD
  260. CalculateHashValue(
  261. IN LPSTR lpszString
  262. );
  263. VOID GetCurrentGmtTime(
  264. LPFILETIME lpFt
  265. );
  266. LPTSTR
  267. FTtoString(
  268. IN FILETIME *pftTime
  269. );
  270. BOOL
  271. PrintFileTimeInInternetFormat(
  272. FILETIME *lpft,
  273. LPSTR lpszBuff,
  274. DWORD dwSize
  275. );
  276. DWORD
  277. ConvertSecurityInfoIntoCertInfoStruct(
  278. IN LPINTERNET_SECURITY_INFO pSecInfo,
  279. OUT INTERNET_CERTIFICATE_INFO *pCertificate,
  280. IN OUT DWORD *pcbCertificate
  281. );
  282. BOOL
  283. CertHashToStr(
  284. IN LPSTR lpMD5Hash,
  285. IN DWORD dwMD5HashSize,
  286. IN OUT LPSTR *lplpszHashStr
  287. );
  288. //DWORD
  289. //UnicodeToUtf8(
  290. // IN LPCWSTR pwszIn,
  291. // IN DWORD dwInLen,
  292. // OUT LPBYTE pszOut,
  293. // IN OUT LPDWORD pdwOutLen
  294. // );
  295. DWORD
  296. CountUnicodeToUtf8(
  297. IN LPCWSTR pwszIn,
  298. IN DWORD dwInLen,
  299. IN BOOL bEncode
  300. );
  301. DWORD
  302. ConvertUnicodeToUtf8(
  303. IN LPCWSTR pwszIn,
  304. IN DWORD dwInLen,
  305. OUT LPBYTE pszOut,
  306. IN DWORD dwOutLen,
  307. IN BOOL bEncode
  308. );
  309. BOOL
  310. StringContainsHighAnsi(
  311. IN LPSTR pszIn,
  312. IN DWORD dwInLen
  313. );
  314. DWORD
  315. GetTickCountWrap();
  316. #ifdef DONT_USE_IERT
  317. char *
  318. StrTokEx(
  319. IN OUT char ** pstring,
  320. IN const char * control);
  321. double
  322. StrToDbl(
  323. IN const char *str,
  324. IN OUT char **strStop);
  325. #endif //DONT_USE_IERT
  326. #if defined(__cplusplus)
  327. }
  328. #endif
  329. DWORD
  330. WideCharToAscii(PCWSTR pszW, char ** ppszA);
  331. DWORD
  332. AsciiToWideChar_UsingGlobalAlloc(const char * pszA, LPWSTR * ppszW);
  333. #endif // defined(__UTIL_H__)