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.

410 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. CWorkStore();
  167. ~CWorkStore();
  168. void Init();
  169. USHORT CRequiredScriptEngines(BOOL fGlobalAsa);
  170. BOOLB FScriptEngineRequired(USHORT idEnginePrelim, BOOL fGlobalAsa);
  171. };
  172. /* ****************************************************************************
  173. Class: COffsetInfo
  174. Synopsis: map byte offsets to character offsets (different for DBCS)
  175. on line boundaries
  176. Each CFileMap has an array of these COffsetInfo structures at each line boundary.
  177. It stores these at the same offsets in the CSourceInfo array so that a simple
  178. binary search is all that's needed to convert offsets.
  179. */
  180. class COffsetInfo
  181. {
  182. public:
  183. unsigned m_cchOffset; // character offset in file
  184. unsigned m_cbOffset; // byte offset in file
  185. // UNSAFE if virtual functions ever added to this class!
  186. COffsetInfo() { memset(this, 0, sizeof(*this)); }
  187. };
  188. /* ****************************************************************************
  189. Class: CByteOffsetOrder
  190. Synopsis: provides ordering function for GetBracketingPair() based on
  191. byte offsets in the COffsetInfo array
  192. */
  193. class CByteOffsetOrder
  194. {
  195. public:
  196. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  197. { return oi.m_cbOffset < ul; }
  198. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  199. { return ul < oi.m_cbOffset; }
  200. };
  201. /* ****************************************************************************
  202. Class: CCharOffsetOrder
  203. Synopsis: provides ordering function for GetBracketingPair() based on
  204. character offsets in the COffsetInfo array
  205. */
  206. class CCharOffsetOrder
  207. {
  208. public:
  209. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  210. { return oi.m_cchOffset < ul; }
  211. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  212. { return ul < oi.m_cchOffset; }
  213. };
  214. /* ****************************************************************************
  215. Class: CFileMap
  216. Synopsis: A memory-mapping of a file
  217. NOTE: We store an incfile-template dependency by storing an incfile ptr in m_pIncFile.
  218. This is efficient but ***will break if we ever change Denali to move its memory around***
  219. */
  220. class CFileMap
  221. {
  222. public:
  223. TCHAR * m_szPathInfo; // file's virtual path (from www root)
  224. TCHAR * m_szPathTranslated; // file's actual file system path
  225. union { // NOTE: m_fHasSibling is used to disambiguate these two
  226. CFileMap* m_pfilemapParent; // ptr to filemap of parent file
  227. CFileMap* m_pfilemapSibling; // ptr to next filemap in same level of hierarchy
  228. };
  229. CFileMap* m_pfilemapChild; // index of first filemap in next lower level of hierarchy
  230. HANDLE m_hFile; // file handle
  231. HANDLE m_hMap; // file map handle
  232. BYTE* m_pbStartOfFile; // ptr to start of file
  233. CIncFile* m_pIncFile; // ptr to inc-file object
  234. PSECURITY_DESCRIPTOR m_pSecurityDescriptor; // ptr to file's security descriptor
  235. unsigned long m_dwSecDescSize:30; // size of security descriptor
  236. unsigned long m_fHasSibling:1; // Does a sibling exist for this node?
  237. unsigned long m_fHasVirtPath:1; // Is m_szPathInfo the virtual or physical path?
  238. FILETIME m_ftLastWriteTime; // last time the file was written to
  239. DWORD m_cChars; // # of characters in the file
  240. vector<COffsetInfo> m_rgByte2DBCS; // line-by-line map of byte offsets to DBCS
  241. CDirMonitorEntry* m_pDME; // pointer to directory monitor entry for this file
  242. CFileMap();
  243. ~CFileMap();
  244. void MapFile(LPCTSTR szFileSpec, LPCTSTR szApplnPath, CFileMap* pfilemapParent, BOOL fVirtual, CHitObj* pRequest, BOOL fGlobalAsp);
  245. void RemapFile();
  246. void UnmapFile();
  247. CFileMap* GetParent();
  248. void SetParent(CFileMap *);
  249. void AddSibling(CFileMap *);
  250. CFileMap* NextSibling() { return m_fHasSibling? m_pfilemapSibling : NULL; }
  251. BOOL FIsMapped()
  252. { return m_pbStartOfFile != NULL; }
  253. BOOL FHasVirtPath()
  254. { return m_fHasVirtPath; }
  255. BOOL FCyclicInclude(LPCTSTR szPathTranslated);
  256. BOOL GetSecurityDescriptor();
  257. DWORD GetSize() { return GetFileSize(m_hFile, NULL); } // return # of bytes
  258. DWORD CountChars(WORD wCodePage); // return # of chars
  259. // implementation of debugging iterface - CTemplate & CIncFile eventually delegate to this function
  260. HRESULT GetText(WORD wCodePage, ULONG cchSourceOffset, WCHAR *pwchText, SOURCE_TEXT_ATTR *pTextAttr, ULONG *pcChars, ULONG cMaxChars);
  261. // Cache on per-class basis
  262. ACACHE_INCLASS_DEFINITIONS()
  263. };
  264. /* ****************************************************************************
  265. Class: CTokenList
  266. Synopsis: A list of tokens.
  267. */
  268. class CTokenList
  269. {
  270. public:
  271. /* ========================================================================
  272. Enum type: TOKEN
  273. Synopsis: Token type.
  274. NOTE: keep sync'ed with CTokenList::Init()
  275. */
  276. enum TOKEN
  277. {
  278. //======== Opener tokens ==================================
  279. tknOpenPrimaryScript, // open primary script segment
  280. tknOpenTaggedScript, // open tagged script segment
  281. tknOpenObject, // open object segment
  282. tknOpenHTMLComment, // open HTML comment
  283. //======== Non-opener tokens ==============================
  284. tknNewLine, // new line
  285. tknClosePrimaryScript, // close primary script segment
  286. tknCloseTaggedScript, // close primary script segment
  287. tknCloseObject, // close object segment
  288. tknCloseHTMLComment, // close HTML comment
  289. tknEscapedClosePrimaryScript, // escaped close-primary-script symbol
  290. tknCloseTag, // close object or script tag
  291. tknCommandINCLUDE, // server-side include (SSI) INCLUDE command
  292. tknTagRunat, // RUNAT script/object attribute
  293. tknTagLanguage, // LANGUAGE tag: page-level compiler directive or script block attribute
  294. tknTagCodePage, // CODEPAGE tag: page-level compiler directive
  295. tknTagLCID, // LCID tag: page-level compiler directive
  296. tknTagTransacted, // TRANSACTED tag: page-level compiler directive
  297. tknTagSession, // SESSION tag: page-level compiler directive
  298. tknTagID, // ID object attribute
  299. tknTagClassID, // CLASSID object attribute
  300. tknTagProgID, // PROGID object attribute
  301. tknTagScope, // SCOPE object attribute
  302. tknTagVirtual, // VIRTUAL include file attribute
  303. tknTagFile, // FILE include file attribute
  304. tknTagMETADATA, // METADATA tag - used by IStudio
  305. // tknTagSetPriScriptLang, // sets primary script language, as in <% @ LANGUAGE = VBScript %>
  306. tknTagName, // NAME inside METADATA
  307. tknValueTypeLib, // TypeLib inside METADATA (has to be before TYPE in the list)
  308. tknTagType, // TYPE inside METADATA
  309. tknTagUUID, // UUID inside METADATA
  310. tknTagVersion, // VERSION inside METADATA
  311. tknTagStartspan, // STARTSPAN inside METADATA
  312. tknTagEndspan, // ENDSPAN inside METADATA
  313. tknValueCookie, // TYPE=Cookie inside METADATA
  314. tknTagSrc, // SRC= inside METADATA
  315. tknValueServer, // Server value - e.g. RUNAT=Server
  316. tknValueApplication, // SCOPE=Application
  317. tknValueSession, // SCOPE=Session
  318. tknValuePage, // SCOPE=Page
  319. tknVBSCommentSQuote, // VBS comment symbol
  320. tknVBSCommentRem, // VBS comment symbol (alternate)
  321. tknTagFPBot, // Front Page webbot tag
  322. tknEOF, // end-of-file pseudo-token
  323. tkncAll // pseudo-token: count of all tokens
  324. };
  325. void Init();
  326. CByteRange* operator[](UINT i) { return m_bufTokens[i]; }
  327. CByteRange* operator[](TOKEN tkn) { return operator[]((UINT) tkn); }
  328. void AppendToken(TOKEN tkn, char* psz);
  329. TOKEN NextOpenToken(CByteRange& brSearch, TOKEN* rgtknOpeners, UINT ctknOpeners, BYTE** ppbToken, LONG lCodePage);
  330. void MovePastToken(TOKEN tkn, BYTE* pbToken, CByteRange& brSearch);
  331. BYTE* GetToken(TOKEN tkn, CByteRange& brSearch, LONG lCodePage);
  332. public:
  333. CBuffer m_bufTokens; // tokens buffer
  334. };
  335. /* ****************************************************************************
  336. Class: CDocNodeElem
  337. Synopsis: contains a pair of document nodes & application it belongs to
  338. */
  339. class CDocNodeElem : public CDblLink
  340. {
  341. public:
  342. CAppln *m_pAppln;
  343. // IDebugApplicationNode *m_pFileRoot; // root of directory hierarchy
  344. IDebugApplicationNode *m_pDocRoot; // root of template document hierarchy
  345. // ctor
  346. CDocNodeElem(CAppln *pAppln, /*IDebugApplicationNode *pFileRoot,*/ IDebugApplicationNode *pDocRoot);
  347. // dtor
  348. ~CDocNodeElem();
  349. };