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.

469 lines
9.7 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. // hObject - the current Internet object handle being used in this API. We
  62. // need this to maintain context e.g. when we want to get timeout values
  63. //
  64. HINTERNET hObject;
  65. //
  66. // hObjectMapped - this is the address of the real object mapped to hObject
  67. //
  68. HINTERNET hObjectMapped;
  69. //
  70. // IsAsyncWorkerThread - TRUE if this thread is an async worker thread
  71. //
  72. BOOL IsAsyncWorkerThread;
  73. //
  74. // InCallback - TRUE if we have made an app callback. Used to detect
  75. // re-entrancy
  76. //
  77. BOOL InCallback;
  78. //
  79. // fExitThread - This is the last thread we're waiting for termination of.
  80. //
  81. BOOL fExitThread;
  82. //
  83. // NestedRequests - incremented when we detect that we're processing an API
  84. // in the async worker thread context. If this API then calls other APIs,
  85. // then we need to treat (mapped) handles differently in the called APIs
  86. //
  87. DWORD NestedRequests;
  88. //
  89. // dwMappedErrorCode - the real error code returned by e.g. a winsock API,
  90. // before it was mapped to a WinInet error
  91. //
  92. DWORD dwMappedErrorCode;
  93. //
  94. // Fsm - currently executing Finite State Machine
  95. //
  96. CFsm * Fsm;
  97. #ifdef ENABLE_DEBUG
  98. //
  99. // IsAsyncSchedulerThread - TRUE if this INTERNET_THREAD_INFO belongs to the
  100. // one-and-only async scheduler thread
  101. //
  102. BOOL IsAsyncSchedulerThread;
  103. //
  104. // per-thread debug variables
  105. //
  106. //
  107. // Pointer to LIFO (stack) of INTERNET_DEBUG_RECORDs. Used to generate
  108. // indented call-tracing for diagnostics
  109. //
  110. LPINTERNET_DEBUG_RECORD Stack;
  111. //
  112. // CallDepth - nesting level for calls
  113. //
  114. int CallDepth;
  115. //
  116. // IndentIncrement - the current indent level. Number of spaces
  117. //
  118. int IndentIncrement;
  119. //
  120. // StartTime and StopTime - used for timing calls to e.g. send(), recv()
  121. //
  122. DWORD StartTime;
  123. DWORD StopTime;
  124. DWORD MajorCategoryFlags;
  125. DWORD MinorCategoryFlags;
  126. #endif // #ifdef ENABLE_DEBUG
  127. } INTERNET_THREAD_INFO, *LPINTERNET_THREAD_INFO;
  128. //
  129. // macros
  130. //
  131. //
  132. // InternetClearLastError - frees the response text buffer for this thread
  133. //
  134. #define InternetClearLastError() \
  135. InternetSetLastError(0, NULL, 0, 0)
  136. //
  137. // InternetResetObjectHandle - resets the per-thread current object handle
  138. //
  139. #define InternetResetObjectHandle() \
  140. InternetSetObjectHandle(NULL)
  141. //
  142. // _InternetIncNestingCount - increments nesting level count
  143. //
  144. #define _InternetIncNestingCount() \
  145. lpThreadInfo->NestedRequests++;
  146. // ** debug version
  147. //#define _InternetIncNestingCount() \
  148. // if ( lpThreadInfo->NestedRequests > 0xffff ) { \
  149. // OutputDebugString("InternetIncNestingCount, inc over threshold, contact arthurbi, x68073 (sechs)\n"); \
  150. // DebugBreak(); \
  151. // } \
  152. // lpThreadInfo->NestedRequests++;
  153. //
  154. // _InternetDecNestingCount - decrements nesting level count
  155. //
  156. #define _InternetDecNestingCount(dwNestingLevel) \
  157. lpThreadInfo->NestedRequests -= dwNestingLevel;
  158. // ** debug version
  159. //#define _InternetDecNestingCount(dwNestingLevel) \
  160. // if ( lpThreadInfo->NestedRequests == 0 ) { \
  161. // OutputDebugString("InternetDecNestingCount, attempting to dec 0, contact arthurbi, x68073 (sieben)\n"); \
  162. // DebugBreak(); \
  163. // } \
  164. // if ( dwNestingLevel != 1 && dwNestingLevel != 0 ) { \
  165. // OutputDebugString("InternetDecNestingCount, invalid nesting level, contact arthurbi, x68073 (acht)\n"); \
  166. // DebugBreak(); \
  167. // } \
  168. // lpThreadInfo->NestedRequests -= dwNestingLevel;
  169. //
  170. // _InternetSetObjectHandle - set the object handle given the thread info block
  171. //
  172. #define _InternetSetObjectHandle(lpThreadInfo, hInternet, hMapped) \
  173. DEBUG_PRINT(HTTP, \
  174. INFO, \
  175. ("Setting new obj handle on thrd=%x, old=%x, new=%x (map: old=%x, new=%x)\n", \
  176. lpThreadInfo, \
  177. lpThreadInfo->hObject, \
  178. hInternet, \
  179. lpThreadInfo->hObjectMapped, \
  180. hMapped \
  181. )); \
  182. lpThreadInfo->hObject = hInternet; \
  183. lpThreadInfo->hObjectMapped = hMapped;
  184. //
  185. // _InternetClearLastError - clear the last error info given the thread info
  186. // block
  187. //
  188. #define _InternetClearLastError(lpThreadInfo) \
  189. _InternetSetLastError(lpThreadInfo, 0, NULL, 0, 0)
  190. //
  191. // _InternetResetObjectHandle - clear the object handle given the thread info
  192. // block
  193. //
  194. #define _InternetResetObjectHandle(lpThreadInfo) \
  195. _InternetSetObjectHandle(lpThreadInfo, NULL, NULL)
  196. //
  197. // _InternetGetObjectHandle - retrieves the object handle from the per-thread
  198. // info block
  199. //
  200. #define _InternetGetObjectHandle(lpThreadInfo) \
  201. lpThreadInfo->hObject
  202. //
  203. // _InternetGetMappedObjectHandle - retrieves the mapped object handle from the
  204. // per-thread info block
  205. //
  206. #define _InternetGetMappedObjectHandle(lpThreadInfo) \
  207. lpThreadInfo->hObjectMapped
  208. //
  209. // InternetDisableAsync - turns off the async worker thread indication in the
  210. // thread info block
  211. //
  212. #define _InternetDisableAsync(lpThreadInfo) \
  213. _InternetSetAsync(FALSE)
  214. //
  215. // InternetEnableAsync - turns off the async worker thread indication in the
  216. // thread info block
  217. //
  218. #define _InternetEnableAsync(lpThreadInfo, Val) \
  219. _InternetSetAsync(TRUE)
  220. //
  221. // _InternetGetAsync - returns the async worker thread indication from the
  222. // thread info block
  223. //
  224. #define _InternetGetAsync(lpThreadInfo) \
  225. lpThreadInfo->IsAsyncWorkerThread
  226. //
  227. // _InternetSetAsync - turns on or off the async worker thread indication in the
  228. // thread info block
  229. //
  230. #define _InternetSetAsync(lpThreadInfo, Val) \
  231. lpThreadInfo->IsAsyncWorkerThread = Val
  232. #define _InternetGetInCallback(lpThreadInfo) \
  233. lpThreadInfo->InCallback
  234. #define _InternetSetInCallback(lpThreadInfo) \
  235. lpThreadInfo->InCallback = TRUE
  236. #define _InternetResetInCallback(lpThreadInfo) \
  237. lpThreadInfo->InCallback = FALSE
  238. #if INET_DEBUG
  239. #define CHECK_INTERNET_THREAD_INFO(lpThreadInfo) \
  240. INET_ASSERT(lpThreadInfo->Signature == INTERNET_THREAD_INFO_SIGNATURE)
  241. #else
  242. #define CHECK_INTERNET_THREAD_INFO(lpThreadInfo) \
  243. /* NOTHING */
  244. #endif
  245. //
  246. // prototypes
  247. //
  248. #define UI_ACTION_CODE_NONE_TAKEN 0
  249. #define UI_ACTION_CODE_BLOCKED_FOR_INTERNET_HANDLE 1
  250. #define UI_ACTION_CODE_BLOCKED_FOR_USER_INPUT 2
  251. #define UI_ACTION_CODE_USER_ACTION_COMPLETED 3
  252. LPINTERNET_THREAD_INFO
  253. InternetCreateThreadInfo(
  254. IN BOOL SetTls
  255. );
  256. VOID
  257. InternetDestroyThreadInfo(
  258. VOID
  259. );
  260. VOID
  261. InternetFreeThreadInfo(
  262. IN LPINTERNET_THREAD_INFO lpThreadInfo
  263. );
  264. VOID
  265. InternetTerminateThreadInfo(
  266. VOID
  267. );
  268. LPINTERNET_THREAD_INFO
  269. InternetGetThreadInfo(
  270. VOID
  271. );
  272. VOID
  273. InternetSetThreadInfo(
  274. IN LPINTERNET_THREAD_INFO lpThreadInfo
  275. );
  276. DWORD
  277. InternetIndicateStatusAddress(
  278. IN DWORD dwInternetStatus,
  279. IN LPSOCKADDR lpSockAddr,
  280. IN DWORD dwSockAddrLength
  281. );
  282. DWORD
  283. InternetIndicateStatusString(
  284. IN DWORD dwInternetStatus,
  285. IN LPSTR lpszStatusInfo,
  286. IN BOOL bCopyBuffer=FALSE,
  287. IN BOOL bConvertToUnicode=TRUE
  288. );
  289. DWORD
  290. InternetIndicateStatus(
  291. IN DWORD dwInternetStatus,
  292. IN LPVOID lpBuffer,
  293. IN DWORD dwBufferLength,
  294. IN BOOL bCopyBuffer=FALSE,
  295. IN BOOL bConvertToUnicode=FALSE
  296. );
  297. DWORD
  298. InternetIndicateStatusNewHandle(
  299. IN LPVOID hInternetMapped
  300. );
  301. DWORD
  302. InternetSetLastError(
  303. IN DWORD ErrorNumber,
  304. IN LPSTR ErrorText,
  305. IN DWORD ErrorTextLength,
  306. IN DWORD Flags
  307. );
  308. #define SLE_APPEND 0x00000001
  309. #define SLE_ZERO_TERMINATE 0x00000002
  310. DWORD
  311. _InternetSetLastError(
  312. IN LPINTERNET_THREAD_INFO lpThreadInfo,
  313. IN DWORD ErrorNumber,
  314. IN LPSTR ErrorText,
  315. IN DWORD ErrorTextLength,
  316. IN DWORD Flags
  317. );
  318. LPSTR
  319. InternetLockErrorText(
  320. VOID
  321. );
  322. VOID
  323. InternetUnlockErrorText(
  324. VOID
  325. );
  326. VOID
  327. InternetSetObjectHandle(
  328. IN HINTERNET hInternet,
  329. IN HINTERNET hInternetMapped
  330. );
  331. HINTERNET
  332. InternetGetObjectHandle(
  333. VOID
  334. );
  335. HINTERNET
  336. InternetGetMappedObjectHandle(
  337. VOID
  338. );
  339. //
  340. // external data
  341. //
  342. extern SERIALIZED_LIST ThreadInfoList;
  343. #if defined(__cplusplus)
  344. }
  345. #endif