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.

415 lines
15 KiB

  1. /*==============================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996-1999 Microsoft Corporation. All Rights Reserved.
  5. File: templcap.h
  6. Maintained by: DaveK
  7. Component: include file for CTemplate 'captive' classes
  8. 'captive' == only used internally within CTemplate
  9. ==============================================================================*/
  10. // forward refs
  11. class CBuffer;
  12. class CFileMap;
  13. class DIR_MONTIOR_ENTRY;
  14. /* ============================================================================
  15. Enum type: SOURCE_SEGMENT
  16. Synopsis: A contiguous segment of a source template, e.g. primary script, html, etc.
  17. */
  18. enum SOURCE_SEGMENT
  19. {
  20. ssegHTML,
  21. ssegPrimaryScript,
  22. ssegTaggedScript,
  23. ssegObject,
  24. ssegInclude,
  25. ssegMetadata,
  26. ssegHTMLComment,
  27. ssegFPBot,
  28. };
  29. /* ****************************************************************************
  30. Class: CSourceInfo
  31. Synopsis: Info on the source of an output
  32. NOTE: The target offsets are strictly increasing, so it is binary
  33. searchable. (This is good because this is the search key
  34. used by the debugger workhorse API, GetSourceContextOfPosition)
  35. Beware, however, that source offsets and line #s are not, in
  36. general, binary searchable because of #include files being thrown
  37. into the mix.
  38. TODO DBCS:
  39. Both the corresponding byte AND character offsets for the source are
  40. stored in this table. Character offsets are used by all of the API
  41. interfaces, but the GetText() API must know what byte offset corresponds
  42. to a character offset. To figure this out, GetText() looks for the
  43. closest character offset in the file and uses that as its base for
  44. figuring out the byte offset.
  45. */
  46. class CSourceInfo
  47. {
  48. public:
  49. CFileMap * m_pfilemap; // filemap to source file
  50. unsigned m_cchTargetOffset; // target offset (target line # implicit)
  51. unsigned m_cchSourceOffset; // character offset of the source line
  52. unsigned m_cchSourceText; // # of characters in the source statement
  53. unsigned m_idLine:31; // line number in source file
  54. unsigned m_fIsHTML:1; // line number is start of HTML block
  55. // UNSAFE if virtual functions ever added to this class!
  56. CSourceInfo() { memset(this, 0, sizeof(*this)); }
  57. };
  58. /* ****************************************************************************
  59. Class: CTargetOffsetOrder
  60. Synopsis: provides ordering function for GetBracketingPair() based on
  61. target offsets in the CSourceInfo array
  62. */
  63. class CTargetOffsetOrder
  64. {
  65. public:
  66. BOOL operator()(const CSourceInfo &si, ULONG ul)
  67. { return si.m_cchTargetOffset < ul; }
  68. BOOL operator()(ULONG ul, const CSourceInfo &si)
  69. { return ul < si.m_cchTargetOffset; }
  70. };
  71. /* ****************************************************************************
  72. Class: CBuffer
  73. Synopsis: A self-sizing memory buffer
  74. */
  75. class CBuffer
  76. {
  77. private:
  78. CByteRange* m_pItems; // ptr to items (i.e. byte ranges)
  79. USHORT m_cSlots; // count of item slots allocated
  80. USHORT m_cItems; // count of items actually stored
  81. BYTE* m_pbData; // ptr to local data storage for items
  82. ULONG m_cbData; // size of local data storage for items
  83. ULONG m_cbDataUsed; // amount of local data storage actually used
  84. public:
  85. CBuffer();
  86. ~CBuffer();
  87. void Init(USHORT cItems, ULONG cbData);
  88. USHORT Count() { return m_cItems; }
  89. USHORT CountSlots() { return m_cSlots; }
  90. void GetItem(UINT i, CByteRange& br);
  91. CByteRange* operator[](UINT i) { return &m_pItems[i]; }
  92. void SetItem(UINT i, const CByteRange& br, BOOL fLocal, UINT idSequence, CFileMap *pfilemap, BOOL fLocalString = FALSE);
  93. void Append(const CByteRange& br, BOOL fLocal, UINT idSequence, CFileMap *pfilemap, BOOL fLocalString = FALSE);
  94. LPSTR PszLocal(UINT i);
  95. // Cache on per-class basis
  96. // ACACHE_INCLASS_DEFINITIONS()
  97. };
  98. /* ****************************************************************************
  99. Class: CScriptStore
  100. Synopsis: Working storage for script segments during compilation.
  101. Terminology
  102. -----------
  103. Engine == a particular script engine (VBScript, JavaScript, etc)
  104. Segment == a contiguous chunk of script text in the source file
  105. */
  106. class CScriptStore
  107. {
  108. public:
  109. CBuffer** m_ppbufSegments; // ptr to array of ptrs to script segment buffers, one per engine
  110. UINT m_cSegmentBuffers; // count of script segment buffers
  111. CBuffer m_bufEngineNames; // buffer of engine names, one per engine
  112. PROGLANG_ID* m_rgProgLangId; // array of prog lang ids, one per engine
  113. CScriptStore(): m_ppbufSegments(NULL), m_cSegmentBuffers(0), m_rgProgLangId(NULL) {}
  114. ~CScriptStore();
  115. HRESULT Init(LPCSTR szDefaultScriptLanguage, CLSID *pCLSIDDefaultEngine);
  116. USHORT CountPreliminaryEngines() { return m_bufEngineNames.Count(); }
  117. HRESULT AppendEngine(CByteRange& brEngine, PROGLANG_ID* pProgLangId, UINT idSequence);
  118. USHORT IdEngineFromBr(CByteRange& brEngine, UINT idSequence);
  119. void AppendScript(CByteRange& brScript, CByteRange& brEngine, BOOLB fPrimary, UINT idSequence, CFileMap* pfilemap);
  120. };
  121. /* ****************************************************************************
  122. Class: CObjectInfo
  123. Synopsis: Information about an object which can be determined at compile time
  124. */
  125. class CObjectInfo
  126. {
  127. public:
  128. CLSID m_clsid; // clsid
  129. CompScope m_scope; // scope: application, session, page
  130. CompModel m_model; // threading model: single, apt, free
  131. };
  132. /* ****************************************************************************
  133. Class: CObjectInfoStore
  134. Synopsis: Working storage for object-infos during compilation.
  135. */
  136. class CObjectInfoStore
  137. {
  138. public:
  139. CObjectInfo* m_pObjectInfos; // array of object infos
  140. CBuffer m_bufObjectNames; // buffer of object names
  141. CObjectInfoStore(): m_pObjectInfos(NULL) {}
  142. ~CObjectInfoStore();
  143. void Init();
  144. void AppendObject(CByteRange& brObjectName, CLSID clsid, CompScope scope, CompModel model, UINT idSequence);
  145. USHORT Count() { return m_bufObjectNames.Count(); }
  146. };
  147. /* ****************************************************************************
  148. Class: CWorkStore
  149. Synopsis: Working storage for template components
  150. */
  151. class CWorkStore
  152. {
  153. public:
  154. CBuffer m_bufHTMLSegments; // buffer of HTML segments
  155. CObjectInfoStore m_ObjectInfoStore; // object-infos store
  156. CScriptStore m_ScriptStore; // script store
  157. UINT m_idCurSequence; // sequence number for current segment
  158. CByteRange m_brCurEngine; // current script engine
  159. BOOLB m_fPageCommandsExecuted; // have we executed page-level @ commands yet?
  160. BOOLB m_fPageCommandsAllowed; // are we allowed to execute page-level @ commands?
  161. // (will be true iff we have not yet compiled any line of script)
  162. LPSTR m_szWriteBlockOpen; // open for Response.WriteBlock() equivalent
  163. LPSTR m_szWriteBlockClose; // close for Response.WriteBlock() equivalent
  164. LPSTR m_szWriteOpen; // open for Response.Write() equivalent
  165. LPSTR m_szWriteClose; // close for Response.Write() equivalent
  166. // Adding fields to maintain state of the line number calculations (Raid Bug 330171)
  167. BYTE* m_pbPrevSource; // pointer to the location of the last Calc line number call in source file
  168. UINT m_cPrevSourceLines; // corresponding line number to the previous call.
  169. HANDLE m_hPrevFile; // Corresponding file Handle. (Identifing a unique file)
  170. CWorkStore();
  171. ~CWorkStore();
  172. void Init();
  173. USHORT CRequiredScriptEngines(BOOL fGlobalAsa);
  174. BOOLB FScriptEngineRequired(USHORT idEnginePrelim, BOOL fGlobalAsa);
  175. };
  176. /* ****************************************************************************
  177. Class: COffsetInfo
  178. Synopsis: map byte offsets to character offsets (different for DBCS)
  179. on line boundaries
  180. Each CFileMap has an array of these COffsetInfo structures at each line boundary.
  181. It stores these at the same offsets in the CSourceInfo array so that a simple
  182. binary search is all that's needed to convert offsets.
  183. */
  184. class COffsetInfo
  185. {
  186. public:
  187. unsigned m_cchOffset; // character offset in file
  188. unsigned m_cbOffset; // byte offset in file
  189. // UNSAFE if virtual functions ever added to this class!
  190. COffsetInfo() { memset(this, 0, sizeof(*this)); }
  191. };
  192. /* ****************************************************************************
  193. Class: CByteOffsetOrder
  194. Synopsis: provides ordering function for GetBracketingPair() based on
  195. byte offsets in the COffsetInfo array
  196. */
  197. class CByteOffsetOrder
  198. {
  199. public:
  200. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  201. { return oi.m_cbOffset < ul; }
  202. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  203. { return ul < oi.m_cbOffset; }
  204. };
  205. /* ****************************************************************************
  206. Class: CCharOffsetOrder
  207. Synopsis: provides ordering function for GetBracketingPair() based on
  208. character offsets in the COffsetInfo array
  209. */
  210. class CCharOffsetOrder
  211. {
  212. public:
  213. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  214. { return oi.m_cchOffset < ul; }
  215. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  216. { return ul < oi.m_cchOffset; }
  217. };
  218. /* ****************************************************************************
  219. Class: CFileMap
  220. Synopsis: A memory-mapping of a file
  221. NOTE: We store an incfile-template dependency by storing an incfile ptr in m_pIncFile.
  222. This is efficient but ***will break if we ever change Denali to move its memory around***
  223. */
  224. class CFileMap
  225. {
  226. public:
  227. TCHAR * m_szPathInfo; // file's virtual path (from www root)
  228. TCHAR * m_szPathTranslated; // file's actual file system path
  229. union { // NOTE: m_fHasSibling is used to disambiguate these two
  230. CFileMap* m_pfilemapParent; // ptr to filemap of parent file
  231. CFileMap* m_pfilemapSibling; // ptr to next filemap in same level of hierarchy
  232. };
  233. CFileMap* m_pfilemapChild; // index of first filemap in next lower level of hierarchy
  234. HANDLE m_hFile; // file handle
  235. HANDLE m_hMap; // file map handle
  236. BYTE* m_pbStartOfFile; // ptr to start of file
  237. CIncFile* m_pIncFile; // ptr to inc-file object
  238. PSECURITY_DESCRIPTOR m_pSecurityDescriptor; // ptr to file's security descriptor
  239. unsigned long m_dwSecDescSize:30; // size of security descriptor
  240. unsigned long m_fHasSibling:1; // Does a sibling exist for this node?
  241. unsigned long m_fHasVirtPath:1; // Is m_szPathInfo the virtual or physical path?
  242. FILETIME m_ftLastWriteTime; // last time the file was written to
  243. DWORD m_cChars; // # of characters in the file
  244. vector<COffsetInfo> m_rgByte2DBCS; // line-by-line map of byte offsets to DBCS
  245. CDirMonitorEntry* m_pDME; // pointer to directory monitor entry for this file
  246. CFileMap();
  247. ~CFileMap();
  248. void MapFile(LPCTSTR szFileSpec, LPCTSTR szApplnPath, CFileMap* pfilemapParent, BOOL fVirtual, CHitObj* pRequest, BOOL fGlobalAsp);
  249. void RemapFile();
  250. void UnmapFile();
  251. CFileMap* GetParent();
  252. void SetParent(CFileMap *);
  253. void AddSibling(CFileMap *);
  254. CFileMap* NextSibling() { return m_fHasSibling? m_pfilemapSibling : NULL; }
  255. BOOL FIsMapped()
  256. { return m_pbStartOfFile != NULL; }
  257. BOOL FHasVirtPath()
  258. { return m_fHasVirtPath; }
  259. BOOL FCyclicInclude(LPCTSTR szPathTranslated);
  260. BOOL GetSecurityDescriptor();
  261. DWORD GetSize() { return GetFileSize(m_hFile, NULL); } // return # of bytes
  262. DWORD CountChars(WORD wCodePage); // return # of chars
  263. // implementation of debugging iterface - CTemplate & CIncFile eventually delegate to this function
  264. HRESULT GetText(WORD wCodePage, ULONG cchSourceOffset, WCHAR *pwchText, SOURCE_TEXT_ATTR *pTextAttr, ULONG *pcChars, ULONG cMaxChars);
  265. // Cache on per-class basis
  266. ACACHE_INCLASS_DEFINITIONS()
  267. };
  268. /* ****************************************************************************
  269. Class: CTokenList
  270. Synopsis: A list of tokens.
  271. */
  272. class CTokenList
  273. {
  274. public:
  275. /* ========================================================================
  276. Enum type: TOKEN
  277. Synopsis: Token type.
  278. NOTE: keep sync'ed with CTokenList::Init()
  279. */
  280. enum TOKEN
  281. {
  282. //======== Opener tokens ==================================
  283. tknOpenPrimaryScript, // open primary script segment
  284. tknOpenTaggedScript, // open tagged script segment
  285. tknOpenObject, // open object segment
  286. tknOpenHTMLComment, // open HTML comment
  287. //======== Non-opener tokens ==============================
  288. tknNewLine, // new line
  289. tknClosePrimaryScript, // close primary script segment
  290. tknCloseTaggedScript, // close primary script segment
  291. tknCloseObject, // close object segment
  292. tknCloseHTMLComment, // close HTML comment
  293. tknEscapedClosePrimaryScript, // escaped close-primary-script symbol
  294. tknCloseTag, // close object or script tag
  295. tknCommandINCLUDE, // server-side include (SSI) INCLUDE command
  296. tknTagRunat, // RUNAT script/object attribute
  297. tknTagLanguage, // LANGUAGE tag: page-level compiler directive or script block attribute
  298. tknTagCodePage, // CODEPAGE tag: page-level compiler directive
  299. tknTagLCID, // LCID tag: page-level compiler directive
  300. tknTagTransacted, // TRANSACTED tag: page-level compiler directive
  301. tknTagSession, // SESSION tag: page-level compiler directive
  302. tknTagID, // ID object attribute
  303. tknTagClassID, // CLASSID object attribute
  304. tknTagProgID, // PROGID object attribute
  305. tknTagScope, // SCOPE object attribute
  306. tknTagVirtual, // VIRTUAL include file attribute
  307. tknTagFile, // FILE include file attribute
  308. tknTagMETADATA, // METADATA tag - used by IStudio
  309. // tknTagSetPriScriptLang, // sets primary script language, as in <% @ LANGUAGE = VBScript %>
  310. tknTagName, // NAME inside METADATA
  311. tknValueTypeLib, // TypeLib inside METADATA (has to be before TYPE in the list)
  312. tknTagType, // TYPE inside METADATA
  313. tknTagUUID, // UUID inside METADATA
  314. tknTagVersion, // VERSION inside METADATA
  315. tknTagStartspan, // STARTSPAN inside METADATA
  316. tknTagEndspan, // ENDSPAN inside METADATA
  317. tknValueCookie, // TYPE=Cookie inside METADATA
  318. tknTagSrc, // SRC= inside METADATA
  319. tknValueServer, // Server value - e.g. RUNAT=Server
  320. tknValueApplication, // SCOPE=Application
  321. tknValueSession, // SCOPE=Session
  322. tknValuePage, // SCOPE=Page
  323. tknVBSCommentSQuote, // VBS comment symbol
  324. tknVBSCommentRem, // VBS comment symbol (alternate)
  325. tknTagFPBot, // Front Page webbot tag
  326. tknEOF, // end-of-file pseudo-token
  327. tkncAll // pseudo-token: count of all tokens
  328. };
  329. void Init();
  330. CByteRange* operator[](UINT i) { return m_bufTokens[i]; }
  331. CByteRange* operator[](TOKEN tkn) { return operator[]((UINT) tkn); }
  332. void AppendToken(TOKEN tkn, char* psz);
  333. TOKEN NextOpenToken(CByteRange& brSearch, TOKEN* rgtknOpeners, UINT ctknOpeners, BYTE** ppbToken, LONG lCodePage);
  334. void MovePastToken(TOKEN tkn, BYTE* pbToken, CByteRange& brSearch);
  335. BYTE* GetToken(TOKEN tkn, CByteRange& brSearch, LONG lCodePage);
  336. public:
  337. CBuffer m_bufTokens; // tokens buffer
  338. };
  339. /* ****************************************************************************
  340. Class: CDocNodeElem
  341. Synopsis: contains a pair of document nodes & application it belongs to
  342. */
  343. class CDocNodeElem : public CDblLink
  344. {
  345. public:
  346. CAppln *m_pAppln;
  347. // IDebugApplicationNode *m_pFileRoot; // root of directory hierarchy
  348. IDebugApplicationNode *m_pDocRoot; // root of template document hierarchy
  349. // ctor
  350. CDocNodeElem(CAppln *pAppln, /*IDebugApplicationNode *pFileRoot,*/ IDebugApplicationNode *pDocRoot);
  351. // dtor
  352. ~CDocNodeElem();
  353. };