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.

288 lines
8.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1998-1999 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: regpropertybag.h
  6. //
  7. // Project: Chameleon
  8. //
  9. // Description: Registry property bag class definition
  10. //
  11. // Author: TLP
  12. //
  13. // When Who What
  14. // ---- --- ----
  15. // 12/3/98 TLP Original version
  16. //
  17. ///////////////////////////////////////////////////////////////////////////
  18. #ifndef __INC_REG_PROPERTY_BAG_H_
  19. #define __INC_REG_PROPERTY_BAG_H_
  20. #include "basedefs.h"
  21. #include "propertybag.h"
  22. #include "propertybagfactory.h"
  23. #include <comdef.h>
  24. #include <comutil.h>
  25. #pragma warning( disable : 4786 ) // template produced long name warning
  26. #include <map>
  27. #include <string>
  28. using namespace std;
  29. ///////////////////////////////////////////////////////////////////////////
  30. class CRegError
  31. {
  32. public:
  33. CRegError() { }
  34. ~CRegError() { }
  35. };
  36. ///////////////////////////////////////////////////////////////////////////
  37. class CRegInfo
  38. {
  39. public:
  40. ///////////////////////////////////////////////////////////////////////////
  41. CRegInfo(bool& bOK, HKEY hKey)
  42. : m_dwSubKeys(0),
  43. m_dwValues(0),
  44. m_dwMaxSubKeyName(0),
  45. m_pSubKeyName(NULL),
  46. m_dwMaxValueName(0),
  47. m_pValueName(NULL),
  48. m_dwMaxValueData(0),
  49. m_pValueData(NULL)
  50. {
  51. bOK = false;
  52. LONG lResult = RegQueryInfoKey(
  53. hKey, // handle to key to query
  54. NULL, // address of buffer for class string
  55. NULL, // address of size of class string buffer
  56. NULL, // reserved
  57. &m_dwSubKeys, // address of buffer for number of subkeys
  58. &m_dwMaxSubKeyName, // address of buffer for longest subkey name length
  59. NULL, // address of buffer for longest class string length
  60. &m_dwValues, // address of buffer for number of value entries
  61. &m_dwMaxValueName, // address of buffer for longest value name length
  62. &m_dwMaxValueData, // address of buffer for longest value data length
  63. NULL, // address of buffer for security descriptor length
  64. NULL // address of buffer for last write time
  65. );
  66. if ( ERROR_SUCCESS == lResult )
  67. {
  68. m_dwMaxSubKeyName++;
  69. m_dwMaxValueName++;
  70. auto_ptr<TCHAR> pSubKey (new TCHAR[m_dwMaxSubKeyName]);
  71. auto_ptr<TCHAR> pValueName (new TCHAR[m_dwMaxValueName]);
  72. m_pValueData = new BYTE[m_dwMaxValueData + 2];
  73. m_pSubKeyName = pSubKey.release();
  74. m_pValueName = pValueName.release();
  75. bOK = true;
  76. }
  77. }
  78. ///////////////////////////////////////////////////////////////////////////
  79. ~CRegInfo()
  80. {
  81. if ( m_pSubKeyName )
  82. delete [] m_pSubKeyName;
  83. if ( m_pValueName )
  84. delete [] m_pValueName;
  85. if ( m_pValueData )
  86. delete [] m_pValueData;
  87. }
  88. ///////////////////////////////////////////////////////////////////////////
  89. DWORD m_dwSubKeys;
  90. DWORD m_dwValues;
  91. DWORD m_dwMaxSubKeyName;
  92. TCHAR* m_pSubKeyName;
  93. DWORD m_dwMaxValueName;
  94. TCHAR* m_pValueName;
  95. DWORD m_dwMaxValueData;
  96. BYTE* m_pValueData;
  97. private:
  98. CRegInfo();
  99. CRegInfo(const CRegInfo& rhs);
  100. CRegInfo& operator = (CRegInfo& rhs);
  101. };
  102. typedef map<wstring, _variant_t> PropertyMap;
  103. typedef PropertyMap::iterator PropertyMapIterator;
  104. ///////////////////////////////////////////////////////////////////////////
  105. class CRegPropertyBag : public CPropertyBag
  106. {
  107. public:
  108. ~CRegPropertyBag();
  109. // CPropertyBag interface functions (see propertybag.h)
  110. bool open(void);
  111. void close(void);
  112. void getLocation(CLocationInfo& location);
  113. LPCWSTR getName(void);
  114. bool load(void);
  115. bool save(void);
  116. bool IsContainer(void);
  117. PPROPERTYBAGCONTAINER getContainer(void);
  118. bool IsProperty(LPCWSTR pszPropertyName);
  119. bool get(LPCWSTR pszPropertyName, VARIANT* pValue);
  120. bool put(LPCWSTR pszPropertyName, VARIANT* pValue);
  121. bool reset(void);
  122. DWORD getMaxPropertyName(void);
  123. bool current(LPWSTR pszPropertyName, VARIANT* pValue);
  124. bool next(void);
  125. private:
  126. // Only the property bag factory can create a reg property bag
  127. friend PPROPERTYBAG MakePropertyBag(
  128. /*[in]*/ PROPERTY_BAG_TYPE eType,
  129. /*[in]*/ CLocationInfo& location
  130. );
  131. CRegPropertyBag(CLocationInfo& location);
  132. // No copy or assignment
  133. CRegPropertyBag(const CRegPropertyBag& rhs);
  134. CRegPropertyBag& operator = (CRegPropertyBag& rhs);
  135. //////////////////////////////////////////////////////////////////////////
  136. PropertyMapIterator
  137. MyFind(LPCWSTR pszPropertyName);
  138. //////////////////////////////////////////////////////////////////////////
  139. bool
  140. IsSupportedType(VARTYPE vt);
  141. //////////////////////////////////////////////////////////////////////////
  142. VARTYPE
  143. getTypeFromBuffer(
  144. /*[in]*/ DWORD dwBuffSize,
  145. /*[in]*/ PBYTE pBuff
  146. );
  147. //////////////////////////////////////////////////////////////////////////
  148. HKEY
  149. getKey(void) const
  150. { return m_key.m_hKey; }
  151. //////////////////////////////////////////////////////////////////////////
  152. void
  153. releaseProperties(void);
  154. //////////////////////////////////////////////////////////////////////////
  155. bool m_isContainer;
  156. DWORD m_maxPropertyName;
  157. CLocationInfo m_locationInfo;
  158. CRegKey m_key;
  159. wstring m_name;
  160. PropertyMapIterator m_current;
  161. PropertyMap m_properties;
  162. };
  163. typedef CMasterPtr<CRegPropertyBag> MPREGPROPERTYBAG;
  164. ///////////////////////////////////////////////////////////////////////////
  165. class CRegPropertyBagContainer : public CPropertyBagContainer
  166. {
  167. public:
  168. ~CRegPropertyBagContainer();
  169. // CPropertyBagContainer interface functions (see propertybag.h)
  170. //
  171. bool open(void);
  172. void close(void);
  173. void getLocation(CLocationInfo& locationInfo);
  174. LPCWSTR getName(void);
  175. DWORD count(void);
  176. PPROPERTYBAG add(LPCWSTR pszName);
  177. bool remove(LPCWSTR pszName);
  178. PPROPERTYBAG find(LPCWSTR pszName);
  179. PPROPERTYBAG current(void);
  180. bool reset(void);
  181. bool next(void);
  182. private:
  183. // Only the property bag factory can create a reg property bag container
  184. friend PPROPERTYBAGCONTAINER MakePropertyBagContainer(
  185. /*[in]*/ PROPERTY_BAG_TYPE eType,
  186. /*[in]*/ CLocationInfo& locationInfo
  187. );
  188. CRegPropertyBagContainer(CLocationInfo& locationInfo);
  189. // No copy or assignment
  190. CRegPropertyBagContainer(const CRegPropertyBagContainer& rhs);
  191. CRegPropertyBagContainer& operator = (CRegPropertyBagContainer& rhs);
  192. //////////////////////////////////////////////////////////////////////////
  193. HKEY
  194. getKey(void) const
  195. { return m_key.m_hKey; }
  196. //////////////////////////////////////////////////////////////////////////
  197. PPROPERTYBAG
  198. addBag(LPCWSTR pszName);
  199. //////////////////////////////////////////////////////////////////////////
  200. void
  201. releaseBags(void);
  202. typedef map< wstring, PPROPERTYBAG > BagMap;
  203. typedef BagMap::iterator BagMapIterator;
  204. CLocationInfo m_locationInfo;
  205. CRegKey m_key;
  206. wstring m_name;
  207. BagMapIterator m_current;
  208. BagMap m_bags;
  209. };
  210. typedef CMasterPtr<CRegPropertyBagContainer> MPREGPROPERTYBAGCONTAINER;
  211. #endif // __INC_REG_PROPERTY_BAG_H_