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.

509 lines
10 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name : isapi_context.hxx
  4. Abstract: defines ISAPI_CONTEXT object
  5. Author: Wade A. Hilmo (wadeh)
  6. Revision History:
  7. --*/
  8. #ifndef _ISAPI_CONTEXT_HXX_
  9. #define _ISAPI_CONTEXT_HXX_
  10. #include "precomp.hxx"
  11. #include "dll_manager.h"
  12. //
  13. // This is private hack for us done by COM team
  14. //
  15. const IID IID_IComDispatchInfo =
  16. {0x000001d9,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  17. MIDL_INTERFACE("000001d9-0000-0000-C000-000000000046")
  18. IComDispatchInfo : public IUnknown
  19. {
  20. public:
  21. virtual HRESULT STDMETHODCALLTYPE EnableComInits(
  22. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvCookie) = 0;
  23. virtual HRESULT STDMETHODCALLTYPE DisableComInits(
  24. /* [in] */ void __RPC_FAR *pvCookie) = 0;
  25. };
  26. //
  27. // Ok, so the ISAPI_CONTEXT_SIGNATURE is weird. This is because, for
  28. // compatibility purposes, the first member of the ISAPI_CONTEXT must
  29. // be the ECB. Since the ECB is a large structure, and its size is
  30. // fixed (and it's a public header that does this, so it's
  31. // not likely to change), we'll be sneaky and use that size as the
  32. // signature.
  33. //
  34. // This lets us maintain compatibility, and immediately recognize a
  35. // freed object in the debugger without dumping a bunch of memory.
  36. //
  37. #define ISAPI_CONTEXT_SIGNATURE sizeof( EXTENSION_CONTROL_BLOCK )
  38. #define ISAPI_CONTEXT_SIGNATURE_FREE 0xbadbad00 | sizeof( EXTENSION_CONTROL_BLOCK )
  39. //
  40. // The SERVER_VARIABLE_INDEX is an OOP optimization. The listed
  41. // server variables can all be handled from data held in the
  42. // ISAPI_CORE_DATA. In the OOP case, we can save an RPC call
  43. // by doing this. It's not worth it in the inproc case, since
  44. // these server variables are pretty cheap there.
  45. //
  46. enum SERVER_VARIABLE_INDEX
  47. {
  48. ServerVariableExternal = 0,
  49. ServerVariableApplMdPath,
  50. ServerVariableUnicodeApplMdPath,
  51. ServerVariableContentLength,
  52. ServerVariableContentType,
  53. ServerVariableInstanceId,
  54. ServerVariablePathInfo,
  55. ServerVariablePathTranslated,
  56. ServerVariableUnicodePathTranslated,
  57. ServerVariableQueryString,
  58. ServerVariableRequestMethod,
  59. ServerVariableServerPortSecure,
  60. ServerVariableServerProtocol,
  61. ServerVariableHttpMethod,
  62. ServerVariableHttpVersion,
  63. ServerVariableHttpCookie,
  64. ServerVariableHttpConnection
  65. };
  66. SERVER_VARIABLE_INDEX
  67. LookupServerVariableIndex(
  68. LPSTR szServerVariable
  69. );
  70. enum ASYNC_PENDING
  71. {
  72. NoAsyncIoPending = 0,
  73. AsyncWritePending,
  74. AsyncReadPending,
  75. AsyncExecPending,
  76. AsyncVectorPending
  77. };
  78. class ISAPI_CONTEXT
  79. {
  80. public:
  81. //
  82. // Object allocation and lifetime control
  83. //
  84. ISAPI_CONTEXT(
  85. IIsapiCore * pIsapiCore,
  86. ISAPI_CORE_DATA * pCoreData,
  87. ISAPI_DLL * pIsapiDll
  88. );
  89. VOID
  90. ReferenceIsapiContext(
  91. VOID
  92. );
  93. VOID
  94. DereferenceIsapiContext(
  95. VOID
  96. );
  97. VOID *
  98. operator new(
  99. size_t uiSize,
  100. VOID * pPlacement
  101. )
  102. {
  103. IIsapiCore * pIsapiCore;
  104. DWORD64 ul64Block;
  105. HRESULT hr;
  106. ULARGE_INTEGER li;
  107. if ( g_pDllManager->IsInproc() )
  108. {
  109. pIsapiCore = (IIsapiCore*) pPlacement;
  110. DBG_ASSERT( pIsapiCore != NULL );
  111. hr = pIsapiCore->AllocateMemory( (DWORD) uiSize, &ul64Block );
  112. if ( FAILED( hr ) )
  113. {
  114. return NULL;
  115. }
  116. li.QuadPart = ul64Block;
  117. #ifdef _WIN64
  118. return (VOID*) li.QuadPart;
  119. #else
  120. return (VOID*) li.LowPart;
  121. #endif
  122. }
  123. else
  124. {
  125. if ( uiSize != sizeof( ISAPI_CONTEXT ) )
  126. {
  127. DBG_ASSERT( FALSE );
  128. return NULL;
  129. }
  130. DBG_ASSERT( sm_pachIsapiContexts != NULL );
  131. return sm_pachIsapiContexts->Alloc();
  132. }
  133. }
  134. VOID
  135. operator delete(
  136. VOID * pIsapiContext
  137. )
  138. {
  139. if ( g_pDllManager->IsInproc() )
  140. {
  141. //
  142. // Do nothing since the memory is in the local request heap
  143. //
  144. }
  145. else
  146. {
  147. DBG_ASSERT( sm_pachIsapiContexts != NULL );
  148. sm_pachIsapiContexts->Free( pIsapiContext );
  149. }
  150. }
  151. BOOL
  152. CheckSignature()
  153. {
  154. return ( _ECB.cbSize == ISAPI_CONTEXT_SIGNATURE );
  155. }
  156. static
  157. HRESULT
  158. Initialize(
  159. VOID
  160. );
  161. static
  162. VOID
  163. Terminate(
  164. VOID
  165. );
  166. //
  167. // Accessors
  168. //
  169. EXTENSION_CONTROL_BLOCK *
  170. QueryECB(
  171. VOID
  172. )
  173. {
  174. DBG_ASSERT( CheckSignature() );
  175. return &_ECB;
  176. }
  177. IIsapiCore *
  178. QueryIsapiCoreInterface(
  179. VOID
  180. )
  181. {
  182. DBG_ASSERT( CheckSignature() );
  183. DBG_ASSERT( _pIsapiCore != NULL );
  184. return _pIsapiCore;
  185. }
  186. BOOL
  187. QueryIsOop(
  188. VOID
  189. )
  190. {
  191. DBG_ASSERT( CheckSignature() );
  192. return _pCoreData->fIsOop;
  193. }
  194. BOOL
  195. QueryClientKeepConn(
  196. VOID
  197. )
  198. {
  199. return _fClientWantsKeepConn;
  200. }
  201. BOOL
  202. QueryKeepConn(
  203. VOID
  204. )
  205. {
  206. return _fDoKeepConn;
  207. }
  208. VOID
  209. SetKeepConn(
  210. BOOL fKeepConn
  211. )
  212. {
  213. _fDoKeepConn = fKeepConn;
  214. }
  215. BOOL
  216. QueryHonorAndKeepConn(
  217. )
  218. {
  219. return _fHonorAndKeepConn;
  220. }
  221. VOID
  222. SetHonorAndKeepConn(
  223. BOOL fHonorAndKeepConn
  224. )
  225. {
  226. _fHonorAndKeepConn = fHonorAndKeepConn;
  227. }
  228. BOOL
  229. QueryHeadersSent(
  230. VOID
  231. )
  232. {
  233. return _fHeadersSent;
  234. }
  235. VOID
  236. SetHeadersSent(
  237. BOOL fHeadersSent
  238. )
  239. {
  240. _fHeadersSent = fHeadersSent;
  241. }
  242. ASYNC_PENDING
  243. QueryIoState(
  244. VOID
  245. )
  246. {
  247. return _AsyncPending;
  248. }
  249. LPVOID
  250. QueryAsyncIoBuffer(
  251. VOID
  252. )
  253. {
  254. return _pvAsyncIoBuffer;
  255. }
  256. VOID
  257. SetAsyncIoBuffer(
  258. LPVOID pBuffer
  259. )
  260. {
  261. _pvAsyncIoBuffer = pBuffer;
  262. }
  263. PFN_HSE_IO_COMPLETION
  264. QueryPfnIoCompletion(
  265. VOID
  266. )
  267. {
  268. return _pfnHseIoCompletion;
  269. }
  270. VOID
  271. SetPfnIoCompletion(
  272. PFN_HSE_IO_COMPLETION pfnHseIoCompletion
  273. )
  274. {
  275. DBG_ASSERT( pfnHseIoCompletion );
  276. _pfnHseIoCompletion = pfnHseIoCompletion;
  277. }
  278. LPVOID
  279. QueryExtensionContext(
  280. VOID
  281. )
  282. {
  283. return _pvHseIoContext;
  284. }
  285. VOID
  286. SetExtensionContext(
  287. LPVOID pExtensionContext
  288. )
  289. {
  290. _pvHseIoContext = pExtensionContext;
  291. }
  292. DWORD
  293. QueryLastAsyncIo(
  294. VOID
  295. )
  296. {
  297. return _cbLastAsyncIo;
  298. }
  299. VOID
  300. SetLastAsyncIo(
  301. DWORD cbIo
  302. )
  303. {
  304. _cbLastAsyncIo = cbIo;
  305. }
  306. HANDLE
  307. QueryToken(
  308. VOID
  309. )
  310. {
  311. DBG_ASSERT( _pCoreData->hToken != NULL );
  312. return _pCoreData->hToken;
  313. }
  314. LPWSTR
  315. QueryClsid(
  316. VOID
  317. )
  318. {
  319. return _pCoreData->szWamClsid;
  320. }
  321. HTTP_REQUEST_ID
  322. QueryRequestId(
  323. VOID
  324. )
  325. {
  326. return _RequestId;
  327. }
  328. LPWSTR
  329. QueryGatewayImage(
  330. VOID
  331. )
  332. {
  333. return _pCoreData->szGatewayImage;
  334. }
  335. //
  336. // Helper functions
  337. //
  338. BOOL
  339. TryInitAsyncIo(
  340. ASYNC_PENDING IoType
  341. );
  342. ASYNC_PENDING
  343. UninitAsyncIo(
  344. VOID
  345. );
  346. VOID
  347. IsapiDoRevertHack(
  348. HANDLE * phToken,
  349. BOOL fForce = FALSE
  350. );
  351. VOID
  352. IsapiUndoRevertHack(
  353. HANDLE * phToken
  354. );
  355. BOOL
  356. GetOopServerVariableByIndex
  357. (
  358. SERVER_VARIABLE_INDEX Index,
  359. LPVOID lpvBuffer,
  360. LPDWORD lpdwSize
  361. );
  362. HRESULT
  363. SetComStateForOop(
  364. VOID
  365. );
  366. VOID
  367. RestoreComStateForOop(
  368. VOID
  369. );
  370. private:
  371. ~ISAPI_CONTEXT();
  372. //
  373. // The EXTENSION_CONTROL_BLOCK
  374. //
  375. // Don't be a biscuit head and put anything into the ISAPI_CONTEXT
  376. // before the ECB. This is because some extensions pass a pointer to the
  377. // ECB into ISAPI calls instead of the ConnID. Due to the layout of
  378. // structures in previous versions of IIS, this worked, so we need to
  379. // continue to support it.
  380. //
  381. EXTENSION_CONTROL_BLOCK _ECB;
  382. //
  383. // Core server information
  384. //
  385. IIsapiCore * _pIsapiCore;
  386. ISAPI_CORE_DATA * _pCoreData;
  387. ISAPI_DLL * _pIsapiDll;
  388. //
  389. // Async I/O management
  390. //
  391. ASYNC_PENDING _AsyncPending;
  392. DWORD _cbLastAsyncIo;
  393. PFN_HSE_IO_COMPLETION _pfnHseIoCompletion;
  394. LPVOID _pvHseIoContext;
  395. LPVOID _pvAsyncIoBuffer;
  396. //
  397. // Client connection management
  398. //
  399. BOOL _fClientWantsKeepConn;
  400. BOOL _fDoKeepConn;
  401. BOOL _fHonorAndKeepConn;
  402. BOOL _fHeadersSent;
  403. //
  404. // COM context info (for enabling CoInit/Uninit in OOP case)
  405. //
  406. IComDispatchInfo * _pComContext;
  407. void * _pComInitsCookie;
  408. //
  409. // Request id for tracing purposes
  410. //
  411. HTTP_REQUEST_ID _RequestId;
  412. //
  413. // Misc stuff for acache, trace log, lifetime control, object
  414. // validation, etc.
  415. //
  416. LONG _cRefs;
  417. static PTRACE_LOG sm_pTraceLog;
  418. static ALLOC_CACHE_HANDLER * sm_pachIsapiContexts;
  419. };
  420. #endif // _ISAPI_CONTEXT_HXX_