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.

471 lines
18 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. // Add fields to optimize on the calls to strlen. in CWriteTemplate
  171. UINT m_cchWriteBlockOpen; // size for open for Response.WriteBlock() equivalent
  172. UINT m_cchWriteBlockClose; // size for close for Response.WriteBlock() equivalent
  173. UINT m_cchWriteOpen; // size for open for Response.Write() equivalent
  174. UINT m_cchWriteClose; // size for close for Response.Write() equivalent
  175. CWorkStore();
  176. ~CWorkStore();
  177. void Init();
  178. USHORT CRequiredScriptEngines(BOOL fGlobalAsa);
  179. BOOLB FScriptEngineRequired(USHORT idEnginePrelim, BOOL fGlobalAsa);
  180. };
  181. /* ****************************************************************************
  182. Class: CWriteTemplate
  183. Synopsis: Class to calculate amount of memory required by the template in advance.
  184. Allocate the required amount and copy the template components into the contigous memory.
  185. */
  186. class CWriteTemplate
  187. {
  188. private:
  189. CWorkStore* m_pworkStore; // Pointer to the workstore. (could use m_pTempale->workStore) here.
  190. UINT m_cbMemRequired; // Counts the estimate (Accurate) of memory required by the template.
  191. CTemplate* m_pTemplate; // Pointer to the enclosing template class..We require this to call methods of the template.
  192. BOOLB m_fWriteScript; // FALSE - Estimate, TRUE - Write
  193. CPINFO m_codePageInfo; // Code page Information...
  194. BOOL m_fCalcLineNumber; // Stores metabase flag for calculation line number. TRUE = Calculate - FALSE = skip
  195. BYTE* m_pbHeader; // Pointer to the start of the template memory.
  196. public :
  197. CWriteTemplate ();
  198. ~CWriteTemplate ();
  199. void Init (CWorkStore* pworkStore, CTemplate* pTemplate, BOOL fCalcLineNumber);
  200. void WriteScriptBlocks (USHORT idEnginePrelim, USHORT idEngine, UINT *pcbDataOffset, UINT *pcbOffsetToOffset, BOOLB m_fGlobalAsa);
  201. void WritePrimaryScript (USHORT idEngine, UINT *pcbDataOffset, UINT cbScriptBlockOffset);
  202. void WriteTaggedScript (USHORT idEngine, CFileMap* pfilemap, CByteRange brScript, UINT* pcbDataOffset, UINT cbScriptBlockOffset, BOOL fAllowExprWrite);
  203. void ScriptMemoryMinusEscapeChars (CByteRange brScript, UINT *pcbDataOffset, UINT cbPtrOffset);
  204. void MemCopyAlign (UINT *pcbOffset, void *pbSource, ULONG cbSource, UINT cbByteAlign = 0);
  205. void MemCopyWithWideChar (UINT *pcbOffset, void *pbSource, ULONG cbSource, UINT cbByteAlign );
  206. void WriteBSTRToMem (CByteRange & brWrite, UINT *pcbOffset );
  207. void WriteTemplate ();
  208. void WriteTemplateComponents ();
  209. void RemoveHTMLCommentSuffix(UINT cbStartOffset, UINT *pcbCurrentOffset);
  210. };
  211. /* ****************************************************************************
  212. Class: COffsetInfo
  213. Synopsis: map byte offsets to character offsets (different for DBCS)
  214. on line boundaries
  215. Each CFileMap has an array of these COffsetInfo structures at each line boundary.
  216. It stores these at the same offsets in the CSourceInfo array so that a simple
  217. binary search is all that's needed to convert offsets.
  218. */
  219. class COffsetInfo
  220. {
  221. public:
  222. unsigned m_cchOffset; // character offset in file
  223. unsigned m_cbOffset; // byte offset in file
  224. // UNSAFE if virtual functions ever added to this class!
  225. COffsetInfo() { memset(this, 0, sizeof(*this)); }
  226. };
  227. /* ****************************************************************************
  228. Class: CByteOffsetOrder
  229. Synopsis: provides ordering function for GetBracketingPair() based on
  230. byte offsets in the COffsetInfo array
  231. */
  232. class CByteOffsetOrder
  233. {
  234. public:
  235. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  236. { return oi.m_cbOffset < ul; }
  237. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  238. { return ul < oi.m_cbOffset; }
  239. };
  240. /* ****************************************************************************
  241. Class: CCharOffsetOrder
  242. Synopsis: provides ordering function for GetBracketingPair() based on
  243. character offsets in the COffsetInfo array
  244. */
  245. class CCharOffsetOrder
  246. {
  247. public:
  248. BOOL operator()(const COffsetInfo &oi, ULONG ul)
  249. { return oi.m_cchOffset < ul; }
  250. BOOL operator()(ULONG ul, const COffsetInfo &oi)
  251. { return ul < oi.m_cchOffset; }
  252. };
  253. /* ****************************************************************************
  254. Class: CFileMap
  255. Synopsis: A memory-mapping of a file
  256. NOTE: We store an incfile-template dependency by storing an incfile ptr in m_pIncFile.
  257. This is efficient but ***will break if we ever change Denali to move its memory around***
  258. */
  259. class CFileMap
  260. {
  261. public:
  262. TCHAR * m_szPathInfo; // file's virtual path (from www root)
  263. TCHAR * m_szPathTranslated; // file's actual file system path
  264. union { // NOTE: m_fHasSibling is used to disambiguate these two
  265. CFileMap* m_pfilemapParent; // ptr to filemap of parent file
  266. CFileMap* m_pfilemapSibling; // ptr to next filemap in same level of hierarchy
  267. };
  268. CFileMap* m_pfilemapChild; // index of first filemap in next lower level of hierarchy
  269. HANDLE m_hFile; // file handle
  270. HANDLE m_hMap; // file map handle
  271. BYTE* m_pbStartOfFile; // ptr to start of file
  272. CIncFile* m_pIncFile; // ptr to inc-file object
  273. PSECURITY_DESCRIPTOR m_pSecurityDescriptor; // ptr to file's security descriptor
  274. unsigned long m_dwSecDescSize:30; // size of security descriptor
  275. unsigned long m_fHasSibling:1; // Does a sibling exist for this node?
  276. unsigned long m_fHasVirtPath:1; // Is m_szPathInfo the virtual or physical path?
  277. unsigned long m_fIsUNCPath:1; // Is m_szPathTranslated a UNC path?
  278. unsigned long m_fIsEncryptedFile:1; // Is this file encrypted?
  279. FILETIME m_ftLastWriteTime; // last time the file was written to
  280. DWORD m_cChars; // # of characters in the file
  281. vector<COffsetInfo> m_rgByte2DBCS; // line-by-line map of byte offsets to DBCS
  282. CDirMonitorEntry* m_pDME; // pointer to directory monitor entry for this file
  283. DWORD m_dwFileSize; // Size of file (cached)
  284. CFileMap();
  285. ~CFileMap();
  286. void MapFile(LPCTSTR szFileSpec, LPCTSTR szApplnPath, CFileMap* pfilemapParent, BOOL fVirtual, CHitObj* pRequest, BOOL fGlobalAsp);
  287. void RemapFile();
  288. void UnmapFile();
  289. CFileMap* GetParent();
  290. void SetParent(CFileMap *);
  291. void AddSibling(CFileMap *);
  292. CFileMap* NextSibling() { return m_fHasSibling? m_pfilemapSibling : NULL; }
  293. BOOL FIsMapped()
  294. { return m_pbStartOfFile != NULL; }
  295. BOOL FHasVirtPath()
  296. { return m_fHasVirtPath; }
  297. BOOL FHasUNCPath()
  298. { return m_fIsUNCPath; }
  299. BOOL FIsEncryptedFile()
  300. { return m_fIsEncryptedFile; }
  301. BOOL FCyclicInclude(LPCTSTR szPathTranslated);
  302. BOOL GetSecurityDescriptor();
  303. DWORD GetSize() { return m_dwFileSize;} // return # of bytes
  304. DWORD CountChars(WORD wCodePage); // return # of chars
  305. // implementation of debugging iterface - CTemplate & CIncFile eventually delegate to this function
  306. HRESULT GetText(WORD wCodePage, ULONG cchSourceOffset, WCHAR *pwchText, SOURCE_TEXT_ATTR *pTextAttr, ULONG *pcChars, ULONG cMaxChars);
  307. // Cache on per-class basis
  308. ACACHE_INCLASS_DEFINITIONS()
  309. };
  310. /* ****************************************************************************
  311. Class: CTokenList
  312. Synopsis: A list of tokens.
  313. */
  314. class CTokenList
  315. {
  316. public:
  317. /* ========================================================================
  318. Enum type: TOKEN
  319. Synopsis: Token type.
  320. NOTE: keep sync'ed with CTokenList::Init()
  321. */
  322. enum TOKEN
  323. {
  324. //======== Opener tokens ==================================
  325. tknOpenPrimaryScript, // open primary script segment
  326. tknOpenTaggedScript, // open tagged script segment
  327. tknOpenObject, // open object segment
  328. tknOpenHTMLComment, // open HTML comment
  329. //======== Non-opener tokens ==============================
  330. tknNewLine, // new line
  331. tknClosePrimaryScript, // close primary script segment
  332. tknCloseTaggedScript, // close primary script segment
  333. tknCloseObject, // close object segment
  334. tknCloseHTMLComment, // close HTML comment
  335. tknEscapedClosePrimaryScript, // escaped close-primary-script symbol
  336. tknCloseTag, // close object or script tag
  337. tknCommandINCLUDE, // server-side include (SSI) INCLUDE command
  338. tknTagRunat, // RUNAT script/object attribute
  339. tknTagLanguage, // LANGUAGE tag: page-level compiler directive or script block attribute
  340. tknTagCodePage, // CODEPAGE tag: page-level compiler directive
  341. tknTagLCID, // LCID tag: page-level compiler directive
  342. tknTagTransacted, // TRANSACTED tag: page-level compiler directive
  343. tknTagSession, // SESSION tag: page-level compiler directive
  344. tknTagID, // ID object attribute
  345. tknTagClassID, // CLASSID object attribute
  346. tknTagProgID, // PROGID object attribute
  347. tknTagScope, // SCOPE object attribute
  348. tknTagVirtual, // VIRTUAL include file attribute
  349. tknTagFile, // FILE include file attribute
  350. tknTagMETADATA, // METADATA tag - used by IStudio
  351. // tknTagSetPriScriptLang, // sets primary script language, as in <% @ LANGUAGE = VBScript %>
  352. tknTagName, // NAME inside METADATA
  353. tknValueTypeLib, // TypeLib inside METADATA (has to be before TYPE in the list)
  354. tknTagType, // TYPE inside METADATA
  355. tknTagUUID, // UUID inside METADATA
  356. tknTagVersion, // VERSION inside METADATA
  357. tknTagStartspan, // STARTSPAN inside METADATA
  358. tknTagEndspan, // ENDSPAN inside METADATA
  359. tknValueCookie, // TYPE=Cookie inside METADATA
  360. tknTagSrc, // SRC= inside METADATA
  361. tknValueServer, // Server value - e.g. RUNAT=Server
  362. tknValueApplication, // SCOPE=Application
  363. tknValueSession, // SCOPE=Session
  364. tknValuePage, // SCOPE=Page
  365. tknVBSCommentSQuote, // VBS comment symbol
  366. tknVBSCommentRem, // VBS comment symbol (alternate)
  367. tknTagFPBot, // Front Page webbot tag
  368. tknEOF, // end-of-file pseudo-token
  369. tkncAll // pseudo-token: count of all tokens
  370. };
  371. void Init();
  372. CByteRange* operator[](UINT i) { return m_bufTokens[i]; }
  373. CByteRange* operator[](TOKEN tkn) { return operator[]((UINT) tkn); }
  374. void AppendToken(TOKEN tkn, char* psz);
  375. TOKEN NextOpenToken(CByteRange& brSearch, TOKEN* rgtknOpeners, UINT ctknOpeners, BYTE** ppbToken, LONG lCodePage);
  376. void MovePastToken(TOKEN tkn, BYTE* pbToken, CByteRange& brSearch);
  377. BYTE* GetToken(TOKEN tkn, CByteRange& brSearch, LONG lCodePage);
  378. public:
  379. CBuffer m_bufTokens; // tokens buffer
  380. };
  381. /* ****************************************************************************
  382. Class: CDocNodeElem
  383. Synopsis: contains a pair of document nodes & application it belongs to
  384. */
  385. class CDocNodeElem : public CDblLink
  386. {
  387. public:
  388. CAppln *m_pAppln;
  389. // IDebugApplicationNode *m_pFileRoot; // root of directory hierarchy
  390. IDebugApplicationNode *m_pDocRoot; // root of template document hierarchy
  391. // ctor
  392. CDocNodeElem(CAppln *pAppln, /*IDebugApplicationNode *pFileRoot,*/ IDebugApplicationNode *pDocRoot);
  393. // dtor
  394. ~CDocNodeElem();
  395. };