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.

290 lines
8.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996 - 1997, Microsoft Corporation.
  4. //
  5. // File: variable.hxx
  6. //
  7. // Contents: Used to track replacable variables
  8. //
  9. // Classes: CVariable, CVariableSet
  10. //
  11. // Notes: Neither of these classes are unwindable, since they
  12. // aren't very useful on the stack and they don't contain
  13. // unwindables. This is a performance win for CVariable
  14. // especially since we create so many of them.
  15. //
  16. // History: 96/Jan/3 DwightKr Created
  17. //
  18. //----------------------------------------------------------------------------
  19. #pragma once
  20. class CVariableSetIter;
  21. class CVirtualString;
  22. class CWebServer;
  23. const ULONG VARIABLESET_HASH_TABLE_SIZE = 61;
  24. ULONG ISAPIVariableNameHash( WCHAR const * wcsName );
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Class: CVariable
  28. //
  29. // Purpose: Encapsulates a single variable used as a replaceable parameter
  30. // in a HTX file.
  31. //
  32. // History: 96/Jan/23 DwightKr Created
  33. //
  34. //----------------------------------------------------------------------------
  35. class CVariable
  36. {
  37. public:
  38. CVariable( WCHAR const * wcsName,
  39. PROPVARIANT const * pVariant,
  40. ULONG ulFlags );
  41. CVariable( const CVariable & variable );
  42. ~CVariable();
  43. WCHAR const * GetName() const { return _wcsName; }
  44. PROPVARIANT * GetValue() { return &_variant; }
  45. void SetValue( PROPVARIANT const * pVariant, ULONG ulFlags );
  46. void FastSetValue( PROPVARIANT const * pVariant );
  47. void SetValue( XPtrST<WCHAR> & wcsValue, ULONG cwcValue );
  48. WCHAR * GetStringValueRAW()
  49. {
  50. Win4Assert( VT_LPWSTR == _variant.vt );
  51. if ( 0 != _wcsRAWValue )
  52. return _wcsRAWValue;
  53. else
  54. return _variant.pwszVal;
  55. }
  56. WCHAR * GetStringValueRAW( COutputFormat & outputFormat, ULONG & cwcValue );
  57. WCHAR * GetStringValueFormattedRAW( COutputFormat & outputFormat, ULONG & cwcValue );
  58. void GetStringValueHTML( COutputFormat & outputFormat,
  59. CVirtualString & StrResult )
  60. {
  61. ULONG cch;
  62. HTMLEscapeW( GetStringValueFormattedRAW( outputFormat, cch ),
  63. StrResult,
  64. outputFormat.CodePage() );
  65. }
  66. void GetStringValueURL( COutputFormat & outputFormat,
  67. CVirtualString & StrResult )
  68. {
  69. ULONG cch;
  70. URLEscapeW( GetStringValueRAW( outputFormat, cch ),
  71. StrResult,
  72. outputFormat.CodePage() );
  73. }
  74. BOOL IsDirectlyComparable() const;
  75. ULONG GetFlags() const { return _ulFlags; }
  76. CVariable * GetNext() const { return _pNext; }
  77. void SetNext( CVariable * pNext )
  78. {
  79. _pNext = pNext;
  80. }
  81. CVariable * GetBack() const { return _pBack; }
  82. void SetBack( CVariable * pBack )
  83. {
  84. _pBack = pBack;
  85. }
  86. WCHAR * DupStringValue(COutputFormat & outputFormat);
  87. private:
  88. // NOTE: try to keep private data < 256 bytes for performance
  89. enum { cwcNumberValue = 100 };
  90. enum eNumType { eNotANumber = 0,
  91. eFormattedNumber = 1,
  92. eRawNumber = 2 };
  93. WCHAR * _wcsName;
  94. ULONG _ulFlags; // Flags
  95. PROPVARIANT _variant; // Its value
  96. WCHAR * _wcsRAWValue; // RAW representation of value
  97. ULONG _cwcRAWValue; // Length of RAW string
  98. eNumType _eNumType; // Type of formatting for raw value
  99. WCHAR _wcsNumberValue[cwcNumberValue];
  100. CVariable * _pNext; // Next item in hash chain
  101. CVariable * _pBack; // Previous item in hash chain
  102. };
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Class: CVariableSet
  106. //
  107. // Purpose: A list of CVariables
  108. //
  109. // History: 96/Jan/23 DwightKr Created
  110. //
  111. //----------------------------------------------------------------------------
  112. class CVariableSet : public PVariableSet
  113. {
  114. friend class CVariableSetIter;
  115. public:
  116. CVariableSet()
  117. {
  118. RtlZeroMemory( _variableSet, sizeof _variableSet );
  119. }
  120. CVariableSet( const CVariableSet & variableSet );
  121. ~CVariableSet();
  122. virtual CVariable * SetVariable( WCHAR const * wcsName,
  123. PROPVARIANT const *pVariant,
  124. ULONG ulFlags );
  125. virtual void SetVariable( WCHAR const * wcsName,
  126. XArray<WCHAR> & xValue );
  127. void CopyStringValue( WCHAR const * wcsName,
  128. WCHAR const * wcsValue,
  129. ULONG ulFlags,
  130. ULONG cwcValue = 0 );
  131. void AcquireStringValue( WCHAR const * wcsName,
  132. WCHAR * wcsValue,
  133. ULONG ulFlags );
  134. void AddVariableSet( CVariableSet & variableSet,
  135. COutputFormat & outputFormat );
  136. void AddExtensionControlBlock( CWebServer & webServer );
  137. PROPVARIANT * GetValue( WCHAR const * wcsName ) const;
  138. WCHAR const * GetStringValueRAW( WCHAR const * wcsName,
  139. ULONG ulHash,
  140. COutputFormat & outputFormat,
  141. ULONG & cwcValue );
  142. BOOL GetStringValueHTML( WCHAR const * wcsName,
  143. ULONG ulHash,
  144. COutputFormat & outputFormat,
  145. CVirtualString & StrResult )
  146. {
  147. // Returns TRUE if the value exists, FALSE otherwise
  148. CVariable * pVariable = Find( wcsName, ulHash );
  149. if ( 0 != pVariable )
  150. {
  151. pVariable->GetStringValueHTML( outputFormat, StrResult );
  152. return TRUE;
  153. }
  154. else
  155. {
  156. return FALSE;
  157. }
  158. }
  159. BOOL GetStringValueURL( WCHAR const * wcsName,
  160. ULONG ulHash,
  161. COutputFormat & outputFormat,
  162. CVirtualString & StrResult )
  163. {
  164. // Returns TRUE if the value exists, FALSE otherwise
  165. CVariable * pVariable = Find( wcsName, ulHash );
  166. if ( 0 != pVariable )
  167. {
  168. pVariable->GetStringValueURL( outputFormat, StrResult );
  169. return TRUE;
  170. }
  171. else
  172. {
  173. return FALSE;
  174. }
  175. }
  176. CVariable * Find( WCHAR const * wcsName, ULONG ulHash ) const;
  177. CVariable * Find( WCHAR const * wcsName ) const
  178. {
  179. ULONG ulHash = ISAPIVariableNameHash( wcsName );
  180. return Find( wcsName, ulHash );
  181. }
  182. void Delete( CVariable * pVariable );
  183. #if (DBG == 1)
  184. void Dump( CVirtualString & string, COutputFormat & outputFormat );
  185. #endif // DBG == 1
  186. private:
  187. // List of variables
  188. CVariable * _variableSet[VARIABLESET_HASH_TABLE_SIZE];
  189. };
  190. //+---------------------------------------------------------------------------
  191. //
  192. // Class: CVariableSetIter
  193. //
  194. // Purpose: Iterates over a CVariableSet
  195. //
  196. // History: 96/Jan/23 DwightKr Created
  197. //
  198. //----------------------------------------------------------------------------
  199. class CVariableSetIter
  200. {
  201. public:
  202. CVariableSetIter( const CVariableSet & variableSet ) :
  203. _variableSet(variableSet),
  204. _item(0),
  205. _pVariable(0)
  206. {
  207. Next();
  208. }
  209. BOOL AtEnd() const
  210. {
  211. return (_item >= VARIABLESET_HASH_TABLE_SIZE) &&
  212. ( 0 == _pVariable );
  213. }
  214. void Next()
  215. {
  216. if ( 0 != _pVariable )
  217. {
  218. _pVariable = _pVariable->GetNext();
  219. }
  220. while ( (0 == _pVariable) && (_item < VARIABLESET_HASH_TABLE_SIZE) )
  221. {
  222. _pVariable = _variableSet._variableSet[ _item ];
  223. _item++;
  224. }
  225. }
  226. CVariable * Get() { return _pVariable; }
  227. private:
  228. ULONG _item; // Current item in dynarray
  229. CVariable * _pVariable; // Current item chain
  230. const CVariableSet & _variableSet; // CVariableSet to iterate over
  231. };