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.

555 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. isapi_handler.h
  5. Abstract:
  6. Handler class for ISAPI
  7. Author:
  8. Taylor Weiss (TaylorW) 01-Feb-1999
  9. Revision History:
  10. --*/
  11. #ifndef _ISAPI_HANDLER_H_
  12. #define _ISAPI_HANDLER_H_
  13. #include "precomp.hxx"
  14. #include <w3isapi.h>
  15. #include "isapi_request.hxx"
  16. #include "iwam.h"
  17. #include "wam_process.hxx"
  18. //
  19. // OOP support flags
  20. //
  21. // The pool's hard-coded CLSID
  22. #define POOL_WAM_CLSID L"{99169CB1-A707-11d0-989D-00C04FD919C1}"
  23. // Application type
  24. #define APP_INPROC 0
  25. #define APP_ISOLATED 1
  26. #define APP_POOL 2
  27. //
  28. // W3_ISAPI_HANDLER states
  29. //
  30. #define ISAPI_STATE_PRELOAD 0 // Preloading entity body
  31. #define ISAPI_STATE_INITIALIZING 1 // Not yet called into extension code
  32. #define ISAPI_STATE_PENDING 2 // Extension has returned HSE_STATUS_PENDING
  33. #define ISAPI_STATE_FAILED 3 // Call out to extension failed
  34. #define ISAPI_STATE_DONE 4 // Extension is done, it's safe to advance
  35. #define CONTENT_TYPE_PLACEHOLDER ""
  36. #define CONNECTION_PLACEHOLDER ""
  37. #define USER_AGENT_PLACEHOLDER ""
  38. #define COOKIE_PLACEHOLDER ""
  39. //
  40. // ISAPI_CORE_DATA inline size
  41. //
  42. #define DEFAULT_CORE_DATA_SIZE 256
  43. //
  44. // Globals
  45. //
  46. extern BOOL sg_Initialized;
  47. //
  48. // W3_INPROC_ISAPI
  49. //
  50. class W3_INPROC_ISAPI
  51. {
  52. public:
  53. W3_INPROC_ISAPI()
  54. : _cRefs( 1 )
  55. {
  56. }
  57. HRESULT
  58. Create(
  59. LPWSTR pName
  60. )
  61. {
  62. return strName.Copy( pName );
  63. }
  64. LPWSTR
  65. QueryName(
  66. VOID
  67. ) const
  68. {
  69. return (LPWSTR)strName.QueryStr();
  70. }
  71. VOID
  72. ReferenceInprocIsapi(
  73. VOID
  74. )
  75. {
  76. InterlockedIncrement( &_cRefs );
  77. }
  78. VOID
  79. DereferenceInprocIsapi(
  80. VOID
  81. )
  82. {
  83. DBG_ASSERT( _cRefs != 0 );
  84. InterlockedDecrement( &_cRefs );
  85. if ( _cRefs == 0 )
  86. {
  87. delete this;
  88. }
  89. }
  90. private:
  91. ~W3_INPROC_ISAPI()
  92. {
  93. }
  94. LONG _cRefs;
  95. STRU strName;
  96. };
  97. //
  98. // W3_INPROC_ISAPI_HASH
  99. //
  100. class W3_INPROC_ISAPI_HASH
  101. : public CTypedHashTable<
  102. W3_INPROC_ISAPI_HASH,
  103. W3_INPROC_ISAPI,
  104. LPCWSTR
  105. >
  106. {
  107. public:
  108. W3_INPROC_ISAPI_HASH()
  109. : CTypedHashTable< W3_INPROC_ISAPI_HASH,
  110. W3_INPROC_ISAPI,
  111. LPCWSTR > ( "W3_INPROC_ISAPI_HASH" )
  112. {
  113. }
  114. static
  115. LPCWSTR
  116. ExtractKey(
  117. const W3_INPROC_ISAPI * pEntry
  118. )
  119. {
  120. return pEntry->QueryName();
  121. }
  122. static
  123. DWORD
  124. CalcKeyHash(
  125. LPCWSTR pszKey
  126. )
  127. {
  128. int cchKey = (int)wcslen(pszKey);
  129. return HashStringNoCase(pszKey, cchKey);
  130. }
  131. static
  132. bool
  133. EqualKeys(
  134. LPCWSTR pszKey1,
  135. LPCWSTR pszKey2
  136. )
  137. {
  138. return _wcsicmp( pszKey1, pszKey2 ) == 0;
  139. }
  140. static
  141. void
  142. AddRefRecord(
  143. W3_INPROC_ISAPI * pEntry,
  144. int nIncr
  145. )
  146. {
  147. if ( nIncr == +1 )
  148. {
  149. pEntry->ReferenceInprocIsapi();
  150. }
  151. else if ( nIncr == - 1)
  152. {
  153. pEntry->DereferenceInprocIsapi();
  154. }
  155. }
  156. MULTISZ _mszImages;
  157. private:
  158. //
  159. // Avoid c++ errors
  160. //
  161. W3_INPROC_ISAPI_HASH( const W3_INPROC_ISAPI_HASH & )
  162. : CTypedHashTable< W3_INPROC_ISAPI_HASH,
  163. W3_INPROC_ISAPI,
  164. LPCWSTR > ( "W3_INPROC_ISAPI_HASH" )
  165. {
  166. }
  167. W3_INPROC_ISAPI_HASH & operator = ( const W3_INPROC_ISAPI_HASH & ) { return *this; }
  168. };
  169. class W3_ISAPI_HANDLER : public W3_HANDLER
  170. {
  171. public:
  172. W3_ISAPI_HANDLER( W3_CONTEXT * pW3Context,
  173. META_SCRIPT_MAP_ENTRY * pScriptMapEntry )
  174. : W3_HANDLER( pW3Context, pScriptMapEntry ),
  175. _pIsapiRequest( NULL ),
  176. _fIsDavRequest( FALSE ),
  177. _pCoreData( NULL ),
  178. _fEntityBodyPreloadComplete( FALSE ),
  179. _pWamProcess( NULL ),
  180. _State( ISAPI_STATE_PRELOAD ),
  181. _buffCoreData( _abCoreData, sizeof( _abCoreData ) ),
  182. INLINE_STRA_INIT( _PhysicalPath ),
  183. INLINE_STRA_INIT( _PathInfo ),
  184. INLINE_STRA_INIT( _QueryString ),
  185. INLINE_STRA_INIT( _PathTranslated ),
  186. INLINE_STRA_INIT( _ApplMdPath ),
  187. INLINE_STRU_INIT( _ApplMdPathW ),
  188. INLINE_STRU_INIT( _PathTranslatedW )
  189. {
  190. IF_DEBUG( ISAPI )
  191. {
  192. DBGPRINTF((
  193. DBG_CONTEXT,
  194. "Creating W3_ISAPI_HANDLER %p. W3Context=%p.\r\n",
  195. this,
  196. pW3Context
  197. ));
  198. }
  199. //
  200. // Update perf counter information
  201. //
  202. pW3Context->QuerySite()->IncIsapiExtReqs();
  203. IF_DEBUG( ISAPI )
  204. {
  205. DBGPRINTF((
  206. DBG_CONTEXT,
  207. "W3_ISAPI_HANDLER %p created successfully.\r\n",
  208. this
  209. ));
  210. }
  211. }
  212. ~W3_ISAPI_HANDLER()
  213. {
  214. //
  215. // Update perf counter information.
  216. //
  217. QueryW3Context()->QuerySite()->DecIsapiExtReqs();
  218. //
  219. // Release this request's reference on the WAM_PROCESS
  220. // if applicable
  221. //
  222. if ( _pWamProcess )
  223. {
  224. _pWamProcess->Release();
  225. _pWamProcess = NULL;
  226. }
  227. IF_DEBUG( ISAPI )
  228. {
  229. DBGPRINTF((
  230. DBG_CONTEXT,
  231. "W3_ISAPI_HANDLER %p has been destroyed.\r\n"
  232. ));
  233. }
  234. }
  235. VOID *
  236. operator new(
  237. size_t uiSize,
  238. VOID * pPlacement
  239. )
  240. {
  241. W3_CONTEXT * pContext;
  242. pContext = (W3_CONTEXT*) pPlacement;
  243. DBG_ASSERT( pContext != NULL );
  244. DBG_ASSERT( pContext->CheckSignature() );
  245. return pContext->ContextAlloc( (UINT)uiSize );
  246. }
  247. VOID
  248. operator delete(
  249. VOID *
  250. )
  251. {
  252. }
  253. WCHAR *
  254. QueryName(
  255. VOID
  256. )
  257. {
  258. return L"ISAPIHandler";
  259. }
  260. BOOL
  261. QueryManagesOwnHead(
  262. VOID
  263. )
  264. {
  265. return TRUE;
  266. }
  267. CONTEXT_STATUS
  268. DoWork(
  269. VOID
  270. );
  271. CONTEXT_STATUS
  272. OnCompletion(
  273. DWORD cbCompletion,
  274. DWORD dwCompletionStatus
  275. );
  276. CONTEXT_STATUS
  277. IsapiDoWork(
  278. W3_CONTEXT * pW3Context
  279. );
  280. CONTEXT_STATUS
  281. IsapiOnCompletion(
  282. DWORD cbCompletion,
  283. DWORD dwCompletionStatus
  284. );
  285. HRESULT
  286. InitCoreData(
  287. BOOL * pfIsVrToken
  288. );
  289. HRESULT
  290. SerializeCoreDataForOop(
  291. DWORD dwAppType
  292. );
  293. HRESULT
  294. SetDavRequest( LPCWSTR szDavIsapiImage )
  295. {
  296. HRESULT hr = _strDavIsapiImage.Copy( szDavIsapiImage );
  297. if ( SUCCEEDED( hr ) )
  298. {
  299. _fIsDavRequest = TRUE;
  300. }
  301. return hr;
  302. }
  303. BOOL
  304. QueryIsOop(
  305. VOID
  306. ) const
  307. {
  308. return _pCoreData->fIsOop;
  309. }
  310. HRESULT
  311. DuplicateWamProcessHandleForLocalUse(
  312. HANDLE hWamProcessHandle,
  313. HANDLE * phLocalHandle
  314. );
  315. HRESULT
  316. MarshalAsyncReadBuffer(
  317. DWORD64 pWamExecInfo,
  318. LPBYTE pBuffer,
  319. DWORD cbBuffer
  320. );
  321. VOID
  322. IsapiRequestFinished(
  323. VOID
  324. );
  325. static
  326. HRESULT
  327. Initialize(
  328. VOID
  329. );
  330. static
  331. VOID
  332. Terminate(
  333. VOID
  334. );
  335. static
  336. HRESULT
  337. W3SVC_WamRegSink(
  338. LPCSTR szAppPath,
  339. const DWORD dwCommand,
  340. DWORD * pdwResult
  341. );
  342. static
  343. BOOL QueryIsInitialized( VOID )
  344. {
  345. return sg_Initialized;
  346. }
  347. static
  348. BOOL
  349. IsInprocIsapi(
  350. WCHAR * szImage
  351. )
  352. {
  353. W3_INPROC_ISAPI * pRecord = NULL;
  354. BOOL fRet;
  355. DBG_ASSERT( sg_Initialized );
  356. if ( szImage == NULL )
  357. {
  358. return FALSE;
  359. }
  360. EnterCriticalSection( &sm_csInprocHashLock );
  361. if ( sm_pInprocIsapiHash == NULL )
  362. {
  363. fRet = FALSE;
  364. }
  365. else
  366. {
  367. fRet = LK_SUCCESS == sm_pInprocIsapiHash->FindKey( szImage, &pRecord );
  368. }
  369. LeaveCriticalSection( &sm_csInprocHashLock );
  370. if ( fRet )
  371. {
  372. pRecord->DereferenceInprocIsapi();
  373. }
  374. return fRet;
  375. }
  376. static
  377. HRESULT
  378. UpdateInprocIsapiHash(
  379. VOID
  380. );
  381. BOOL
  382. QueryIsUlCacheable(
  383. VOID
  384. )
  385. {
  386. return TRUE;
  387. }
  388. HRESULT
  389. SetupUlCachedResponse(
  390. W3_CONTEXT * pW3Context,
  391. HTTP_CACHE_POLICY *pCachePolicy
  392. );
  393. private:
  394. ISAPI_REQUEST * _pIsapiRequest;
  395. BOOL _fIsDavRequest;
  396. STRU _strDavIsapiImage;
  397. ISAPI_CORE_DATA * _pCoreData;
  398. WAM_PROCESS * _pWamProcess;
  399. DWORD _State;
  400. //
  401. // Data for optimized w3wp mode operation
  402. //
  403. ISAPI_CORE_DATA _InlineCoreData;
  404. INLINE_STRA( _PhysicalPath,64);
  405. INLINE_STRA( _PathInfo,64);
  406. STRA _Method;
  407. INLINE_STRA( _QueryString,64);
  408. INLINE_STRA( _PathTranslated,64);
  409. INLINE_STRA( _ApplMdPath,32);
  410. INLINE_STRU( _ApplMdPathW,32);
  411. INLINE_STRU( _PathTranslatedW,64);
  412. //
  413. // Have we finished preloading entity body?
  414. //
  415. BOOL _fEntityBodyPreloadComplete;
  416. //
  417. // Buffer containing core data
  418. //
  419. BUFFER _buffCoreData;
  420. BYTE _abCoreData[ DEFAULT_CORE_DATA_SIZE ];
  421. static HMODULE sm_hIsapiModule;
  422. static PFN_ISAPI_TERM_MODULE sm_pfnTermIsapiModule;
  423. static PFN_ISAPI_PROCESS_REQUEST sm_pfnProcessIsapiRequest;
  424. static PFN_ISAPI_PROCESS_COMPLETION sm_pfnProcessIsapiCompletion;
  425. static IWam * sm_pIWamPool;
  426. static W3_INPROC_ISAPI_HASH * sm_pInprocIsapiHash;
  427. static CRITICAL_SECTION sm_csInprocHashLock;
  428. static WAM_PROCESS_MANAGER * sm_pWamProcessManager;
  429. static BOOL sm_fWamActive;
  430. static CHAR sm_szInstanceId[SIZE_CLSID_STRING];
  431. static CRITICAL_SECTION sm_csBigHurkinWamRegLock;
  432. //
  433. // Private functions
  434. //
  435. VOID
  436. RestartCoreStateMachine(
  437. VOID
  438. );
  439. static
  440. VOID
  441. LockWamReg()
  442. {
  443. EnterCriticalSection( &sm_csBigHurkinWamRegLock );
  444. }
  445. static
  446. VOID
  447. UnlockWamReg()
  448. {
  449. LeaveCriticalSection( &sm_csBigHurkinWamRegLock );
  450. }
  451. };
  452. #endif // _ISAPI_HANDLER_H_