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.

684 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 "txnsupp.h"
  21. #include "gip.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. // IsapiReqInfo
  81. CIsapiReqInfo *m_pIReq;
  82. // Intrinsics set from outside HitObj (to be ref. counted)
  83. IUnknown *m_punkScriptingNamespace;
  84. DWORD m_dwObjectContextCookie;
  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. CPageComponentManager * PPageComponentManager();
  180. BOOL FIsBrowserRequest() const;
  181. BOOL FIsSessionCleanupRequest() const;
  182. BOOL FIsApplnCleanupRequest() const;
  183. BOOL FIsValidRequestType() const;
  184. const char * PSzNewSessionCookie() const;
  185. DWORD SessionId() const;
  186. CScriptingContext * PScriptingContextGet();
  187. BOOL FStartApplication();
  188. BOOL FStartSession();
  189. BOOL FNewCookie();
  190. BOOL FObjectTag(IDispatch * pDispatch);
  191. BOOL FHasSession();
  192. BOOL FClientCodeDebug();
  193. BOOL FDoneWithSession();
  194. BOOL FExecuting();
  195. BOOL F449Done();
  196. BOOL FInTransferOnError();
  197. BOOL FSecure();
  198. void SetScriptTimeout(long nScriptTimeout);
  199. long GetScriptTimeout();
  200. void SetExecStatus(EExecStatus status);
  201. EExecStatus ExecStatus();
  202. void SetActiveEngineInfo(ActiveEngineInfo *);
  203. void SetCompilationFailed();
  204. void SetDoneWithSession();
  205. void Set449Done();
  206. void SetInTransferOnError();
  207. TCHAR * GlobalAspPath();
  208. HRESULT SetCodePage(UINT uCodePage); // Proxy function, CodePage is stored in m_pSession
  209. UINT GetCodePage(); // same as above
  210. HRESULT SetLCID(LCID lcid); // Proxy function, LCID is stored in m_pSession
  211. LCID GetLCID(); // same as above
  212. CAppConfig * QueryAppConfig();
  213. TCHAR * PSzCurrTemplatePhysPath();
  214. TCHAR * PSzCurrTemplateVirtPath();
  215. DWORD DWInstanceID();
  216. CTemplate *GetTemplate();
  217. void SetTemplate(CTemplate *);
  218. // Instead of add/remove to/from component collection use these:
  219. void HideRequestAndResponseIntrinsics();
  220. void UnHideRequestAndResponseIntrinsics();
  221. BOOL FRequestAndResponseIntrinsicsHidden();
  222. void AddScriptingNamespace(IUnknown *punkNamespace);
  223. void RemoveScriptingNamespace();
  224. void AddObjectContext(IASPObjectContext *pASPObjContext);
  225. void RemoveObjectContext();
  226. void UseObjectContext(IASPObjectContext **ppASPObjContext);
  227. // Typelib wrapper support
  228. IDispatch *PTypeLibWrapper();
  229. void SetTypeLibWrapper(IDispatch *pdisp);
  230. // Timestamp manipulation
  231. void UpdateTimestamp();
  232. DWORD ElapsedTimeSinceTimestamp();
  233. #ifdef DBG
  234. virtual void AssertValid() const;
  235. #else
  236. virtual void AssertValid() const {}
  237. #endif
  238. // Cache on per-class basis
  239. ACACHE_INCLASS_DEFINITIONS()
  240. };
  241. /*===================================================================
  242. CHitObj inlines
  243. ===================================================================*/
  244. inline CIsapiReqInfo *CHitObj::PIReq()
  245. {
  246. return m_pIReq;
  247. }
  248. inline BOOL CHitObj::FIsBrowserRequest() const
  249. {
  250. return (m_ehtType == ehtBrowserRequest);
  251. }
  252. inline BOOL CHitObj::FIsSessionCleanupRequest() const
  253. {
  254. return (m_ehtType == ehtSessionCleanup);
  255. }
  256. inline BOOL CHitObj::FIsApplnCleanupRequest() const
  257. {
  258. return (m_ehtType == ehtApplicationCleanup);
  259. }
  260. inline BOOL CHitObj::FIsValidRequestType() const
  261. {
  262. return (FIsBrowserRequest() ||
  263. FIsSessionCleanupRequest() ||
  264. FIsApplnCleanupRequest());
  265. }
  266. inline HANDLE CHitObj::HImpersonate()
  267. {
  268. return m_hImpersonate;
  269. }
  270. inline DWORD CHitObj::SessionId() const
  271. {
  272. return m_SessionId.m_dwId;
  273. }
  274. inline const char *CHitObj::PSzNewSessionCookie() const
  275. {
  276. return (m_fNewCookie ? m_szSessionCookie : NULL);
  277. }
  278. inline BOOL CHitObj::FStartApplication()
  279. {
  280. return m_fStartApplication;
  281. }
  282. inline BOOL CHitObj::FStartSession()
  283. {
  284. return m_fStartSession;
  285. }
  286. inline BOOL CHitObj::FNewCookie()
  287. {
  288. return m_fNewCookie;
  289. }
  290. inline BOOL CHitObj::FHasSession()
  291. {
  292. return (m_pSession != NULL && !m_fHideSessionIntrinsic);
  293. }
  294. inline BOOL CHitObj::FClientCodeDebug()
  295. {
  296. return m_fClientCodeDebug;
  297. }
  298. inline BOOL CHitObj::FDoneWithSession()
  299. {
  300. return m_fDoneWithSession;
  301. }
  302. inline BOOL CHitObj::FExecuting()
  303. {
  304. return m_fExecuting;
  305. }
  306. inline BOOL CHitObj::F449Done()
  307. {
  308. return m_f449Done;
  309. }
  310. inline BOOL CHitObj::FInTransferOnError()
  311. {
  312. return m_fInTransferOnError;
  313. }
  314. inline BOOL CHitObj::FSecure()
  315. {
  316. return m_fSecure;
  317. }
  318. inline void CHitObj::SessionOnStartFailed()
  319. {
  320. Assert(m_pSession);
  321. m_pSession->SetOnStartFailedFlag();
  322. }
  323. inline void CHitObj::ApplnOnStartFailed()
  324. {
  325. m_fApplnOnStartFailed = TRUE;
  326. if (m_pSession)
  327. SessionOnStartFailed();
  328. }
  329. inline void CHitObj::SessionOnStartInvoked()
  330. {
  331. Assert(m_pSession);
  332. m_pSession->SetOnStartInvokedFlag();
  333. }
  334. inline void CHitObj::SessionOnEndPresent()
  335. {
  336. Assert(m_pSession);
  337. m_pSession->SetOnEndPresentFlag();
  338. }
  339. inline DWORD CHitObj::DWInstanceID()
  340. {
  341. return (m_pIReq) ? m_pIReq->QueryInstanceId() : 0;
  342. }
  343. inline CViperActivity *CHitObj::PActivity()
  344. {
  345. return m_pActivity;
  346. }
  347. inline CScriptingContext *CHitObj::PScriptingContextGet()
  348. {
  349. return m_pScriptingContext;
  350. }
  351. inline CResponse *CHitObj::PResponse()
  352. {
  353. return m_pResponse;
  354. }
  355. inline CRequest *CHitObj::PRequest()
  356. {
  357. return m_pRequest;
  358. }
  359. inline CServer *CHitObj::PServer()
  360. {
  361. return m_pServer;
  362. }
  363. inline CAppln *CHitObj::PAppln()
  364. {
  365. return m_pAppln;
  366. }
  367. inline CSession *CHitObj::PSession()
  368. {
  369. return m_pSession;
  370. }
  371. inline CPageComponentManager *CHitObj::PPageComponentManager()
  372. {
  373. return m_pPageObjMgr;
  374. }
  375. inline TCHAR *CHitObj::GlobalAspPath()
  376. {
  377. if ( m_fRunGlobalAsa )
  378. return m_pAppln->GetGlobalAsa();
  379. else
  380. return NULL;
  381. }
  382. inline void CHitObj::SetScriptTimeout(long nScriptTimeout)
  383. {
  384. m_nScriptTimeout = nScriptTimeout;
  385. }
  386. inline long CHitObj::GetScriptTimeout()
  387. {
  388. return m_nScriptTimeout;
  389. }
  390. inline void CHitObj::SetExecStatus(EExecStatus status)
  391. {
  392. m_eExecStatus = status;
  393. }
  394. inline EExecStatus CHitObj::ExecStatus()
  395. {
  396. return m_eExecStatus;
  397. }
  398. inline EEventState CHitObj::EventState()
  399. {
  400. return m_eEventState;
  401. }
  402. inline void CHitObj::SetEventState(EEventState eState)
  403. {
  404. m_eEventState = eState;
  405. }
  406. inline CAppConfig * CHitObj::QueryAppConfig(void)
  407. {
  408. return m_pAppln->QueryAppConfig();
  409. }
  410. inline UINT CHitObj::GetCodePage(void)
  411. {
  412. return m_uCodePage;
  413. }
  414. inline LCID CHitObj::GetLCID()
  415. {
  416. return m_lcid;
  417. }
  418. inline VOID CHitObj::SetActiveEngineInfo(ActiveEngineInfo *pActiveEngineInfo)
  419. {
  420. m_pEngineInfo = pActiveEngineInfo;
  421. }
  422. inline void CHitObj::SetCompilationFailed()
  423. {
  424. m_fCompilationFailed = TRUE;
  425. }
  426. inline void CHitObj::SetDoneWithSession()
  427. {
  428. Assert(!m_fDoneWithSession);
  429. m_fDoneWithSession = TRUE;
  430. }
  431. inline void CHitObj::Set449Done()
  432. {
  433. Assert(!m_f449Done);
  434. m_f449Done = TRUE;
  435. }
  436. inline void CHitObj::SetInTransferOnError()
  437. {
  438. Assert(!m_fInTransferOnError);
  439. m_fInTransferOnError = TRUE;
  440. }
  441. inline void CHitObj::HideRequestAndResponseIntrinsics()
  442. {
  443. m_fHideRequestAndResponseIntrinsics = TRUE;
  444. }
  445. inline void CHitObj::UnHideRequestAndResponseIntrinsics()
  446. {
  447. m_fHideRequestAndResponseIntrinsics = FALSE;
  448. }
  449. inline BOOL CHitObj::FRequestAndResponseIntrinsicsHidden()
  450. {
  451. return m_fHideRequestAndResponseIntrinsics;
  452. }
  453. inline void CHitObj::AddScriptingNamespace(IUnknown *punkNamespace)
  454. {
  455. Assert(m_punkScriptingNamespace == NULL);
  456. Assert(punkNamespace);
  457. m_punkScriptingNamespace = punkNamespace;
  458. m_punkScriptingNamespace->AddRef();
  459. }
  460. inline void CHitObj::RemoveScriptingNamespace()
  461. {
  462. if (m_punkScriptingNamespace)
  463. {
  464. m_punkScriptingNamespace->Release();
  465. m_punkScriptingNamespace = NULL;
  466. }
  467. }
  468. inline IDispatch *CHitObj::PTypeLibWrapper()
  469. {
  470. return m_pdispTypeLibWrapper;
  471. }
  472. inline void CHitObj::SetTypeLibWrapper(IDispatch *pdisp)
  473. {
  474. if (m_pdispTypeLibWrapper)
  475. m_pdispTypeLibWrapper->Release();
  476. m_pdispTypeLibWrapper = pdisp;
  477. if (m_pdispTypeLibWrapper)
  478. m_pdispTypeLibWrapper->AddRef();
  479. }
  480. inline void CHitObj::UpdateTimestamp()
  481. {
  482. m_dwtTimestamp = GetTickCount();
  483. }
  484. inline DWORD CHitObj::ElapsedTimeSinceTimestamp()
  485. {
  486. DWORD dwt = GetTickCount();
  487. if (dwt >= m_dwtTimestamp)
  488. return (dwt - m_dwtTimestamp);
  489. else
  490. return ((0xffffffff - m_dwtTimestamp) + dwt);
  491. }
  492. inline TCHAR *CHitObj::PSzCurrTemplatePhysPath()
  493. {
  494. if (m_szCurrTemplatePhysPath != NULL)
  495. return m_szCurrTemplatePhysPath;
  496. else if (m_pIReq != NULL)
  497. return m_pIReq->QueryPszPathTranslated();
  498. else
  499. return NULL;
  500. }
  501. inline TCHAR *CHitObj::PSzCurrTemplateVirtPath()
  502. {
  503. if (m_szCurrTemplateVirtPath != NULL)
  504. return m_szCurrTemplateVirtPath;
  505. else if (m_pIReq != NULL)
  506. return m_pIReq->QueryPszPathInfo();
  507. else
  508. return NULL;
  509. }
  510. inline void CHitObj::SetASPError(IASPError *pASPError)
  511. {
  512. if (m_pASPError)
  513. m_pASPError->Release();
  514. m_pASPError = pASPError; // passed addref'd
  515. }
  516. inline BOOL CHitObj::FHasASPError()
  517. {
  518. return (m_pASPError != NULL);
  519. }
  520. inline CTemplate *CHitObj::GetTemplate()
  521. {
  522. return m_pTemplate;
  523. }
  524. inline void CHitObj::SetTemplate(CTemplate *pTemplate)
  525. {
  526. m_pTemplate = pTemplate;
  527. }
  528. /*===================================================================
  529. Globals
  530. ===================================================================*/
  531. extern DWORD g_nBrowserRequests;
  532. extern DWORD g_nSessionCleanupRequests;
  533. extern DWORD g_nApplnCleanupRequests;
  534. #undef SCRIPT_STATS
  535. #ifdef SCRIPT_STATS
  536. # include <locks.h>
  537. void
  538. ReadRegistrySettings();
  539. extern CSmallSpinLock g_lockRequestStats;
  540. extern DWORD g_dwQueueDebugThreshold;
  541. extern DWORD g_fSendScriptlessOnAtqThread;
  542. extern LONG g_cRequests;
  543. extern LONG g_cScriptlessRequests;
  544. extern LONG g_cHttpExtensionsExecuting;
  545. extern LONG g_cConcurrentScriptlessRequests;
  546. extern LONG g_cMaxConcurrentScriptlessRequests;
  547. extern LONGLONG g_nSumConcurrentScriptlessRequests;
  548. extern LONGLONG g_nSumExecTimeScriptlessRequests;
  549. extern LONG g_nAvgConcurrentScriptlessRequests;
  550. extern LONG g_nAvgExecTimeScriptlessRequests;
  551. #endif // SCRIPT_STATS
  552. #endif // HITOBJ_H