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.

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