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.

237 lines
7.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation.
  4. //
  5. // File: htx.hxx
  6. //
  7. // Contents: Parser for an HTX file
  8. //
  9. // History: 96/Jan/3 DwightKr Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #pragma once
  13. //
  14. // This is the total number of include files allowed
  15. //
  16. const ULONG MAX_HTX_INCLUDE_FILES = 32;
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Class: CHTXScanner
  20. //
  21. // Purpose: Breaks up a string into a number of HTX tokens
  22. //
  23. // History: 96/Jan/23 DwightKr Created
  24. //
  25. //----------------------------------------------------------------------------
  26. class CHTXScanner
  27. {
  28. public:
  29. CHTXScanner( CVariableSet & variableSet,
  30. WCHAR const * wcsPrefix,
  31. WCHAR const * wcsSuffix );
  32. void Init( WCHAR * wcsString );
  33. BOOL FindNextToken();
  34. BOOL IsToken(WCHAR * wcs);
  35. int TokenType() const { return _type; }
  36. WCHAR * GetToken();
  37. private:
  38. WCHAR * _wcsString; // String to parse
  39. WCHAR const * _wcsPrefix; // Token prefix delimiter
  40. WCHAR const * _wcsSuffix; // Token suffix delimiter
  41. WCHAR * _wcsPrefixToken; // Start of current token
  42. WCHAR * _wcsSuffixToken; // End of current token
  43. CVariableSet & _variableSet; // List of replaceabe parameters
  44. // used to identify replaceable tokens
  45. unsigned _cchPrefix; // Length of the prefix delimiter
  46. unsigned _cchSuffix; // Length of the suffix delimiter
  47. WCHAR * _wcsNextToken; // Ptr to next token
  48. unsigned _type; // Type of current token
  49. unsigned _nextType; // Type of next token if not eNone
  50. };
  51. #define CANONIC_HTX_FILE L"//CANONIC.HTX"
  52. class CParameterReplacer;
  53. //+---------------------------------------------------------------------------
  54. //
  55. // Class: CHTXFile
  56. //
  57. // Purpose: Scans and parses an HTX file.
  58. //
  59. // History: 96/Jan/23 DwightKr Created
  60. //
  61. //----------------------------------------------------------------------------
  62. class CHTXFile
  63. {
  64. public:
  65. CHTXFile( XPtrST<WCHAR> & wcsTemplate,
  66. UINT codePage,
  67. CSecurityIdentity const & securityIdentity,
  68. ULONG ulServerInstance );
  69. ~CHTXFile();
  70. void ParseFile( WCHAR const * wcsFileName,
  71. CVariableSet & variableSet,
  72. CWebServer & webServer );
  73. void GetHeader( CVirtualString & string,
  74. CVariableSet & variableSet,
  75. COutputFormat & outputFormat );
  76. void GetFooter( CVirtualString & string,
  77. CVariableSet & variableSet,
  78. COutputFormat & outputFormat );
  79. BOOL DoesDetailSectionExist() { return 0 != _pVarRowDetails; }
  80. void GetDetailSection( CVirtualString & string,
  81. CVariableSet & variableSet,
  82. COutputFormat & outputFormat )
  83. {
  84. Win4Assert( 0 != _pVarRowDetails );
  85. _pVarRowDetails->ReplaceParams( string, variableSet, outputFormat );
  86. }
  87. WCHAR const * GetVirtualName() const { return _wcsVirtualName; }
  88. WCHAR const * GetPhysicalName() const { return _wcsPhysicalName; }
  89. BOOL IsCachedDataValid();
  90. inline BOOL CheckSecurity( CSecurityIdentity const & securityIdentity ) const;
  91. void SetSecurityToken( CSecurityIdentity const & securityIdentity )
  92. {
  93. _securityIdentity.SetSecurityToken( securityIdentity );
  94. }
  95. BOOL IsSequential() const { return _fSequential; }
  96. void LokAddRef() { InterlockedIncrement(&_refCount); }
  97. void Release()
  98. {
  99. InterlockedDecrement(&_refCount);
  100. Win4Assert( _refCount >= 0 );
  101. }
  102. LONG LokGetRefCount() { return _refCount; }
  103. ULONG GetServerInstance() { return _ulServerInstance; }
  104. void GetFileNameAndLineNumber( int offset,
  105. WCHAR *& wcsFileName,
  106. LONG & lineNumber );
  107. UINT GetCodePage() const { return _codePage; }
  108. private:
  109. WCHAR * ReadFile( WCHAR const * wcsFileName,
  110. FILETIME & ftLastWrite );
  111. BOOL CheckForSequentialAccess();
  112. void ExpandFile( WCHAR const * wcsFileName,
  113. CWebServer & webServer,
  114. CVirtualString & vString,
  115. FILETIME & ftLastWrite );
  116. LONG CountLines( WCHAR const * wcsStart, WCHAR const * wcsEnd ) const;
  117. FILETIME _ftHTXLastWriteTime; // Last write time of HTX file
  118. FILETIME _aftIncludeLastWriteTime[MAX_HTX_INCLUDE_FILES];
  119. WCHAR * _wcsVirtualName; // Virtual name of HTX file
  120. WCHAR _wcsPhysicalName[_MAX_PATH]; // Physical name
  121. WCHAR * _awcsIncludeFileName[MAX_HTX_INCLUDE_FILES];
  122. ULONG _aulIncludeFileOffset[MAX_HTX_INCLUDE_FILES];
  123. WCHAR * _wcsFileBuffer; // Contents of combined HTX files
  124. CParameterReplacer * _pVarHeader; // Buffer containing HTX header
  125. CParameterReplacer * _pVarRowDetails; // Buffer containing detail section
  126. CParameterReplacer * _pVarFooter; // Buffer containing footer
  127. BOOL _fSequential; // File can be expanded using seq cursor
  128. ULONG _cIncludeFiles; // # of include files
  129. LONG _refCount; // Refcount for this file
  130. UINT _codePage; // Code page used to read this file
  131. ULONG _ulServerInstance; // VServer Instance ID
  132. CSecurityIdentity _securityIdentity; // Security ID used to open file
  133. };
  134. //+---------------------------------------------------------------------------
  135. //
  136. // Class: CHTXFileList
  137. //
  138. // Purpose: List of parsed and cached HTX files
  139. //
  140. // History: 96/Mar/27 DwightKr Created
  141. //
  142. //----------------------------------------------------------------------------
  143. class CHTXFileList
  144. {
  145. public:
  146. CHTXFileList() :
  147. _ulSignature( LONGSIG( 'h', 't', 'x', 'l' ) ),
  148. _pCanonicHTX( 0 )
  149. {
  150. END_CONSTRUCTION(CHTXFileList);
  151. }
  152. ~CHTXFileList();
  153. CHTXFile & FindCanonicHTX( CVariableSet & variableSet,
  154. UINT codePage,
  155. CSecurityIdentity const & securityIdentity,
  156. ULONG ulServerInstance );
  157. CHTXFile & Find( WCHAR const * wcsVirtualName,
  158. CVariableSet & variableSet,
  159. COutputFormat & outputFormat,
  160. CSecurityIdentity const & securityIdentity,
  161. ULONG ulServerInstance );
  162. void Release( CHTXFile & htxFile );
  163. void DeleteZombies();
  164. private:
  165. ULONG _ulSignature; // Signature of start of privates
  166. CMutexSem _mutex; // To serialize access to list
  167. CDynArrayInPlace<CHTXFile *> _aHTXFile; // parsed HTX files
  168. CHTXFile * _pCanonicHTX; // HTX file for canonic output.
  169. };
  170. //+---------------------------------------------------------------------------
  171. //
  172. // Method: CHTXFile::CheckSecurity
  173. //
  174. // Purpose: Compare user id with one used to load IDQ file
  175. //
  176. // Arguments: [securityIdentity] - Check against this
  177. //
  178. // Returns: TRUE if check passes
  179. //
  180. // History: 26-Oct-1996 KyleP Created
  181. //
  182. //----------------------------------------------------------------------------
  183. inline BOOL CHTXFile::CheckSecurity( CSecurityIdentity const & securityIdentity ) const
  184. {
  185. return _securityIdentity.IsEqual( securityIdentity );
  186. }