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.

276 lines
8.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2002.
  5. //
  6. // File: regprop.hxx
  7. //
  8. // Contents: Class for parsing cached properties as listed in the registry.
  9. //
  10. // Classes: CParseRegistryProperty
  11. //
  12. // History: 11-Nov-97 KyleP Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <ciguid.hxx>
  17. #include <ctype.h>
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Class: CParseRegistryProperty
  21. //
  22. // Purpose: Parses a registry property entry
  23. //
  24. // History: 11-Nov-97 KyleP Created.
  25. //
  26. //----------------------------------------------------------------------------
  27. class CParseRegistryProperty
  28. {
  29. public:
  30. inline CParseRegistryProperty( WCHAR *pValueName, ULONG uValueType,
  31. VOID *pValueData, ULONG uValueLength );
  32. BOOL IsOk() { return _fOk; }
  33. CFullPropSpec & GetFPS() { return _fps; }
  34. ULONG Type() { return _vt; }
  35. ULONG Size() { return _cb; }
  36. BOOL IsModifiable() { return _fModifiable; }
  37. DWORD StorageLevel() { return _dwStoreLevel; }
  38. private:
  39. BOOL _fOk; // TRUE if parse succeeded
  40. CFullPropSpec _fps; // Property stored here
  41. ULONG _vt; // Datatype
  42. ULONG _cb; // Size
  43. BOOL _fModifiable; // Is this modifiable once entered into metabase?
  44. DWORD _dwStoreLevel;// Storage level
  45. };
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Class: CBuildRegistryProperty
  49. //
  50. // Purpose: Builds a registry property entry
  51. //
  52. // History: 11-Nov-97 KyleP Created.
  53. //
  54. //----------------------------------------------------------------------------
  55. class CBuildRegistryProperty
  56. {
  57. public:
  58. inline CBuildRegistryProperty( CFullPropSpec const & fps, ULONG vt,
  59. ULONG cb, DWORD dwStoreLevel = SECONDARY_STORE,
  60. BOOL fModifiable = TRUE);
  61. WCHAR const * GetValue() { return _xwcsValue.Get(); }
  62. WCHAR const * GetData() { return _xwcsData.Get(); }
  63. private:
  64. XGrowable<WCHAR> _xwcsValue;
  65. XGrowable<WCHAR> _xwcsData;
  66. };
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Member: CParseRegistryProperty::CParseRegistryProperty, public
  70. //
  71. // Synopsis: Parses a registry entry for a property value
  72. //
  73. // Arguments: [pValueName] -- Name of value (should be FULLPROPSPEC)
  74. // [pValueType] -- Value type. Should be REG_SZ
  75. // [pValueData] -- Data (should be "<type>,<size>"
  76. // [uValueLength] -- Size of [pValueData]
  77. //
  78. // History: 10-Nov-97 KyleP Created
  79. //
  80. //----------------------------------------------------------------------------
  81. inline CParseRegistryProperty::CParseRegistryProperty( WCHAR *pValueName,
  82. ULONG uValueType,
  83. VOID *pValueData,
  84. ULONG uValueLength )
  85. : _fOk( FALSE ),
  86. _dwStoreLevel( SECONDARY_STORE ),
  87. _fModifiable( TRUE )
  88. {
  89. //
  90. // Format is GUID [PROPID | "PropName"] = datatype,length[,storagelevel[,fModifiable]]
  91. // storagelevel, if absent, defaults to Secondary Store.
  92. // fModifiable, if absent, defaults to TRUE.
  93. do
  94. {
  95. //
  96. // Has to be at least 38 characters long (36 for guid plus space + name/number)
  97. //
  98. unsigned cc = wcslen(pValueName);
  99. if ( cc < 38 || pValueName[36] != L' ' )
  100. break;
  101. if ( REG_SZ != uValueType )
  102. break;
  103. //
  104. // Parse GUID
  105. //
  106. GUID guid;
  107. pValueName[36] = 0;
  108. if ( !ParseGuid( pValueName, guid ) )
  109. break;
  110. _fps.SetPropSet( guid );
  111. pValueName[36] = L' ';
  112. //
  113. // Parse number/name
  114. //
  115. PROPID pid = 0;
  116. for ( WCHAR * p = pValueName + 37; *p; p++ )
  117. {
  118. if ( !isdigit(*p) )
  119. {
  120. pid = 0;
  121. break;
  122. }
  123. pid = pid * 10 + *p - L'0';
  124. }
  125. if ( 0 == pid )
  126. {
  127. if ( !_fps.SetProperty( pValueName + 37 ) )
  128. THROW( CException( E_OUTOFMEMORY ) );
  129. }
  130. else
  131. _fps.SetProperty( pid );
  132. //
  133. // Parse data type
  134. //
  135. _vt = 0;
  136. for ( p = (WCHAR *)pValueData; *p && isdigit(*p); p++ )
  137. _vt = _vt * 10 + *p - L'0';
  138. if ( L',' != *p )
  139. break;
  140. _cb = 0;
  141. for ( p++; *p && isdigit(*p); p++ )
  142. _cb = _cb * 10 + *p - L'0';
  143. //
  144. // Parse storage level
  145. //
  146. if ( L',' == *p )
  147. {
  148. _dwStoreLevel = 0;
  149. for ( p++; *p && isdigit(*p); p++ )
  150. _dwStoreLevel = _dwStoreLevel * 10 + *p - L'0';
  151. // if we don't see a primary or a secondary store signature,
  152. // consider the registry string corrupt.
  153. if (PRIMARY_STORE != _dwStoreLevel &&
  154. SECONDARY_STORE != _dwStoreLevel)
  155. break;
  156. }
  157. //
  158. // Parse modifiability
  159. //
  160. if ( L',' == *p )
  161. {
  162. int iVal = 0;
  163. for ( p++; *p && isdigit(*p); p++ )
  164. iVal = iVal * 10 + *p - L'0';
  165. // if we don't see a TRUE (1) or FALSE (0) signature,
  166. // consider the registry string corrupt.
  167. if (0 != iVal && 1 != iVal)
  168. break;
  169. _fModifiable = BOOL(iVal);
  170. }
  171. _fOk = TRUE;
  172. } while(FALSE);
  173. }
  174. //+---------------------------------------------------------------------------
  175. //
  176. // Member: CBuildRegistryProperty::CBuildRegistryProperty, public
  177. //
  178. // Synopsis: Builds property registry entry from components
  179. //
  180. // Arguments: [fps] -- Property
  181. // [vt] -- Data type
  182. // [cb] -- Size of data in cache
  183. // [dwStoreLevel] -- Property storage level
  184. // [fModifiable] -- Can property metadata be modified once set?
  185. //
  186. // History: 10-Nov-97 KyleP Created
  187. //
  188. //----------------------------------------------------------------------------
  189. inline CBuildRegistryProperty::CBuildRegistryProperty( CFullPropSpec const & fps, ULONG vt,
  190. ULONG cb, DWORD dwStoreLevel,
  191. BOOL fModifiable )
  192. {
  193. GUID const & guid = fps.GetPropSet();
  194. unsigned cc = 36 + 10 + 2; // GUID + space + MAX_INT + null
  195. if ( fps.IsPropertyName() )
  196. cc += wcslen( fps.GetPropertyName() );
  197. _xwcsValue.SetSize( cc );
  198. swprintf( _xwcsValue.Get(),
  199. L"%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ",
  200. guid.Data1,
  201. guid.Data2,
  202. guid.Data3,
  203. guid.Data4[0], guid.Data4[1],
  204. guid.Data4[2], guid.Data4[3],
  205. guid.Data4[4], guid.Data4[5],
  206. guid.Data4[6], guid.Data4[7] );
  207. if ( fps.IsPropertyName() )
  208. swprintf( _xwcsValue.Get() + 37, L"%ws", fps.GetPropertyName() );
  209. else
  210. swprintf( _xwcsValue.Get() + 37, L"%u", fps.GetPropertyPropid() );
  211. _xwcsData.SetSize( 35 ); // 3*MAX_INT + 3*comma + fModifiable + NULL =
  212. // 3*10 + 3 + 1 + 1
  213. swprintf( _xwcsData.Get(), L"%u,%u,%u,%u", vt, cb, dwStoreLevel, fModifiable?1:0 );
  214. }