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.

537 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. thrdinfo.h
  5. Abstract:
  6. Per-thread structure definitions/macros
  7. Author:
  8. Richard L Firth (rfirth) 16-Feb-1995
  9. Revision History:
  10. 16-Feb-1995 rfirth
  11. Created
  12. --*/
  13. #if defined(__cplusplus)
  14. extern "C" {
  15. #endif
  16. //
  17. // manifests
  18. //
  19. #define INTERNET_THREAD_INFO_SIGNATURE 'drhT' // "Thrd"
  20. //
  21. // forward references
  22. //
  23. class CFsm;
  24. //
  25. // types
  26. //
  27. //
  28. // INTERNET_THREAD_INFO - per-thread information, handily referenced via a TLS
  29. // slot
  30. //
  31. typedef struct _INTERNET_THREAD_INFO {
  32. //
  33. // List - doubly linked list that we delete on DLL_PROCESS_DETACH
  34. //
  35. LIST_ENTRY List;
  36. #if INET_DEBUG
  37. //
  38. // Signature - lets us know that this structure is probably an
  39. // INTERNET_THREAD_INFO
  40. //
  41. DWORD Signature;
  42. #endif
  43. //
  44. // ThreadId - used to identify this thread within a process
  45. //
  46. DWORD ThreadId;
  47. //
  48. // ErrorNumber - arbitrary error code, supplied in InternetSetLastError
  49. //
  50. DWORD ErrorNumber;
  51. //
  52. // hErrorText - we store the last error text on a per-thread basis. This
  53. // handle identifies a moveable buffer
  54. //
  55. HLOCAL hErrorText;
  56. //
  57. // ErrorTextLength - length of the error text in hErrorText
  58. //
  59. DWORD ErrorTextLength;
  60. //
  61. // Context - arbitrary app-supplied context value. This is used by
  62. // StatusCallback to identify which operation the callback is for. We keep
  63. // the context in the per-thread information so we don't have to pass it
  64. // around, nor across the wire in the case of an RPC callback
  65. //
  66. DWORD_PTR Context;
  67. //
  68. // hObject - the current Internet object handle being used in this API. We
  69. // need this to maintain context e.g. when we want to get timeout values
  70. //
  71. HINTERNET hObject;
  72. //
  73. // hObjectMapped - this is the address of the real object mapped to hObject
  74. //
  75. HINTERNET hObjectMapped;
  76. //
  77. // IsAsyncWorkerThread - TRUE if this thread is an async worker thread
  78. //
  79. BOOL IsAsyncWorkerThread;
  80. //
  81. // InCallback - TRUE if we have made an app callback. Used to detect
  82. // re-entrancy
  83. //
  84. BOOL InCallback;
  85. //
  86. // IsAutoProxyProxyThread - TRUE if we are the thread running auto-proxy requests. Used
  87. // to allow direct shutdown of auto-proxy during PROCESS_DETACH
  88. //
  89. BOOL IsAutoProxyProxyThread;
  90. //
  91. // NestedRequests - incremented when we detect that we're processing an API
  92. // in the async worker thread context. If this API then calls other APIs,
  93. // then we need to treat (mapped) handles differently in the called APIs
  94. //
  95. DWORD NestedRequests;
  96. //
  97. // dwMappedErrorCode - the real error code returned by e.g. a winsock API,
  98. // before it was mapped to a WinInet error
  99. //
  100. DWORD dwMappedErrorCode;
  101. //
  102. // Fsm - currently executing Finite State Machine
  103. //
  104. CFsm * Fsm;
  105. #ifdef ENABLE_DEBUG
  106. //
  107. // IsAsyncSchedulerThread - TRUE if this INTERNET_THREAD_INFO belongs to the
  108. // one-and-only async scheduler thread
  109. //
  110. BOOL IsAsyncSchedulerThread;
  111. //
  112. // per-thread debug variables
  113. //
  114. //
  115. // Pointer to LIFO (stack) of INTERNET_DEBUG_RECORDs. Used to generate
  116. // indented call-tracing for diagnostics
  117. //
  118. LPINTERNET_DEBUG_RECORD Stack;
  119. //
  120. // CallDepth - nesting level for calls
  121. //
  122. int CallDepth;
  123. //
  124. // IndentIncrement - the current indent level. Number of spaces
  125. //
  126. int IndentIncrement;
  127. //
  128. // StartTime and StopTime - used for timing calls to e.g. send(), recv()
  129. //
  130. DWORD StartTime;
  131. DWORD StopTime;
  132. DWORD MajorCategoryFlags;
  133. DWORD MinorCategoryFlags;
  134. #endif // #ifdef ENABLE_DEBUG
  135. } INTERNET_THREAD_INFO, *LPINTERNET_THREAD_INFO;
  136. //
  137. // macros
  138. //
  139. //
  140. // InternetClearLastError - frees the response text buffer for this thread
  141. //
  142. #define InternetClearLastError() \
  143. InternetSetLastError(0, NULL, 0, 0)
  144. //
  145. // InternetResetContext - resets the per-thread call-back context value
  146. //
  147. #define InternetResetContext() \
  148. InternetSetContext(INTERNET_NO_CALLBACK)
  149. //
  150. // InternetResetObjectHandle - resets the per-thread current object handle
  151. //
  152. #define InternetResetObjectHandle() \
  153. InternetSetObjectHandle(NULL)
  154. //
  155. // _InternetIncNestingCount - increments nesting level count
  156. //
  157. #define _InternetIncNestingCount() \
  158. lpThreadInfo->NestedRequests++;
  159. // ** debug version
  160. //#define _InternetIncNestingCount() \
  161. // if ( lpThreadInfo->NestedRequests > 0xffff ) { \
  162. // OutputDebugString("InternetIncNestingCount, inc over threshold, contact arthurbi, x68073 (sechs)\n"); \
  163. // DebugBreak(); \
  164. // } \
  165. // lpThreadInfo->NestedRequests++;
  166. //
  167. // _InternetDecNestingCount - decrements nesting level count
  168. //
  169. #define _InternetDecNestingCount(dwNestingLevel) \
  170. lpThreadInfo->NestedRequests -= dwNestingLevel;
  171. // ** debug version
  172. //#define _InternetDecNestingCount(dwNestingLevel) \
  173. // if ( lpThreadInfo->NestedRequests == 0 ) { \
  174. // OutputDebugString("InternetDecNestingCount, attempting to dec 0, contact arthurbi, x68073 (sieben)\n"); \
  175. // DebugBreak(); \
  176. // } \
  177. // if ( dwNestingLevel != 1 && dwNestingLevel != 0 ) { \
  178. // OutputDebugString("InternetDecNestingCount, invalid nesting level, contact arthurbi, x68073 (acht)\n"); \
  179. // DebugBreak(); \
  180. // } \
  181. // lpThreadInfo->NestedRequests -= dwNestingLevel;
  182. //
  183. // _InternetSetObjectHandle - set the object handle given the thread info block
  184. //
  185. #define _InternetSetObjectHandle(lpThreadInfo, hInternet, hMapped) \
  186. DEBUG_PRINT(HTTP, \
  187. INFO, \
  188. ("Setting new obj handle on thrd=%x, old=%x, new=%x (map: old=%x, new=%x)\n", \
  189. lpThreadInfo, \
  190. lpThreadInfo->hObject, \
  191. hInternet, \
  192. lpThreadInfo->hObjectMapped, \
  193. hMapped \
  194. )); \
  195. if ( lpThreadInfo->IsAutoProxyProxyThread ) \
  196. GlobalProxyInfo.SetAbortHandle(hInternet); \
  197. lpThreadInfo->hObject = hInternet; \
  198. lpThreadInfo->hObjectMapped = hMapped;
  199. //
  200. // _InternetSetContext - set the object context given the thread info block
  201. //
  202. #define _InternetSetContext(lpThreadInfo, dwContext) \
  203. DEBUG_PRINT(HTTP, \
  204. INFO, \
  205. ("Setting new context on thrd=%x, old=%x, new=%x\n", \
  206. lpThreadInfo, \
  207. lpThreadInfo->Context, \
  208. dwContext \
  209. )); \
  210. lpThreadInfo->Context = dwContext;
  211. //
  212. // _InternetClearLastError - clear the last error info given the thread info
  213. // block
  214. //
  215. #define _InternetClearLastError(lpThreadInfo) \
  216. _InternetSetLastError(lpThreadInfo, 0, NULL, 0, 0)
  217. //
  218. // _InternetResetObjectHandle - clear the object handle given the thread info
  219. // block
  220. //
  221. #define _InternetResetObjectHandle(lpThreadInfo) \
  222. _InternetSetObjectHandle(lpThreadInfo, NULL, NULL)
  223. //
  224. // _InternetGetObjectHandle - retrieves the object handle from the per-thread
  225. // info block
  226. //
  227. #define _InternetGetObjectHandle(lpThreadInfo) \
  228. lpThreadInfo->hObject
  229. //
  230. // _InternetGetMappedObjectHandle - retrieves the mapped object handle from the
  231. // per-thread info block
  232. //
  233. #define _InternetGetMappedObjectHandle(lpThreadInfo) \
  234. lpThreadInfo->hObjectMapped
  235. //
  236. // _InternetGetContext - retrieve the context from the per-thread info block
  237. //
  238. #define _InternetGetContext(lpThreadInfo) \
  239. lpThreadInfo->Context
  240. //
  241. // _InternetResetContext - reset context in per-thread info block given
  242. // per-thread info block
  243. //
  244. #define _InternetResetContext(lpThreadInfo) \
  245. _InternetSetContext(lpThreadInfo, 0)
  246. //
  247. // InternetDisableAsync - turns off the async worker thread indication in the
  248. // thread info block
  249. //
  250. #define _InternetDisableAsync(lpThreadInfo) \
  251. _InternetSetAsync(FALSE)
  252. //
  253. // InternetEnableAsync - turns off the async worker thread indication in the
  254. // thread info block
  255. //
  256. #define _InternetEnableAsync(lpThreadInfo, Val) \
  257. _InternetSetAsync(TRUE)
  258. //
  259. // _InternetGetAsync - returns the async worker thread indication from the
  260. // thread info block
  261. //
  262. #define _InternetGetAsync(lpThreadInfo) \
  263. lpThreadInfo->IsAsyncWorkerThread
  264. //
  265. // _InternetSetAsync - turns on or off the async worker thread indication in the
  266. // thread info block
  267. //
  268. #define _InternetSetAsync(lpThreadInfo, Val) \
  269. lpThreadInfo->IsAsyncWorkerThread = Val
  270. #define _InternetGetInCallback(lpThreadInfo) \
  271. lpThreadInfo->InCallback
  272. #define _InternetSetInCallback(lpThreadInfo) \
  273. lpThreadInfo->InCallback = TRUE
  274. #define _InternetResetInCallback(lpThreadInfo) \
  275. lpThreadInfo->InCallback = FALSE
  276. #define _InternetSetAutoProxy(lpThreadInfo) \
  277. lpThreadInfo->IsAutoProxyProxyThread = TRUE
  278. #if INET_DEBUG
  279. #define CHECK_INTERNET_THREAD_INFO(lpThreadInfo) \
  280. INET_ASSERT(lpThreadInfo->Signature == INTERNET_THREAD_INFO_SIGNATURE)
  281. #else
  282. #define CHECK_INTERNET_THREAD_INFO(lpThreadInfo) \
  283. /* NOTHING */
  284. #endif
  285. //
  286. // prototypes
  287. //
  288. #define UI_ACTION_CODE_NONE_TAKEN 0
  289. #define UI_ACTION_CODE_BLOCKED_FOR_INTERNET_HANDLE 1
  290. #define UI_ACTION_CODE_BLOCKED_FOR_USER_INPUT 2
  291. #define UI_ACTION_CODE_USER_ACTION_COMPLETED 3
  292. DWORD
  293. ChangeUIBlockingState(
  294. IN HINTERNET hRequestMapped,
  295. IN DWORD dwError,
  296. OUT LPDWORD lpdwActionTaken,
  297. OUT LPDWORD lpdwResultCode,
  298. IN OUT LPVOID * lplpResultData
  299. );
  300. DWORD
  301. ResumeAfterUserInput(
  302. IN HINTERNET hRequestMapped,
  303. IN DWORD dwResultCode,
  304. OUT LPBOOL pfItemResumed
  305. );
  306. LPINTERNET_THREAD_INFO
  307. InternetCreateThreadInfo(
  308. IN BOOL SetTls
  309. );
  310. VOID
  311. InternetDestroyThreadInfo(
  312. VOID
  313. );
  314. VOID
  315. InternetFreeThreadInfo(
  316. IN LPINTERNET_THREAD_INFO lpThreadInfo
  317. );
  318. VOID
  319. InternetTerminateThreadInfo(
  320. VOID
  321. );
  322. LPINTERNET_THREAD_INFO
  323. InternetGetThreadInfo(
  324. VOID
  325. );
  326. VOID
  327. InternetSetThreadInfo(
  328. IN LPINTERNET_THREAD_INFO lpThreadInfo
  329. );
  330. DWORD
  331. InternetIndicateStatusAddress(
  332. IN DWORD dwInternetStatus,
  333. IN LPSOCKADDR lpSockAddr,
  334. IN DWORD dwSockAddrLength
  335. );
  336. DWORD
  337. InternetIndicateStatusString(
  338. IN DWORD dwInternetStatus,
  339. IN LPSTR lpszStatusInfo
  340. );
  341. DWORD
  342. InternetIndicateStatus(
  343. IN DWORD dwInternetStatus,
  344. IN LPVOID lpBuffer,
  345. IN DWORD dwBufferLength
  346. );
  347. DWORD
  348. InternetIndicateStatusNewHandle(
  349. IN LPVOID hInternetMapped
  350. );
  351. DWORD
  352. InternetSetLastError(
  353. IN DWORD ErrorNumber,
  354. IN LPSTR ErrorText,
  355. IN DWORD ErrorTextLength,
  356. IN DWORD Flags
  357. );
  358. #define SLE_APPEND 0x00000001
  359. #define SLE_ZERO_TERMINATE 0x00000002
  360. DWORD
  361. _InternetSetLastError(
  362. IN LPINTERNET_THREAD_INFO lpThreadInfo,
  363. IN DWORD ErrorNumber,
  364. IN LPSTR ErrorText,
  365. IN DWORD ErrorTextLength,
  366. IN DWORD Flags
  367. );
  368. LPSTR
  369. InternetLockErrorText(
  370. VOID
  371. );
  372. VOID
  373. InternetUnlockErrorText(
  374. VOID
  375. );
  376. VOID
  377. InternetSetContext(
  378. IN DWORD_PTR dwContext
  379. );
  380. VOID
  381. InternetSetObjectHandle(
  382. IN HINTERNET hInternet,
  383. IN HINTERNET hInternetMapped
  384. );
  385. HINTERNET
  386. InternetGetObjectHandle(
  387. VOID
  388. );
  389. HINTERNET
  390. InternetGetMappedObjectHandle(
  391. VOID
  392. );
  393. //
  394. // external data
  395. //
  396. extern SERIALIZED_LIST ThreadInfoList;
  397. #if defined(__cplusplus)
  398. }
  399. #endif