Source code of Windows XP (NT5)
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.

696 lines
19 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Hit Object
  6. File: Hitobj.h
  7. Owner: PramodD
  8. This is the Hit Object header file.
  9. ===================================================================*/
  10. #ifndef HITOBJ_H
  11. #define HITOBJ_H
  12. #include "Compcol.h"
  13. #include "Sessmgr.h"
  14. #include "Applmgr.h"
  15. #include "Context.h"
  16. #include "Resource.h"
  17. #include "exec.h"
  18. #include "glob.h"
  19. #include "memcls.h"
  20. #include "gip.h"
  21. #include "txnsup.h"
  22. #define hNil (HANDLE)0
  23. #define SESSIONID_LEN 24
  24. // HitObj type
  25. #define EHitType DWORD
  26. #define ehtUnInitedRequest 0x00000000
  27. #define ehtBrowserRequest 0x00000001
  28. #define ehtSessionCleanup 0x00000002
  29. #define ehtApplicationCleanup 0x00000004
  30. // Execution status (result)
  31. #define EExecStatus DWORD
  32. #define eExecFailed 0x00000000
  33. #define eExecSucceeded 0x00000001
  34. #define eExecTimedOut 0x00000002
  35. // Current execution state
  36. #define EEventState DWORD
  37. #define eEventNone 0x00000000
  38. #define eEventAppOnStart 0x00000001
  39. #define eEventSesOnStart 0x00000002
  40. #define eEventAppOnEnd 0x00000004
  41. #define eEventSesOnEnd 0x00000008
  42. // Global interface table
  43. extern IGlobalInterfaceTable *g_pGIT;
  44. /*===================================================================
  45. C H i t O b j
  46. The Hit Manager runs in the context of an IIS thread.
  47. It packages up a request, calls Viper async. and
  48. on callback executes the request
  49. ===================================================================*/
  50. class CHitObj
  51. {
  52. private:
  53. // Flags and other bit-fields
  54. DWORD m_fInited : 1; // Are we initialized?
  55. DWORD m_fRunGlobalAsa : 1; // Should we run global.asa
  56. DWORD m_fStartSession : 1; // New session
  57. DWORD m_fNewCookie : 1; // Is New session cookie?
  58. DWORD m_fStartApplication : 1; // New application
  59. DWORD m_fClientCodeDebug : 1; // Client code debug enabled?
  60. DWORD m_fApplnOnStartFailed : 1; // Application_OnStart failed
  61. DWORD m_fCompilationFailed : 1; // Script Compilation error?
  62. DWORD m_fExecuting : 1; // Currently inside Viper callback
  63. DWORD m_fHideRequestAndResponseIntrinsics : 1; // TRUE while instrinsics are hidden
  64. DWORD m_fHideSessionIntrinsic : 1; // TRUE if session intrinsic's hidden
  65. DWORD m_fDoneWithSession : 1; // TRUE after DONE_WITH_SESSION
  66. DWORD m_fRejected : 1; // TRUE if rejected (not posted)
  67. DWORD m_f449Done : 1; // 449 processing done for this request
  68. DWORD m_fInTransferOnError : 1; // doing transfer on error (to break infinite)
  69. DWORD m_fSecure : 1; // Secure Connection
  70. EHitType m_ehtType : 4; // Type of the request
  71. EExecStatus m_eExecStatus : 4; // Error Status // for Perf Counter only
  72. EEventState m_eEventState : 4; // Current Event
  73. CompScope m_ecsActivityScope : 4; // Which activity running this request?
  74. // Intrinsics set from inside HitObj
  75. CSession *m_pSession;
  76. CAppln *m_pAppln;
  77. CResponse *m_pResponse;
  78. CRequest *m_pRequest;
  79. CServer *m_pServer;
  80. CASPObjectContext *m_pASPObjectContext;
  81. // IsapiReqInfo
  82. CIsapiReqInfo *m_pIReq;
  83. // Intrinsics set from outside HitObj (to be ref. counted)
  84. IUnknown *m_punkScriptingNamespace;
  85. // Component collection of extrinsic objects
  86. CComponentCollection *m_pPageCompCol;
  87. CPageComponentManager *m_pPageObjMgr;
  88. // Impersonation handle
  89. HANDLE m_hImpersonate;
  90. // Viper page-level activity (if no session)
  91. CViperActivity *m_pActivity;
  92. // Current session info
  93. char m_szSessionCookie[SESSIONID_LEN+4]; // +4 to keep DWORD boundary
  94. CSessionId m_SessionId;
  95. // Context object (for OnStartPage)
  96. CScriptingContext * m_pScriptingContext;
  97. // Misc
  98. long m_nScriptTimeout; // Maximum number of seconds script should run
  99. UINT m_uCodePage; // RunTime CodePage
  100. LCID m_lcid; // RunTime LCID
  101. ActiveEngineInfo *m_pEngineInfo; // List of active engines for this hit objext
  102. IDispatch *m_pdispTypeLibWrapper; // Page-level typelib wrapper
  103. DWORD m_dwtTimestamp; // Timestamp for wait time and perf calcs
  104. // Used to reffer to the current template during the compilation
  105. TCHAR *m_szCurrTemplatePhysPath;
  106. TCHAR *m_szCurrTemplateVirtPath;
  107. // ASP Error object
  108. IASPError *m_pASPError;
  109. // Store a pointer to the associated template so as to avoid redundant
  110. // FindTemplate calls.
  111. CTemplate *m_pTemplate;
  112. // Private interfaces
  113. HRESULT ParseCookiesForSessionIdAndFlags();
  114. // Request rejection logic
  115. HRESULT RejectBrowserRequestWhenNeeded(DWORD dwtQueueWaitTime, BOOL *pfRejected);
  116. // Public Interfaces
  117. public:
  118. CHitObj();
  119. virtual ~CHitObj();
  120. static HRESULT NewBrowserRequest(CIsapiReqInfo *pIReq,
  121. BOOL *pfRejected = NULL,
  122. BOOL *pfCompleted = NULL,
  123. int *piErrorId = NULL);
  124. HRESULT BrowserRequestInit(CIsapiReqInfo *pIReq, int * dwId);
  125. HRESULT AssignApplnToBrowserRequest(BOOL *pfApplnRestarting);
  126. HRESULT AssignSessionToBrowserRequest(BOOL *pfNewSession, BOOL *pfNewCookie, int *pErrorId);
  127. HRESULT DetachBrowserRequestFromSession();
  128. HRESULT ReassignAbandonedSession();
  129. void SessionCleanupInit(CSession *pSession);
  130. void ApplicationCleanupInit(CAppln *pAppln);
  131. BOOL SendHeader(const char *szStatus);
  132. BOOL SendError(const char *szError);
  133. TCHAR* GetSzAppPhysicalPath(void);
  134. void ApplnOnStartFailed();
  135. void SessionOnStartFailed();
  136. void SessionOnStartInvoked();
  137. void SessionOnEndPresent();
  138. void SetEventState(EEventState eEvent);
  139. EEventState EventState();
  140. // Report server error without response object
  141. HRESULT ReportServerError(UINT ErrorId);
  142. // Component Collection Interfaces
  143. HRESULT InitComponentProcessing();
  144. HRESULT StopComponentProcessing();
  145. HRESULT GetPageComponentCollection(CComponentCollection **ppCollection);
  146. HRESULT GetSessionComponentCollection(CComponentCollection **ppCollection);
  147. HRESULT GetApplnComponentCollection(CComponentCollection **ppCollection);
  148. HRESULT AddComponent(CompType type, const CLSID &clsid, CompScope scope,
  149. CompModel model, LPWSTR pwszName = NULL,
  150. IUnknown *pUnk = NULL);
  151. HRESULT GetComponent(CompScope scope, LPWSTR pwszName, DWORD cbName,
  152. CComponentObject **ppObj);
  153. HRESULT GetIntrinsic(LPWSTR pwszName, DWORD cbName, IUnknown **ppUnk);
  154. HRESULT CreateComponent(const CLSID &clsid, IDispatch **ppDisp);
  155. HRESULT SetPropertyComponent(CompScope scope, LPWSTR pwszName,
  156. VARIANT *pVariant);
  157. HRESULT GetPropertyComponent(CompScope scope, LPWSTR pwszName,
  158. CComponentObject **ppObj);
  159. // Viper Integration
  160. CViperActivity *PActivity();
  161. CViperActivity *PCurrentActivity();
  162. HRESULT SetActivity(CViperActivity *pActivity);
  163. HRESULT PostViperAsyncCall();
  164. HRESULT ViperAsyncCallback(BOOL *pfRePosted);
  165. // Execute / Transfer
  166. HRESULT ExecuteChildRequest(BOOL fTransfer, TCHAR *szTemplate, TCHAR *szVirtTemplate);
  167. HRESULT GetASPError(IASPError **ppASPError);
  168. inline void SetASPError(IASPError *pASPError);
  169. inline BOOL FHasASPError();
  170. // inline functions
  171. public:
  172. CIsapiReqInfo *PIReq();
  173. HANDLE HImpersonate();
  174. CResponse * PResponse();
  175. CRequest * PRequest();
  176. CServer * PServer();
  177. CAppln * PAppln();
  178. CSession * PSession();
  179. CASPObjectContext *PASPObjectContext();
  180. CASPObjectContext *SetASPObjectContext(CASPObjectContext *);
  181. CPageComponentManager * PPageComponentManager();
  182. BOOL FIsBrowserRequest() const;
  183. BOOL FIsSessionCleanupRequest() const;
  184. BOOL FIsApplnCleanupRequest() const;
  185. BOOL FIsValidRequestType() const;
  186. const char * PSzNewSessionCookie() const;
  187. DWORD SessionId() const;
  188. CScriptingContext * PScriptingContextGet();
  189. BOOL FStartApplication();
  190. BOOL FStartSession();
  191. BOOL FNewCookie();
  192. BOOL FObjectTag(IDispatch * pDispatch);
  193. BOOL FHasSession();
  194. BOOL FClientCodeDebug();
  195. BOOL FDoneWithSession();
  196. BOOL FExecuting();
  197. BOOL F449Done();
  198. BOOL FInTransferOnError();
  199. BOOL FSecure();
  200. void SetScriptTimeout(long nScriptTimeout);
  201. long GetScriptTimeout();
  202. void SetExecStatus(EExecStatus status);
  203. EExecStatus ExecStatus();
  204. void SetActiveEngineInfo(ActiveEngineInfo *);
  205. void SetCompilationFailed();
  206. void SetDoneWithSession();
  207. void Set449Done();
  208. void SetInTransferOnError();
  209. TCHAR * GlobalAspPath();
  210. HRESULT SetCodePage(UINT uCodePage); // Proxy function, CodePage is stored in m_pSession
  211. UINT GetCodePage(); // same as above
  212. HRESULT SetLCID(LCID lcid); // Proxy function, LCID is stored in m_pSession
  213. LCID GetLCID(); // same as above
  214. CAppConfig * QueryAppConfig();
  215. TCHAR * PSzCurrTemplatePhysPath();
  216. TCHAR * PSzCurrTemplateVirtPath();
  217. DWORD DWInstanceID();
  218. CTemplate *GetTemplate();
  219. void SetTemplate(CTemplate *);
  220. // Instead of add/remove to/from component collection use these:
  221. void HideRequestAndResponseIntrinsics();
  222. void UnHideRequestAndResponseIntrinsics();
  223. BOOL FRequestAndResponseIntrinsicsHidden();
  224. void AddScriptingNamespace(IUnknown *punkNamespace);
  225. void RemoveScriptingNamespace();
  226. // Typelib wrapper support
  227. IDispatch *PTypeLibWrapper();
  228. void SetTypeLibWrapper(IDispatch *pdisp);
  229. // Timestamp manipulation
  230. void UpdateTimestamp();
  231. DWORD ElapsedTimeSinceTimestamp();
  232. #ifdef DBG
  233. virtual void AssertValid() const;
  234. #else
  235. virtual void AssertValid() const {}
  236. #endif
  237. // Cache on per-class basis
  238. ACACHE_INCLASS_DEFINITIONS()
  239. };
  240. /*===================================================================
  241. CHitObj inlines
  242. ===================================================================*/
  243. inline CIsapiReqInfo *CHitObj::PIReq()
  244. {
  245. return m_pIReq;
  246. }
  247. inline BOOL CHitObj::FIsBrowserRequest() const
  248. {
  249. return (m_ehtType == ehtBrowserRequest);
  250. }
  251. inline BOOL CHitObj::FIsSessionCleanupRequest() const
  252. {
  253. return (m_ehtType == ehtSessionCleanup);
  254. }
  255. inline BOOL CHitObj::FIsApplnCleanupRequest() const
  256. {
  257. return (m_ehtType == ehtApplicationCleanup);
  258. }
  259. inline BOOL CHitObj::FIsValidRequestType() const
  260. {
  261. return (FIsBrowserRequest() ||
  262. FIsSessionCleanupRequest() ||
  263. FIsApplnCleanupRequest());
  264. }
  265. inline HANDLE CHitObj::HImpersonate()
  266. {
  267. return m_hImpersonate;
  268. }
  269. inline DWORD CHitObj::SessionId() const
  270. {
  271. return m_SessionId.m_dwId;
  272. }
  273. inline const char *CHitObj::PSzNewSessionCookie() const
  274. {
  275. return (m_fNewCookie ? m_szSessionCookie : NULL);
  276. }
  277. inline BOOL CHitObj::FStartApplication()
  278. {
  279. return m_fStartApplication;
  280. }
  281. inline BOOL CHitObj::FStartSession()
  282. {
  283. return m_fStartSession;
  284. }
  285. inline BOOL CHitObj::FNewCookie()
  286. {
  287. return m_fNewCookie;
  288. }
  289. inline BOOL CHitObj::FHasSession()
  290. {
  291. return (m_pSession != NULL && !m_fHideSessionIntrinsic);
  292. }
  293. inline BOOL CHitObj::FClientCodeDebug()
  294. {
  295. return m_fClientCodeDebug;
  296. }
  297. inline BOOL CHitObj::FDoneWithSession()
  298. {
  299. return m_fDoneWithSession;
  300. }
  301. inline BOOL CHitObj::FExecuting()
  302. {
  303. return m_fExecuting;
  304. }
  305. inline BOOL CHitObj::F449Done()
  306. {
  307. return m_f449Done;
  308. }
  309. inline BOOL CHitObj::FInTransferOnError()
  310. {
  311. return m_fInTransferOnError;
  312. }
  313. inline BOOL CHitObj::FSecure()
  314. {
  315. return m_fSecure;
  316. }
  317. inline void CHitObj::SessionOnStartFailed()
  318. {
  319. Assert(m_pSession);
  320. m_pSession->SetOnStartFailedFlag();
  321. }
  322. inline void CHitObj::ApplnOnStartFailed()
  323. {
  324. m_fApplnOnStartFailed = TRUE;
  325. if (m_pSession)
  326. SessionOnStartFailed();
  327. }
  328. inline void CHitObj::SessionOnStartInvoked()
  329. {
  330. Assert(m_pSession);
  331. m_pSession->SetOnStartInvokedFlag();
  332. }
  333. inline void CHitObj::SessionOnEndPresent()
  334. {
  335. Assert(m_pSession);
  336. m_pSession->SetOnEndPresentFlag();
  337. }
  338. inline DWORD CHitObj::DWInstanceID()
  339. {
  340. return (m_pIReq) ? m_pIReq->QueryInstanceId() : 0;
  341. }
  342. inline CViperActivity *CHitObj::PActivity()
  343. {
  344. return m_pActivity;
  345. }
  346. inline CScriptingContext *CHitObj::PScriptingContextGet()
  347. {
  348. return m_pScriptingContext;
  349. }
  350. inline CResponse *CHitObj::PResponse()
  351. {
  352. return m_pResponse;
  353. }
  354. inline CRequest *CHitObj::PRequest()
  355. {
  356. return m_pRequest;
  357. }
  358. inline CServer *CHitObj::PServer()
  359. {
  360. return m_pServer;
  361. }
  362. inline CAppln *CHitObj::PAppln()
  363. {
  364. return m_pAppln;
  365. }
  366. inline CSession *CHitObj::PSession()
  367. {
  368. return m_pSession;
  369. }
  370. inline CASPObjectContext *CHitObj::PASPObjectContext()
  371. {
  372. return m_pASPObjectContext;
  373. }
  374. inline CASPObjectContext *CHitObj::SetASPObjectContext(CASPObjectContext *pContext)
  375. {
  376. CASPObjectContext *pPoppedContext = m_pASPObjectContext;
  377. m_pASPObjectContext = pContext;
  378. return pPoppedContext;
  379. }
  380. inline CPageComponentManager *CHitObj::PPageComponentManager()
  381. {
  382. return m_pPageObjMgr;
  383. }
  384. inline TCHAR *CHitObj::GlobalAspPath()
  385. {
  386. if ( m_fRunGlobalAsa )
  387. return m_pAppln->GetGlobalAsa();
  388. else
  389. return NULL;
  390. }
  391. inline void CHitObj::SetScriptTimeout(long nScriptTimeout)
  392. {
  393. m_nScriptTimeout = nScriptTimeout;
  394. }
  395. inline long CHitObj::GetScriptTimeout()
  396. {
  397. return m_nScriptTimeout;
  398. }
  399. inline void CHitObj::SetExecStatus(EExecStatus status)
  400. {
  401. m_eExecStatus = status;
  402. }
  403. inline EExecStatus CHitObj::ExecStatus()
  404. {
  405. return m_eExecStatus;
  406. }
  407. inline EEventState CHitObj::EventState()
  408. {
  409. return m_eEventState;
  410. }
  411. inline void CHitObj::SetEventState(EEventState eState)
  412. {
  413. m_eEventState = eState;
  414. }
  415. inline CAppConfig * CHitObj::QueryAppConfig(void)
  416. {
  417. return m_pAppln->QueryAppConfig();
  418. }
  419. inline UINT CHitObj::GetCodePage(void)
  420. {
  421. return m_uCodePage == 0 ? GetACP() : m_uCodePage;
  422. }
  423. inline LCID CHitObj::GetLCID()
  424. {
  425. return m_lcid;
  426. }
  427. inline VOID CHitObj::SetActiveEngineInfo(ActiveEngineInfo *pActiveEngineInfo)
  428. {
  429. m_pEngineInfo = pActiveEngineInfo;
  430. }
  431. inline void CHitObj::SetCompilationFailed()
  432. {
  433. m_fCompilationFailed = TRUE;
  434. }
  435. inline void CHitObj::SetDoneWithSession()
  436. {
  437. Assert(!m_fDoneWithSession);
  438. m_fDoneWithSession = TRUE;
  439. }
  440. inline void CHitObj::Set449Done()
  441. {
  442. Assert(!m_f449Done);
  443. m_f449Done = TRUE;
  444. }
  445. inline void CHitObj::SetInTransferOnError()
  446. {
  447. Assert(!m_fInTransferOnError);
  448. m_fInTransferOnError = TRUE;
  449. }
  450. inline void CHitObj::HideRequestAndResponseIntrinsics()
  451. {
  452. m_fHideRequestAndResponseIntrinsics = TRUE;
  453. }
  454. inline void CHitObj::UnHideRequestAndResponseIntrinsics()
  455. {
  456. m_fHideRequestAndResponseIntrinsics = FALSE;
  457. }
  458. inline BOOL CHitObj::FRequestAndResponseIntrinsicsHidden()
  459. {
  460. return m_fHideRequestAndResponseIntrinsics;
  461. }
  462. inline void CHitObj::AddScriptingNamespace(IUnknown *punkNamespace)
  463. {
  464. Assert(m_punkScriptingNamespace == NULL);
  465. Assert(punkNamespace);
  466. m_punkScriptingNamespace = punkNamespace;
  467. m_punkScriptingNamespace->AddRef();
  468. }
  469. inline void CHitObj::RemoveScriptingNamespace()
  470. {
  471. if (m_punkScriptingNamespace)
  472. {
  473. m_punkScriptingNamespace->Release();
  474. m_punkScriptingNamespace = NULL;
  475. }
  476. }
  477. inline IDispatch *CHitObj::PTypeLibWrapper()
  478. {
  479. return m_pdispTypeLibWrapper;
  480. }
  481. inline void CHitObj::SetTypeLibWrapper(IDispatch *pdisp)
  482. {
  483. if (m_pdispTypeLibWrapper)
  484. m_pdispTypeLibWrapper->Release();
  485. m_pdispTypeLibWrapper = pdisp;
  486. if (m_pdispTypeLibWrapper)
  487. m_pdispTypeLibWrapper->AddRef();
  488. }
  489. inline void CHitObj::UpdateTimestamp()
  490. {
  491. m_dwtTimestamp = GetTickCount();
  492. }
  493. inline DWORD CHitObj::ElapsedTimeSinceTimestamp()
  494. {
  495. DWORD dwt = GetTickCount();
  496. if (dwt >= m_dwtTimestamp)
  497. return (dwt - m_dwtTimestamp);
  498. else
  499. return ((0xffffffff - m_dwtTimestamp) + dwt);
  500. }
  501. inline TCHAR *CHitObj::PSzCurrTemplatePhysPath()
  502. {
  503. if (m_szCurrTemplatePhysPath != NULL)
  504. return m_szCurrTemplatePhysPath;
  505. else if (m_pIReq != NULL)
  506. return m_pIReq->QueryPszPathTranslated();
  507. else
  508. return NULL;
  509. }
  510. inline TCHAR *CHitObj::PSzCurrTemplateVirtPath()
  511. {
  512. if (m_szCurrTemplateVirtPath != NULL)
  513. return m_szCurrTemplateVirtPath;
  514. else if (m_pIReq != NULL)
  515. return m_pIReq->QueryPszPathInfo();
  516. else
  517. return NULL;
  518. }
  519. inline void CHitObj::SetASPError(IASPError *pASPError)
  520. {
  521. if (m_pASPError)
  522. m_pASPError->Release();
  523. m_pASPError = pASPError; // passed addref'd
  524. }
  525. inline BOOL CHitObj::FHasASPError()
  526. {
  527. return (m_pASPError != NULL);
  528. }
  529. inline CTemplate *CHitObj::GetTemplate()
  530. {
  531. return m_pTemplate;
  532. }
  533. inline void CHitObj::SetTemplate(CTemplate *pTemplate)
  534. {
  535. m_pTemplate = pTemplate;
  536. }
  537. /*===================================================================
  538. Globals
  539. ===================================================================*/
  540. extern DWORD g_nBrowserRequests;
  541. extern DWORD g_nSessionCleanupRequests;
  542. extern DWORD g_nApplnCleanupRequests;
  543. #undef SCRIPT_STATS
  544. #ifdef SCRIPT_STATS
  545. # include <locks.h>
  546. void
  547. ReadRegistrySettings();
  548. extern CSmallSpinLock g_lockRequestStats;
  549. extern DWORD g_dwQueueDebugThreshold;
  550. extern DWORD g_fSendScriptlessOnAtqThread;
  551. extern LONG g_cRequests;
  552. extern LONG g_cScriptlessRequests;
  553. extern LONG g_cHttpExtensionsExecuting;
  554. extern LONG g_cConcurrentScriptlessRequests;
  555. extern LONG g_cMaxConcurrentScriptlessRequests;
  556. extern LONGLONG g_nSumConcurrentScriptlessRequests;
  557. extern LONGLONG g_nSumExecTimeScriptlessRequests;
  558. extern LONG g_nAvgConcurrentScriptlessRequests;
  559. extern LONG g_nAvgExecTimeScriptlessRequests;
  560. #endif // SCRIPT_STATS
  561. #endif // HITOBJ_H