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.

233 lines
7.8 KiB

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