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.

796 lines
35 KiB

  1. /*==============================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. File: template.h
  6. Maintained by: DaveK
  7. Component: include file for Denali Compiled Template object
  8. ==============================================================================*/
  9. #ifndef _TEMPLATE_H
  10. #define _TEMPLATE_H
  11. #include "vector.h"
  12. #include "LinkHash.h"
  13. #include "Compcol.h"
  14. #include "util.h"
  15. #include "activdbg.h"
  16. #include "ConnPt.h"
  17. #include "DblLink.h"
  18. #include "aspdmon.h"
  19. #include "ie449.h"
  20. #include "memcls.h"
  21. #define PER_TEMPLATE_REFLOG 0
  22. /* NOTE we ensure that C_COUNTS_IN_HEADER is a multiple of 4 because the offsets which follow
  23. the counts in template header are dword-aligned. It is easiest (and fastest at runtime)
  24. to make sure those offsets start on a dword-alignment point; thus no runtime alignment calc
  25. is needed in GetAddress().
  26. */
  27. #define C_REAL_COUNTS_IN_HEADER 3 // actual number of count fields in template header
  28. #define C_COUNTS_IN_HEADER (C_REAL_COUNTS_IN_HEADER/4 + 1) * 4 // allocated number of count fields in template header
  29. #define C_OFFOFFS_IN_HEADER 4 // number of 'ptr-to-ptr' fields in template header
  30. #define CB_TEMPLATE_DEFAULT 2500 // default memory allocation for new template
  31. #define C_TARGET_LINES_DEFAULT 50 // default count of target script lines per engine
  32. #define C_TEMPLATES_PER_INCFILE_DEFAULT 4 // default count of templates per inc-file
  33. #define SZ_NULL "\0"
  34. #define WSTR_NULL L"\0"
  35. #define SZ_NEWLINE "\r\n"
  36. const unsigned CB_NEWLINE = strlen(SZ_NEWLINE);
  37. const LPSTR g_szWriteBlockOpen = "Response.WriteBlock(";
  38. const LPSTR g_szWriteBlockClose = ")";
  39. const LPSTR g_szWriteOpen = "Response.Write(";
  40. const LPSTR g_szWriteClose = ")";
  41. // defaults for buffering interim compile results
  42. #define C_SCRIPTENGINESDEFAULT 2 // default count of script engines
  43. #define C_SCRIPTSEGMENTSDEFAULT 20 // default count of script segments
  44. #define C_OBJECTINFOS_DEFAULT 10 // default count of object-infos
  45. #define C_HTMLSEGMENTSDEFAULT 20 // default count of HTML segments
  46. #define C_INCLUDELINESDEFAULT 5 // default count of include lines
  47. #define CB_TOKENS_DEFAULT 400 // default byte count for tokens
  48. #define CH_ATTRIBUTE_SEPARATOR '=' // separator for attribute-value pair
  49. #define CH_SINGLE_QUOTE '\'' // single-quote character
  50. #define CH_DOUBLE_QUOTE '"' // double-quote character
  51. #define CH_ESCAPE '\\' // escape character - tells us to ignore following token
  52. // ACLs: the following code should in future be shared with IIS (see creatfil.cxx in IIS project)
  53. // NOTE we want SECURITY_DESC_DEFAULT_SIZE to be relatively small, since it affects template memory reqt dramatically
  54. #define SECURITY_DESC_GRANULARITY 128 // 'chunk' size for re-sizing file security descriptor
  55. #define SECURITY_DESC_DEFAULT_SIZE 256 // initial default size of file security descriptor
  56. #define SIZE_PRIVILEGE_SET 128 // size of privilege set
  57. // macros
  58. // use outside of CTokenList class
  59. #define SZ_TOKEN(i) (*gm_pTokenList).m_bufTokens.PszLocal(i)
  60. #define CCH_TOKEN(i) (*gm_pTokenList)[i]->m_cb
  61. #define _TOKEN CTemplate::CTokenList::TOKEN
  62. // use within CTokenList class
  63. #define CCH_TOKEN_X(i) (*this)[i]->m_cb
  64. #define BR_TOKEN_X(i) *((*this)[i])
  65. // Use to specify which source file name you want (pathInfo or pathTranslated)
  66. #ifndef _SRCPATHTYPE_DEFINED
  67. #define _SRCPATHTYPE_DEFINED
  68. enum SOURCEPATHTYPE
  69. {
  70. SOURCEPATHTYPE_VIRTUAL = 0,
  71. SOURCEPATHTYPE_PHYSICAL = 1
  72. };
  73. #endif
  74. // CTemplate error codes
  75. #define E_COULDNT_OPEN_SOURCE_FILE 0x8000D001L
  76. #define E_SOURCE_FILE_IS_EMPTY 0x8000D002L
  77. #define E_TEMPLATE_COMPILE_FAILED 0x8000D003L
  78. #define E_USER_LACKS_PERMISSIONS 0x8000D004L
  79. #define E_TEMPLATE_COMPILE_FAILED_DONT_CACHE 0x8000D005L
  80. #define E_TEMPLATE_MAGIC_FAILURE 0x8000D006L
  81. inline BOOL FIsPreprocessorError(HRESULT hr)
  82. {
  83. return
  84. (
  85. hr == E_SOURCE_FILE_IS_EMPTY ||
  86. hr == E_TEMPLATE_COMPILE_FAILED ||
  87. hr == E_TEMPLATE_COMPILE_FAILED_DONT_CACHE ||
  88. hr == E_TEMPLATE_MAGIC_FAILURE
  89. );
  90. }
  91. //Can not use same index as CErrorInfo anymore.
  92. //Index for lastErrorInfo in Template
  93. #define ILE_szFileName 0
  94. #define ILE_szLineNum 1
  95. #define ILE_szEngine 2
  96. #define ILE_szErrorCode 3
  97. #define ILE_szShortDes 4
  98. #define ILE_szLongDes 5
  99. #define ILE_MAX 6
  100. // forward references
  101. class CTemplate;
  102. class CTemplateCacheManager;
  103. class CHitObj;
  104. class CTokenList;
  105. class CIncFile;
  106. typedef CLSID PROGLANG_ID; // NOTE also defined in scrptmgr.h; we define here to avoid include file circularity
  107. /* ============================================================================
  108. Class: CByteRange
  109. Synopsis: A range of bytes
  110. NOTE fLocal member is only used if the byte range is stored in a CBuffer
  111. NOTE 2
  112. m_pfilemap is really a pointer to a CFileMap - however, it's impossible
  113. to declare that type here because the CFileMap struct is nested inside
  114. CTemplate, and C++ won't let you forward declare nested classes. Since
  115. the CTemplate definition depends on CByteRange, properly declaring the
  116. type of "m_pfilemap" is impossible.
  117. */
  118. class CByteRange
  119. {
  120. public:
  121. BYTE* m_pb; // ptr to bytes
  122. ULONG m_cb; // count of bytes
  123. ULONG m_fLocal:1; // whether bytes are stored in buffer (TRUE) or elsewhere (FALSE)
  124. UINT m_idSequence:31; // byte range's sequence id
  125. void* m_pfilemap; // file the byte range comes from
  126. CByteRange(): m_pb(NULL), m_cb(0), m_fLocal(FALSE), m_idSequence(0), m_pfilemap(NULL) {}
  127. CByteRange(BYTE* pb, ULONG cb): m_fLocal(FALSE), m_idSequence(0) {m_pb = pb; m_cb = cb;}
  128. BOOLB IsNull() { return((m_pb == NULL) || (m_cb == 0)) ; }
  129. void Nullify() { m_pb = NULL; m_cb = 0; }
  130. void operator=(const CByteRange& br)
  131. { m_pb = br.m_pb; m_cb = br.m_cb; m_fLocal = br.m_fLocal; m_idSequence = br.m_idSequence; }
  132. BOOLB FMatchesSz(LPCSTR psz);
  133. void Advance(UINT i);
  134. BYTE* PbString(LPSTR psz, LONG lCodePage);
  135. BYTE* PbOneOfAspOpenerStringTokens(LPSTR rgszTokens[], UINT rgcchTokens[],
  136. UINT nTokens, UINT *pidToken);
  137. BOOLB FEarlierInSourceThan(CByteRange& br);
  138. };
  139. /* ============================================================================
  140. Enum type: TEMPLATE_COMPONENT
  141. Synopsis: A component of a template, e.g. script block, html block, etc.
  142. */
  143. enum TEMPLATE_COMPONENT
  144. {
  145. // NOTE enum values and order are tightly coupled with template layout order
  146. // DO NOT CHANGE
  147. tcompScriptEngine = 0,
  148. tcompScriptBlock,
  149. tcompObjectInfo,
  150. tcompHTMLBlock,
  151. };
  152. /* ****************************************************************************
  153. Class: CTemplateConnPt
  154. Synopsis: Connection point for IDebugDocumentTextEvents
  155. */
  156. class CTemplateConnPt : public CConnectionPoint
  157. {
  158. public:
  159. // ctor
  160. CTemplateConnPt(IConnectionPointContainer *pContainer, const GUID &uidConnPt)
  161. : CConnectionPoint(pContainer, uidConnPt) {}
  162. // IUnknown methods
  163. STDMETHOD(QueryInterface)(const GUID &, void **);
  164. STDMETHOD_(ULONG, AddRef)();
  165. STDMETHOD_(ULONG, Release)();
  166. };
  167. /* ****************************************************************************
  168. Class: CTemplateKey
  169. Synopsis: Packaged data to locate template in hash table
  170. (instance ID, and template name)
  171. */
  172. #define MATCH_ALL_INSTANCE_IDS 0xFFFBAD1D // unlikely instance ID. sort of spells "BAD ID"
  173. struct CTemplateKey
  174. {
  175. const TCHAR * szPathTranslated;
  176. DWORD dwInstanceID;
  177. CTemplateKey(const TCHAR *_szPathTranslated = NULL, UINT _dwInstanceID = MATCH_ALL_INSTANCE_IDS)
  178. : szPathTranslated(_szPathTranslated),
  179. dwInstanceID(_dwInstanceID) {}
  180. };
  181. /* ****************************************************************************
  182. Class: CTemplate
  183. Synopsis: A Denali compiled template.
  184. NOTE: CTemplate's primary client is CTemplateCacheManager, which maintains
  185. a cache of compiled templates.
  186. USAGE
  187. -----
  188. The CTemplate class must be used as follows:
  189. CLASS INIT - InitClass must be called before any CTemplate can be created.
  190. NEW TEMPLATE - For each new template the client wants to create, the client
  191. must do the following, in order:
  192. 1) New a CTemplate
  193. 2) Initialize the CTemplate by calling Init, passing a source file name
  194. 3) Load the CTemplate by calling Load; when Load returns, the new CTemplate is ready for use.
  195. EXISTING TEMPLATE - To use an existing template, the client must:
  196. 1) Call Deliver; when Deliver returns, the existing CTemplate is ready for use.
  197. CLASS UNINIT - UnInitClass must be called after the last CTemplate has been destroyed.
  198. To ensure thread-safety, the client must implement a critical section
  199. around the call to Init. Init is designed to be as fast as possible,
  200. so the client can quickly learn that it has a pending template for a given
  201. source file, and queue up other requests for the same source file.
  202. CTemplate provides implementations for Debug documents, namely
  203. IDebugDocumentProvider & IDebugDocumentText
  204. */
  205. class CActiveScriptEngine;
  206. class CTemplate :
  207. public CDblLink,
  208. public IDebugDocumentProvider,
  209. public IDebugDocumentText,
  210. public IConnectionPointContainer // Source of IDebugDocumentTextEvents
  211. {
  212. private:
  213. #include "templcap.h" // 'captive' classes, only used internally within CTemplate
  214. friend HRESULT InitMemCls();
  215. friend HRESULT UnInitMemCls();
  216. friend class CTemplateCacheManager; // TODO: decouple CTemplate class from it's manager class
  217. friend class CFileMap;
  218. friend class CIncFile; // IncFiles are privy to debugging data structures
  219. // CScriptStore::Init() must access gm_brDefaultScriptLanguage, gm_progLangIdDefault
  220. friend HRESULT CTemplate::CScriptStore::Init(LPCSTR szDefaultScriptLanguage, CLSID *pCLSIDDefaultEngine);
  221. private:
  222. CWorkStore* m_pWorkStore; // ptr to working storage for source segments
  223. HANDLE m_hEventReadyForUse; // ready-for-use event handle
  224. public:
  225. BYTE* m_pbStart; // ptr to start of template memory
  226. ULONG m_cbTemplate; // bytes allocated for template
  227. LONG m_cRefs; // ref count - NOTE LONG required by InterlockedIncrement
  228. private:
  229. CTemplateConnPt m_CPTextEvents; // Connection point for IDebugDocumentTextEvents
  230. // support for compile-time errors
  231. BYTE* m_pbErrorLocation; // ptr to error location in source file
  232. UINT m_idErrMsg; // error message id
  233. UINT m_cMsgInserts; // count of insert strings for error msg
  234. char** m_ppszMsgInserts; // array of ptrs to error msg insert strings
  235. // support for run-time errors and debugging
  236. UINT m_cScriptEngines; // count of script engines
  237. CActiveScriptEngine **m_rgpDebugScripts;// array (indexed by engine) of scripts CURRENTLY BEING DEBUGGED
  238. vector<CSourceInfo> *m_rgrgSourceInfos; // array of arrays of script source line infos, one per script engine per target line
  239. ULONG m_cbTargetOffsetPrevT; // running total of last source offset processed
  240. CRITICAL_SECTION m_csDebuggerDetach; // CS needed to avoid race condition with detaching from debugger
  241. CDblLink m_listDocNodes; // list of document nodes we are attached to
  242. CFileMap** m_rgpFilemaps; // array of ptrs to filemaps of source files
  243. CTemplateKey m_LKHashKey; // bundled info for key (contains copy of m_rgpfilemaps[0] filename to make things simpler
  244. UINT m_cFilemaps; // count of filemaps of source files
  245. CFileMap** m_rgpSegmentFilemaps; // array of filemap ptrs per source segment
  246. UINT m_cSegmentFilemapSlots; // count of per-source-segment filemap ptrs
  247. LPSTR m_pszLastErrorInfo[6]; // text of last error - cached for new requests on this template
  248. // FileName, LineNum, Engine, ShortDes, LongDes
  249. DWORD m_dwLastErrorMask; // cached for new requests on this template
  250. DWORD m_hrOnNoCache; // HRESULT when don't cache is set.
  251. TCHAR* m_szApplnVirtPath; // application virtual path (substring of Application URL)
  252. TCHAR* m_szApplnURL; // application URL (starts with "http://")
  253. // for best structure packing we all boleans here as bitfields
  254. unsigned m_fGlobalAsa:1; // is template for global.asa file?
  255. unsigned m_fIsValid:1; // is template in valid state?
  256. unsigned m_fDontCache:1; // don't cache this template
  257. unsigned m_fReadyForUse:1; // is template ready for use?
  258. unsigned m_fDebuggerDetachCSInited:1;// has debugger attach critical section been initialized?
  259. unsigned m_fDontAttach:1; // should not be attached to debugger (not in cache)
  260. unsigned m_fSession:1; // does this page require session state
  261. unsigned m_fScriptless:1; // doesn't have any scripts
  262. unsigned m_fDebuggable:1; // is this page part of at least one debuggable app?
  263. unsigned m_fZombie:1; // File template is based on has changed since obtained from cache
  264. unsigned m_fCodePageSet:1; // Did template contain a code page directive
  265. unsigned m_fLCIDSet:1; // Did template contain an LCID directive
  266. unsigned m_fIsPersisted:1;
  267. TransType m_ttTransacted; // type of transaction support
  268. // class-wide support for compilation
  269. static CTokenList* gm_pTokenList; // array of tokens
  270. unsigned m_wCodePage; // Compiler Time CodePage
  271. long m_lLCID; // Compile Time LCID
  272. vector<ITypeLib *> m_rgpTypeLibs; // array of ptrs to typelibs
  273. IDispatch* m_pdispTypeLibWrapper; // typelib wrapper object
  274. vector<C449Cookie *> m_rgp449; // array of ptrs to 449 requests
  275. LPSTR m_szPersistTempName; // filename of persisted template, if any
  276. void *m_pHashTable; // CacheMgr hash table that this template is on
  277. IUnknown *m_pServicesConfig;
  278. static HANDLE sm_hSmallHeap;
  279. static HANDLE sm_hLargeHeap;
  280. public:
  281. /**
  282. ** Initialization and destruction public interfaces
  283. **/
  284. // Initializes CTemplate static members; must be called on denali.dll load
  285. static HRESULT InitClass();
  286. // Un-initilaizes CTemplate static members; must be called on denali.dll unload
  287. static void UnInitClass();
  288. // Inits template in preparation for compilation
  289. // Called by template cache mgr before calling Load
  290. HRESULT Init(CHitObj* pHitObj, BOOL fGlobalAsp, const CTemplateKey &rTemplateKey);
  291. // Compiles the template from its main source file (and include files, if any)
  292. HRESULT Compile(CHitObj* pHitObj);
  293. // Called by requestor of existing template to determine if template is ready for use
  294. HRESULT Deliver(CHitObj* pHitObj);
  295. // Create this template's CServicesConfig object
  296. HRESULT CreateTransServiceConfig(BOOL fEnableTracker);
  297. CTemplate();
  298. ~CTemplate();
  299. void RemoveIncFile(CIncFile* pIncFile);
  300. // Trace Log info
  301. static PTRACE_LOG gm_pTraceLog;
  302. public:
  303. #if PER_TEMPLATE_REFLOG
  304. PTRACE_LOG m_pTraceLog;
  305. #endif
  306. /*
  307. 'Consumer' public interfaces
  308. Methods for getting info out of a CTemplate
  309. */
  310. // Returns name of source file on which this template is based
  311. LPTSTR GetSourceFileName(SOURCEPATHTYPE = SOURCEPATHTYPE_PHYSICAL);
  312. // Returns virtual path of the source file
  313. LPTSTR GetApplnPath(SOURCEPATHTYPE = SOURCEPATHTYPE_PHYSICAL);
  314. // Returns hashing key of the template
  315. const CTemplateKey *ExtractHashKey() const;
  316. // Returns version stamp of compiler by which this template was compiled
  317. LPSTR GetCompilerVersion();
  318. // Component counts
  319. USHORT Count(TEMPLATE_COMPONENT tcomp);
  320. USHORT CountScriptEngines() { return (USHORT)m_cScriptEngines; }
  321. // Returns i-th script block as ptr to prog lang id and ptr to script text
  322. void GetScriptBlock(UINT i, LPSTR* pszScriptEngine, PROGLANG_ID** ppProgLangId, LPCOLESTR* pwstrScriptText);
  323. // Returns i-th object-info as object name, clsid, scope, model
  324. HRESULT GetObjectInfo(UINT i, LPSTR* ppszObjectName,
  325. CLSID *pClsid, CompScope *pScope, CompModel *pcmModel);
  326. // Returns i-th HTML block as ptr, count of bytes, original offset, incl filename
  327. HRESULT GetHTMLBlock(UINT i, LPSTR* pszHTML, ULONG* pcbHTML, ULONG* pcbSrcOffs, LPSTR* pszSrcIncFile);
  328. // Returns line number and source file name a given target line in a given script engine.
  329. void GetScriptSourceInfo(UINT idEngine, int iTargetLine, LPTSTR* pszPathInfo, LPTSTR* pszPathTranslated, ULONG* piSourceLine, ULONG* pichSourceLine, BOOLB* pfGuessedLine);
  330. // Converts a character offset from the target script to the offset in the source
  331. void GetSourceOffset(ULONG idEngine, ULONG cchTargetOffset, TCHAR **pszSourceFile, ULONG *pcchSourceOffset, ULONG *pcchSourceText);
  332. // Converts a character offset from the source document to the offset in the target
  333. BOOL GetTargetOffset(TCHAR *szSourceFile, ULONG cchSourceOffset, ULONG *pidEngine, ULONG *pcchTargetOffset);
  334. // Get the character position of a line (directly implements debugging interface)
  335. HRESULT GetPositionOfLine(CFileMap *pFilemap, ULONG cLineNumber, ULONG *pcCharacterPosition);
  336. // Get the line # of a character position (directly implements debugging interface)
  337. HRESULT GetLineOfPosition(CFileMap *pFilemap, ULONG cCharacterPosition, ULONG *pcLineNumber, ULONG *pcCharacterOffsetInLine);
  338. // Return a RUNNING script based on the engine, or NULL if code context has never been requested yet
  339. CActiveScriptEngine *GetActiveScript(ULONG idEngine);
  340. // associate a running script for an engine ID (Use after you get the first code context)
  341. HRESULT AddScript(ULONG idEngine, CActiveScriptEngine *pScriptEngine);
  342. // attach the CTemplate object to an application (debugger tree view)
  343. HRESULT AttachTo(CAppln *pAppln);
  344. // detach the CTemplate object from an application (debugger tree view)
  345. HRESULT DetachFrom(CAppln *pAppln);
  346. // detach the CTemplate object all applications (and release script engines)
  347. HRESULT Detach();
  348. // Signifies last use of template as a recylable object. Any outstanding references
  349. // should be from currently executing scripts.
  350. ULONG End();
  351. // Let debugger know about page start/end
  352. HRESULT NotifyDebuggerOnPageEvent(BOOL fStart);
  353. // Generate 449 response in cookie negotiations with IE when needed
  354. HRESULT Do449Processing(CHitObj *pHitObj);
  355. HRESULT PersistData(char *pszTempFilePath);
  356. HRESULT UnPersistData();
  357. HRESULT PersistCleanup();
  358. ULONG TemplateSize() { return m_cbTemplate; }
  359. BOOL FTransacted();
  360. BOOL FSession();
  361. BOOL FScriptless();
  362. BOOL FDebuggable();
  363. BOOL FIsValid(); // determine if compilation succeeded
  364. BOOL FTemplateObsolete();
  365. BOOL FGlobalAsa();
  366. BOOL FIsZombie();
  367. BOOL FDontAttach();
  368. BOOL FIsPersisted();
  369. VOID Zombify();
  370. IUnknown *PServicesConfig() {return m_pServicesConfig;};
  371. IDispatch *PTypeLibWrapper();
  372. void SetHashTablePtr(void *pTable) { m_pHashTable = pTable; }
  373. void *GetHashTablePtr() { return m_pHashTable; }
  374. public:
  375. /*
  376. COM public interfaces
  377. Implementation of debugging documents.
  378. */
  379. // IUnknown methods
  380. STDMETHOD(QueryInterface)(const GUID &, void **);
  381. STDMETHOD_(ULONG, AddRef)();
  382. STDMETHOD_(ULONG, Release)();
  383. // IDebugDocumentProvider methods
  384. STDMETHOD(GetDocument)(/* [out] */ IDebugDocument **ppDebugDoc);
  385. // IDebugDocumentInfo (also IDebugDocumentProvider) methods
  386. STDMETHOD(GetName)(
  387. /* [in] */ DOCUMENTNAMETYPE dnt,
  388. /* [out] */ BSTR *pbstrName);
  389. STDMETHOD(GetDocumentClassId)(/* [out] */ CLSID *)
  390. {
  391. return E_NOTIMPL;
  392. }
  393. // IDebugDocumentText methods
  394. STDMETHOD(GetDocumentAttributes)(
  395. /* [out] */ TEXT_DOC_ATTR *ptextdocattr);
  396. STDMETHOD(GetSize)(
  397. /* [out] */ ULONG *pcLines,
  398. /* [out] */ ULONG *pcChars);
  399. STDMETHOD(GetPositionOfLine)(
  400. /* [in] */ ULONG cLineNumber,
  401. /* [out] */ ULONG *pcCharacterPosition);
  402. STDMETHOD(GetLineOfPosition)(
  403. /* [in] */ ULONG cCharacterPosition,
  404. /* [out] */ ULONG *pcLineNumber,
  405. /* [out] */ ULONG *pcCharacterOffsetInLine);
  406. STDMETHOD(GetText)(
  407. /* [in] */ ULONG cCharacterPosition,
  408. /* [size_is][length_is][out][in] */ WCHAR *pcharText,
  409. /* [size_is][length_is][out][in] */ SOURCE_TEXT_ATTR *pstaTextAttr,
  410. /* [out][in] */ ULONG *pcChars,
  411. /* [in] */ ULONG cMaxChars);
  412. STDMETHOD(GetPositionOfContext)(
  413. /* [in] */ IDebugDocumentContext *psc,
  414. /* [out] */ ULONG *pcCharacterPosition,
  415. /* [out] */ ULONG *cNumChars);
  416. STDMETHOD(GetContextOfPosition)(
  417. /* [in] */ ULONG cCharacterPosition,
  418. /* [in] */ ULONG cNumChars,
  419. /* [out] */ IDebugDocumentContext **ppsc);
  420. // IConnectionPointContainer methods
  421. STDMETHOD(EnumConnectionPoints)(
  422. /* [out] */ IEnumConnectionPoints __RPC_FAR *__RPC_FAR *ppEnum)
  423. {
  424. return E_NOTIMPL; // doubt we need this - client is expecting only TextEvents
  425. }
  426. STDMETHOD(FindConnectionPoint)(
  427. /* [in] */ const IID &iid,
  428. /* [out] */ IConnectionPoint **ppCP);
  429. private:
  430. /* NOTE Compile() works by calling GetSegmentsFromFile followed by WriteTemplate
  431. Most other private methods support one of these two workhorse functions
  432. */
  433. void AppendMapFile(LPCTSTR szFileSpec, CFileMap* pfilemapParent, BOOLB fVirtual,
  434. CHitObj* pHitObj, BOOLB fGlobalAsp);
  435. void GetSegmentsFromFile(CFileMap& filemap, CWorkStore& WorkStore, CHitObj* pHitObj, BOOL fIsHTML = TRUE);
  436. void GetLanguageEquivalents();
  437. void SetLanguageEquivalent(HANDLE hKeyScriptLanguage, LPSTR szLanguageItem, LPSTR* pszOpen, LPSTR* pszClose);
  438. void ThrowError(BYTE* pbErrorLocation, UINT idErrMsg);
  439. void AppendErrorMessageInsert(BYTE* pbInsert, UINT cbInsert);
  440. void ThrowErrorSingleInsert(BYTE* pbErrorLocation, UINT idErrMsg, BYTE* pbInsert, UINT cbInsert);
  441. HRESULT ShowErrorInDebugger(CFileMap* pFilemap, UINT cchErrorLocation, char* szDescription, CHitObj* pHitObj, BOOL fAttachDocument);
  442. void ProcessSpecificError(CFileMap& filemap, CHitObj* pHitObj);
  443. void HandleCTemplateError(CFileMap* pfilemap, BYTE* pbErrorLocation,
  444. UINT idErrMsg, UINT cInserts, char** ppszInserts, CHitObj *pHitObj);
  445. void FreeGoodTemplateMemory();
  446. void UnmapFiles();
  447. // ExtractAndProcessSegment: gets and processes next source segment in search range
  448. void ExtractAndProcessSegment(CByteRange& brSearch, const SOURCE_SEGMENT& ssegLeading,
  449. _TOKEN* rgtknOpeners, UINT ctknOpeners, CFileMap* pfilemapCurrent, CWorkStore& WorkStore,
  450. CHitObj* pHitObj, BOOL fScriptTagProcessed = FALSE, BOOL fIsHTML = TRUE);
  451. // Support methods for ExtractAndProcessSegment()
  452. SOURCE_SEGMENT SsegFromHTMLComment(CByteRange& brSegment);
  453. void ProcessSegment(SOURCE_SEGMENT sseg, CByteRange& brSegment, CFileMap* pfilemapCurrent,
  454. CWorkStore& WorkStore, BOOL fScriptTagProcessed, CHitObj* pHitObj,
  455. BOOL fIsHTML);
  456. void ProcessHTMLSegment(CByteRange& brHTML, CBuffer& bufHTMLBlocks, UINT idSequence, CFileMap* pfilemapCurrent);
  457. void ProcessHTMLCommentSegment(CByteRange& brSegment, CFileMap* pfilemapCurrent, CWorkStore& WorkStore, CHitObj* pHitObj);
  458. void ProcessScriptSegment(SOURCE_SEGMENT sseg, CByteRange& brSegment, CFileMap* pfilemapCurrent,
  459. CWorkStore& WorkStore, UINT idSequence, BOOLB fScriptTagProcessed, CHitObj* pHitObj);
  460. HRESULT ProcessMetadataSegment(const CByteRange& brSegment, UINT *pidError, CHitObj* pHitObj);
  461. HRESULT ProcessMetadataTypelibSegment(const CByteRange& brSegment, UINT *pidError, CHitObj* pHitObj);
  462. HRESULT ProcessMetadataCookieSegment(const CByteRange& brSegment, UINT *pidError, CHitObj* pHitObj);
  463. void GetScriptEngineOfSegment(CByteRange& brSegment, CByteRange& brEngine, CByteRange& brInclude);
  464. void ProcessTaggedScriptSegment(CByteRange& brSegment, CFileMap* pfilemapCurrent, CWorkStore& WorkStore, CHitObj* pHitObj);
  465. void ProcessObjectSegment(CByteRange& brSegment, CFileMap* pfilemapCurrent, CWorkStore& WorkStore,
  466. UINT idSequence);
  467. void GetCLSIDFromBrClassIDText(CByteRange& brClassIDText, LPCLSID pclsid);
  468. void GetCLSIDFromBrProgIDText(CByteRange& brProgIDText, LPCLSID pclsid);
  469. BOOLB FValidObjectName(CByteRange& brName);
  470. void ProcessIncludeFile(CByteRange& brSegment, CFileMap* pfilemapCurrent, CWorkStore& WorkStore, UINT idSequence, CHitObj* pHitObj, BOOL fIsHTML);
  471. void ProcessIncludeFile2(CHAR* szFileSpec, CByteRange& brFileSpec, CFileMap* pfilemapCurrent, CWorkStore& WorkStore, UINT idSequence, CHitObj* pHitObj, BOOL fIsHTML);
  472. BYTE* GetOpenToken(CByteRange brSearch, SOURCE_SEGMENT ssegLeading, _TOKEN* rgtknOpeners, UINT ctknOpeners, _TOKEN* ptknOpen);
  473. BYTE* GetCloseToken(CByteRange brSearch, _TOKEN tknClose);
  474. _TOKEN GetComplementToken(_TOKEN tkn);
  475. SOURCE_SEGMENT GetSegmentOfOpenToken(_TOKEN tknOpen);
  476. CByteRange BrTagsFromSegment(CByteRange brSegment, _TOKEN tknClose, BYTE** ppbCloseTag);
  477. CByteRange BrValueOfTag(CByteRange brTags, _TOKEN tknTag);
  478. BYTE* GetTagName(CByteRange brTags, _TOKEN tknTagName);
  479. BOOL GetTag(CByteRange &brTags, int nIndex = 1);
  480. BOOL CompTagName(CByteRange &brTags, _TOKEN tknTagName);
  481. BOOLB FTagHasValue(const CByteRange& brTags, _TOKEN tknTag, _TOKEN tknValue);
  482. void CopySzAdv(char* pchWrite, LPSTR psz);
  483. // WriteTemplate: writes the template to a contiguous block of memory
  484. void WriteTemplate(CWorkStore& WorkStore, CHitObj* pHitObj);
  485. // Support methods for WriteTemplate()
  486. // NOTE Adv suffix on some function names == advance ptr after writing
  487. void WriteHeader(USHORT cScriptBlocks,USHORT cObjectInfos, USHORT cHTMLBlocks, UINT* pcbHeaderOffset, UINT* pcbOffsetToOffset);
  488. void WriteScriptBlockOfEngine(USHORT idEnginePrelim, USHORT idEngine, CWorkStore& WorkStore, UINT* pcbDataOffset,
  489. UINT* pcbOffsetToOffset, CHitObj* pHitObj);
  490. void WritePrimaryScriptProcedure(USHORT idEngine, CWorkStore& WorkStore, UINT* pcbDataOffset, UINT cbScriptBlockStart);
  491. void WriteScriptSegment(USHORT idEngine, CFileMap* pfilemap, CByteRange& brScript, UINT* pcbDataOffset, UINT cbScriptBlockStart,
  492. BOOL fAllowExprWrite);
  493. void WriteScriptMinusEscapeChars(CByteRange brScript, UINT* pcbDataOffset, UINT* pcbPtrOffset);
  494. BOOLB FVbsComment(CByteRange& brLine);
  495. BOOLB FExpression(CByteRange& brLine);
  496. void WriteOffsetToOffset(USHORT cBlocks, UINT* pcbHeaderOffset, UINT* pcbOffsetToOffset);
  497. void WriteSzAsBytesAdv(LPCSTR szSource, UINT* pcbDataOffset);
  498. void WriteByteRangeAdv(CByteRange& brSource, BOOLB fWriteAsBsz, UINT* pcbDataOffset, UINT* pcbPtrOffset);
  499. void WriteLongAdv(ULONG uSource, UINT* pcbOffset);
  500. void WriteShortAdv(USHORT uSource, UINT* pcbOffset);
  501. void MemCpyAdv(UINT* pcbOffset, void* pbSource, ULONG cbSource, UINT cbByteAlign = 0);
  502. // Memory access primitives
  503. // NOTE invalid until WriteTemplate() has succeeded
  504. BYTE* GetAddress(TEMPLATE_COMPONENT tcomp, USHORT i);
  505. // Debugging methods
  506. void AppendSourceInfo(USHORT idEngine, CFileMap* pfilemap, BYTE* pbSource,
  507. ULONG cbSourceOffset, ULONG cbScriptBlockOffset, ULONG cbTargetOffset,
  508. ULONG cchSourceText, BOOL fIsHTML);
  509. UINT SourceLineNumberFromPb(CFileMap* pfilemap, BYTE* pbSource);
  510. HRESULT CreateDocumentTree(CFileMap *pfilemapRoot, IDebugApplicationNode **ppDocRoot);
  511. BOOLB FIsLangVBScriptOrJScript(USHORT idEngine);
  512. #if 0
  513. void OutputDebugTables();
  514. void OutputIncludeHierarchy(CFileMap *pfilemap, int cchIndent);
  515. void GetScriptSnippets(ULONG cchSourceOffset, CFileMap *pFilemapSource, ULONG cchTargetOffset, ULONG idTargetEngine, wchar_t wszSourceText[], wchar_t wszTargetText[]);
  516. #endif
  517. void RemoveFromIncFiles();
  518. void ReleaseTypeLibs();
  519. void WrapTypeLibs(CHitObj *pHitObj);
  520. void Release449();
  521. HRESULT BuildPersistedDACL(PACL *ppRetDACL);
  522. // Cache on per-class basis
  523. ACACHE_INCLASS_DEFINITIONS()
  524. public:
  525. // memory allocation
  526. static void* SmallMalloc(SIZE_T dwBytes);
  527. static void* SmallReAlloc(void* pvMem, SIZE_T dwBytes);
  528. static void SmallFree(void* pvMem);
  529. static void* LargeMalloc(SIZE_T dwBytes);
  530. static void* LargeReAlloc(void* pvMem, SIZE_T dwBytes);
  531. static void LargeFree(void* pvMem);
  532. };
  533. ////////////////////////////////////////////////////////////////////////////////
  534. // Inline functions
  535. // Write a long or short to memory, then advance target-ptr
  536. inline void CTemplate::WriteLongAdv(ULONG uSource, UINT* pcbOffset)
  537. { MemCpyAdv(pcbOffset, &uSource, sizeof(ULONG), sizeof(ULONG)); }
  538. inline void CTemplate::WriteShortAdv(USHORT uSource, UINT* pcbOffset)
  539. { MemCpyAdv(pcbOffset, &uSource, sizeof(USHORT), sizeof(USHORT)); }
  540. inline const CTemplateKey * CTemplate::ExtractHashKey() const
  541. { return &m_LKHashKey; }
  542. inline BOOL CTemplate::FTransacted()
  543. { return (m_ttTransacted != ttUndefined); }
  544. inline BOOL CTemplate::FDebuggable()
  545. { return(m_fDebuggable); }
  546. inline BOOL CTemplate::FSession()
  547. { return(m_fSession); }
  548. inline BOOL CTemplate::FScriptless()
  549. { return m_fScriptless; }
  550. inline BOOL CTemplate::FIsValid()
  551. { return(m_fIsValid); }
  552. inline BOOL CTemplate::FGlobalAsa()
  553. { return(m_fGlobalAsa); }
  554. inline BOOL CTemplate::FIsZombie()
  555. { return m_fZombie; }
  556. inline VOID CTemplate::Zombify()
  557. { m_fZombie = TRUE; }
  558. inline BOOL CTemplate::FDontAttach()
  559. { return (m_fDontAttach); }
  560. inline BOOL CTemplate::FIsPersisted()
  561. { return (m_fIsPersisted); }
  562. inline LPTSTR CTemplate::GetApplnPath(SOURCEPATHTYPE pathtype)
  563. { Assert (pathtype == SOURCEPATHTYPE_VIRTUAL); return m_szApplnVirtPath; }
  564. inline IDispatch *CTemplate::PTypeLibWrapper()
  565. { return (m_pdispTypeLibWrapper); }
  566. /* ****************************************************************************
  567. Class: CIncFile
  568. Synopsis: A file included by one or more templates.
  569. NOTE: We store an incfile-template dependency by storing a template ptr in m_rgpTemplates.
  570. This is efficient but ***will break if we ever change Denali to move its memory around***
  571. */
  572. class CIncFile :
  573. private CLinkElem,
  574. public IDebugDocumentProvider,
  575. public IDebugDocumentText,
  576. public IConnectionPointContainer // Source of IDebugDocumentTextEvents
  577. {
  578. // CIncFileMap is a friend so that it can manipulate CLinkElem private members and to access m_ftLastWriteTime
  579. friend class CIncFileMap;
  580. private:
  581. LONG m_cRefs; // ref count - NOTE LONG required by InterlockedIncrement
  582. TCHAR * m_szIncFile; // include file name - NOTE we keep this as a stable ptr to hash table key
  583. CRITICAL_SECTION m_csUpdate; // CS for updating the template ptrs array
  584. vector<CTemplate *> m_rgpTemplates; // array of ptrs to templates which include this include file
  585. CTemplateConnPt m_CPTextEvents; // Connection point for IDebugDocumentTextEvents
  586. BOOLB m_fCsInited; // has CS been initialized yet?
  587. CTemplate::CFileMap *GetFilemap(); // Return the filemap pointer from a template
  588. public:
  589. CIncFile();
  590. HRESULT Init(const TCHAR* szIncFile);
  591. ~CIncFile();
  592. HRESULT AddTemplate(CTemplate* pTemplate);
  593. void RemoveTemplate(CTemplate* pTemplate);
  594. CTemplate* GetTemplate(int iTemplate);
  595. BOOL FlushTemplates();
  596. TCHAR * GetIncFileName() { return m_szIncFile; }
  597. void OnIncFileDecache();
  598. /*
  599. COM public interfaces
  600. Implementation of debugging documents.
  601. */
  602. // IUnknown methods
  603. STDMETHOD(QueryInterface)(const GUID &, void **);
  604. STDMETHOD_(ULONG, AddRef)();
  605. STDMETHOD_(ULONG, Release)();
  606. // IDebugDocumentProvider methods
  607. STDMETHOD(GetDocument)(/* [out] */ IDebugDocument **ppDebugDoc);
  608. // IDebugDocumentInfo (also IDebugDocumentProvider) methods
  609. STDMETHOD(GetName)(
  610. /* [in] */ DOCUMENTNAMETYPE dnt,
  611. /* [out] */ BSTR *pbstrName);
  612. STDMETHOD(GetDocumentClassId)(/* [out] */ CLSID *)
  613. {
  614. return E_NOTIMPL;
  615. }
  616. // IDebugDocumentText methods
  617. STDMETHOD(GetDocumentAttributes)(
  618. /* [out] */ TEXT_DOC_ATTR *ptextdocattr);
  619. STDMETHOD(GetSize)(
  620. /* [out] */ ULONG *pcLines,
  621. /* [out] */ ULONG *pcChars);
  622. STDMETHOD(GetPositionOfLine)(
  623. /* [in] */ ULONG cLineNumber,
  624. /* [out] */ ULONG *pcCharacterPosition);
  625. STDMETHOD(GetLineOfPosition)(
  626. /* [in] */ ULONG cCharacterPosition,
  627. /* [out] */ ULONG *pcLineNumber,
  628. /* [out] */ ULONG *pcCharacterOffsetInLine);
  629. STDMETHOD(GetText)(
  630. /* [in] */ ULONG cCharacterPosition,
  631. /* [size_is][length_is][out][in] */ WCHAR *pcharText,
  632. /* [size_is][length_is][out][in] */ SOURCE_TEXT_ATTR *pstaTextAttr,
  633. /* [out][in] */ ULONG *pcChars,
  634. /* [in] */ ULONG cMaxChars);
  635. STDMETHOD(GetPositionOfContext)(
  636. /* [in] */ IDebugDocumentContext *psc,
  637. /* [out] */ ULONG *pcCharacterPosition,
  638. /* [out] */ ULONG *cNumChars);
  639. STDMETHOD(GetContextOfPosition)(
  640. /* [in] */ ULONG cCharacterPosition,
  641. /* [in] */ ULONG cNumChars,
  642. /* [out] */ IDebugDocumentContext **ppsc);
  643. // IConnectionPointContainer methods
  644. STDMETHOD(EnumConnectionPoints)(
  645. /* [out] */ IEnumConnectionPoints __RPC_FAR *__RPC_FAR *ppEnum)
  646. {
  647. return E_NOTIMPL; // doubt we need this - client is expecting only TextEvents
  648. }
  649. STDMETHOD(FindConnectionPoint)(
  650. /* [in] */ const IID &iid,
  651. /* [out] */ IConnectionPoint **ppCP);
  652. };
  653. #endif /* _TEMPLATE_H */