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.

392 lines
7.1 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. * These should surround any call to g_pSecMgr->PUA, or MUTZ calls in urlmon
  32. * [ potentially ANYTHING that passes a URL to the sec. mgr. ]
  33. * to prevent the auto_proxy queueing calls going async.
  34. *
  35. * Why not just put it in HostBypassesProxy()?
  36. *
  37. * Try only HostBypassesProxy() and then later, we'll add to the urlmon calls
  38. * if need be.
  39. *
  40. * Can optimize these to surround the outermost calls to these functions where
  41. * the fsm is already available, but in doing so, make sure that no paths
  42. * that would legitimately send the autoproxy async are made sync.
  43. *
  44. * USE ONLY ONE EACH OF THESE CALLS IN A FUNCTION, and
  45. * MAKE SURE THEY ARE PAIRED UP and IN THE SAME SCOPE.
  46. */
  47. #define START_GUARD_AGAINST_ASYNC_AUTOPROXY_CALL \
  48. LPINTERNET_THREAD_INFO lpThreadInfo = InternetGetThreadInfo();\
  49. BOOL bSetNonBlocking = FALSE;\
  50. CFsm* pFsm;\
  51. if (lpThreadInfo && (pFsm=lpThreadInfo->Fsm) && lpThreadInfo->IsAsyncWorkerThread && !pFsm->IsBlocking())\
  52. {\
  53. pFsm->SetBlocking(TRUE);\
  54. bSetNonBlocking = TRUE;\
  55. }
  56. #define END_GUARD_AGAINST_ASYNC_AUTOPROXY_CALL \
  57. {\
  58. if (bSetNonBlocking)\
  59. {\
  60. pFsm->SetBlocking(FALSE);\
  61. }\
  62. }
  63. //
  64. // types
  65. //
  66. //
  67. // TRI_STATE - for places where we need to differentiate between TRUE/FALSE and
  68. // uninitialized
  69. //
  70. typedef enum {
  71. TRI_STATE_UNKNOWN = -1,
  72. TRI_STATE_FALSE = 0,
  73. TRI_STATE_TRUE = 1
  74. } TRI_STATE;
  75. //
  76. // DLL_ENTRY_POINT - maps a name to an entry point in a DLL
  77. //
  78. typedef struct {
  79. LPSTR lpszProcedureName;
  80. FARPROC * lplpfnProcedure;
  81. } DLL_ENTRY_POINT, * LPDLL_ENTRY_POINT;
  82. //
  83. // DLL_INFO - used to dynamically load/unload libraries
  84. //
  85. typedef struct {
  86. LPSTR lpszDllName;
  87. HINSTANCE hModule;
  88. LONG LoadCount;
  89. DWORD dwNumberOfEntryPoints;
  90. LPDLL_ENTRY_POINT lpEntryPoints;
  91. } DLL_INFO, * LPDLL_INFO;
  92. //
  93. // macros
  94. //
  95. #define IsPlatformWin95() \
  96. (BOOL)((GlobalPlatformType == PLATFORM_TYPE_WIN95) ? TRUE : FALSE)
  97. #define IsPlatformWinNT() \
  98. (BOOL)((GlobalPlatformType == PLATFORM_TYPE_WINNT) ? TRUE : FALSE)
  99. //#define IsUnicodeSupported() \
  100. // (BOOL)((PlatformSupport() & PLATFORM_SUPPORTS_UNICODE) ? TRUE : FALSE)
  101. #define DLL_ENTRY_POINT_ELEMENT(name) \
  102. # name, (FARPROC *)&_I_ ## name
  103. #define DLL_INFO_INIT(name, entryPoints) { \
  104. name, \
  105. NULL, \
  106. 0, \
  107. ARRAY_ELEMENTS(entryPoints), \
  108. (LPDLL_ENTRY_POINT)&entryPoints \
  109. }
  110. #define CompareFileTime(ft1, ft2) \
  111. (((*(LONGLONG UNALIGNED *)&ft1) > (*(LONGLONG UNALIGNED *)&ft2)) ? 1 : \
  112. (((*(LONGLONG UNALIGNED *)&ft1) == (*(LONGLONG UNALIGNED *)&ft2)) ? 0 : -1 ) )
  113. //
  114. // prototypes
  115. //
  116. LPSTR
  117. NewString(
  118. IN LPCSTR String,
  119. IN DWORD dwLen = 0
  120. );
  121. LPWSTR
  122. NewStringW(
  123. IN LPCWSTR String,
  124. IN DWORD dwLen = 0
  125. );
  126. LPSTR
  127. CatString (
  128. IN LPCSTR lpszLeft,
  129. IN LPCSTR lpszRight
  130. );
  131. HLOCAL
  132. ResizeBuffer(
  133. IN HLOCAL BufferHandle,
  134. IN DWORD Size,
  135. IN BOOL Moveable
  136. );
  137. LPSTR
  138. _memrchr(
  139. IN LPSTR lpString,
  140. IN CHAR cTarget,
  141. IN INT iLength
  142. );
  143. LPSTR
  144. strnistr(
  145. IN LPSTR str1,
  146. IN LPSTR str2,
  147. IN DWORD Length
  148. );
  149. LPSTR
  150. FASTCALL
  151. PrivateStrChr(
  152. IN LPCSTR lpStart,
  153. IN WORD wMatch
  154. );
  155. DWORD
  156. PlatformType(
  157. IN OUT LPDWORD lpdwVersion5os = NULL
  158. );
  159. DWORD
  160. PlatformSupport(
  161. VOID
  162. );
  163. DWORD
  164. GetTimeoutValue(
  165. IN DWORD TimeoutOption
  166. );
  167. DWORD
  168. ProbeWriteBuffer(
  169. IN LPVOID lpBuffer,
  170. IN DWORD dwBufferLength
  171. );
  172. DWORD
  173. ProbeReadBuffer(
  174. IN LPVOID lpBuffer,
  175. IN DWORD dwBufferLength
  176. );
  177. DWORD
  178. ProbeAndSetDword(
  179. IN LPDWORD lpDword,
  180. IN DWORD dwValue
  181. );
  182. DWORD
  183. ProbeString(
  184. IN LPSTR lpString,
  185. OUT LPDWORD lpdwStringLength
  186. );
  187. DWORD
  188. ProbeStringW(
  189. IN LPWSTR lpString,
  190. OUT LPDWORD lpdwStringLength
  191. );
  192. DWORD
  193. LoadDllEntryPoints(
  194. IN OUT LPDLL_INFO lpDllInfo,
  195. IN DWORD dwFlags
  196. );
  197. //
  198. // flags for LoadDllEntryPoints()
  199. //
  200. #define LDEP_PARTIAL_LOAD_OK 0x00000001 // ok if not all entry points can be loaded
  201. DWORD
  202. UnloadDllEntryPoints(
  203. IN OUT LPDLL_INFO lpDllInfo,
  204. IN BOOL bForce
  205. );
  206. DWORD
  207. MapInternetError(
  208. IN DWORD ErrorCode
  209. );
  210. DWORD
  211. CalculateHashValue(
  212. IN LPSTR lpszString
  213. );
  214. VOID GetCurrentGmtTime(
  215. LPFILETIME lpFt
  216. );
  217. //DWORD DwRemoveDots (
  218. // char * pchPath
  219. // );
  220. LPSTR GetFileExtensionFromUrl(
  221. LPSTR lpszUrl,
  222. LPDWORD lpdwLength
  223. );
  224. DWORD
  225. CheckExpired(
  226. HINTERNET handle,
  227. BOOL *lpfIsExpired,
  228. LPCACHE_ENTRY_INFO lpCEI,
  229. LONGLONG DefaultExpiryDelta
  230. );
  231. LPTSTR
  232. FTtoString(
  233. IN FILETIME *pftTime
  234. );
  235. BOOL
  236. PrintFileTimeInInternetFormat(
  237. FILETIME *lpft,
  238. LPSTR lpszBuff,
  239. DWORD dwSize
  240. );
  241. BOOL
  242. InternetSettingsChanged(
  243. VOID
  244. );
  245. DWORD
  246. ConvertSecurityInfoIntoCertInfoStruct(
  247. IN LPINTERNET_SECURITY_INFO pSecInfo,
  248. OUT INTERNET_CERTIFICATE_INFO *pCertificate,
  249. IN OUT DWORD *pcbCertificate
  250. );
  251. LPTSTR
  252. FormatCertInfo(
  253. IN INTERNET_CERTIFICATE_INFO *pCertInfo
  254. );
  255. BOOL
  256. CertHashToStr(
  257. IN LPSTR lpMD5Hash,
  258. IN DWORD dwMD5HashSize,
  259. IN OUT LPSTR *lplpszHashStr
  260. );
  261. //DWORD
  262. //UnicodeToUtf8(
  263. // IN LPCWSTR pwszIn,
  264. // IN DWORD dwInLen,
  265. // OUT LPBYTE pszOut,
  266. // IN OUT LPDWORD pdwOutLen
  267. // );
  268. BOOL
  269. StringContainsHighAnsi(
  270. IN LPSTR pszIn,
  271. IN DWORD dwInLen
  272. );
  273. LPSTR
  274. ConvertMBCSToUTF8(
  275. IN LPCSTR lpszMBCSHostName,
  276. IN DWORD dwMBCSHostNameLength,
  277. IN DWORD dwCodePage,
  278. OUT DWORD * pdwUTF8HostNameLength,
  279. BOOL bLowerCase = TRUE
  280. );
  281. DWORD
  282. GetTickCountWrap();
  283. char *FindNamedValue(char *pszHeader,
  284. const char *pszFieldName,
  285. unsigned long *pdwValSize);
  286. #ifdef DONT_USE_IERT
  287. char *
  288. StrTokEx(
  289. IN OUT char ** pstring,
  290. IN const char * control);
  291. double
  292. StrToDbl(
  293. IN const char *str,
  294. IN OUT char **strStop);
  295. #endif //DONT_USE_IERT
  296. char* StrTokEx2(char** pstring, const char* control);
  297. BOOL IsAddressValidIPString(LPCSTR pszHostIP);
  298. BOOL
  299. RefreshSslState(
  300. VOID
  301. );
  302. BOOL
  303. IsInGUIModeSetup();
  304. #if defined(__cplusplus)
  305. }
  306. #endif
  307. #endif // defined(__UTIL_H__)