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.

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