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.

194 lines
7.8 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: MetaUtil object
  6. File: MUtilObj.h
  7. Owner: t-BrianM
  8. This file contains the headers for the main MetaUtil object and
  9. utility functions.
  10. ===================================================================*/
  11. #ifndef __METAUTIL_H_
  12. #define __METAUTIL_H_
  13. #include "resource.h" // main symbols
  14. #include <iadmw.h> // Metabase base object unicode interface
  15. #include <iiscnfg.h> // MD_ & IIS_MD_ defines
  16. #include "utility.h"
  17. #include "MetaSchm.h"
  18. #include "keycol.h"
  19. #include "propcol.h"
  20. #include "chkerror.h"
  21. #define MUTIL_OPEN_KEY_TIMEOUT 5000 //Timeout for metabase OpenKey() calls
  22. /*
  23. * C M e t a U t i l
  24. *
  25. * Implements the main MetaUtil object
  26. */
  27. class ATL_NO_VTABLE CMetaUtil :
  28. public CComObjectRootEx<CComSingleThreadModel>,
  29. public CComCoClass<CMetaUtil, &CLSID_MetaUtil>,
  30. public ISupportErrorInfo,
  31. public IDispatchImpl<IMetaUtil, &IID_IMetaUtil, &LIBID_MetaUtil>
  32. {
  33. public:
  34. CMetaUtil();
  35. HRESULT FinalConstruct();
  36. void FinalRelease();
  37. DECLARE_REGISTRY_RESOURCEID(IDR_METAUTIL)
  38. BEGIN_COM_MAP(CMetaUtil)
  39. COM_INTERFACE_ENTRY(IMetaUtil)
  40. COM_INTERFACE_ENTRY(IDispatch)
  41. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  42. END_COM_MAP()
  43. // DECLARE_NOT_AGGREGATABLE(CMetaUtil)
  44. // ISupportsErrorInfo
  45. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  46. // IMetaUtil
  47. STDMETHOD(EnumProperties)(/*[in]*/ BSTR bstrKey, /*[out, retval]*/ IPropertyCollection **ppIReturn);
  48. STDMETHOD(EnumKeys)(/*[in]*/ BSTR bstrBaseKey, /*[out, retval]*/ IKeyCollection **ppIReturn);
  49. STDMETHOD(EnumAllKeys)(/*[in]*/ BSTR bstrBaseKey, /*[out, retval]*/ IKeyCollection **ppIReturn);
  50. STDMETHOD(CreateKey)(/*[in]*/ BSTR bstrKey);
  51. STDMETHOD(DeleteKey)(/*[in]*/ BSTR bstrKey);
  52. STDMETHOD(RenameKey)(/*[in]*/ BSTR bstrOldName, /*[in]*/ BSTR bstrNewName);
  53. STDMETHOD(CopyKey)(/*[in]*/ BSTR bstrSrcKey, /*[in]*/ BSTR bstrDestKey, /*[in]*/ BOOL fOverwrite);
  54. STDMETHOD(MoveKey)(/*[in]*/ BSTR bstrSrcKey, /*[in]*/ BSTR bstrDestKey, /*[in]*/ BOOL fOverwrite);
  55. STDMETHOD(GetProperty)(/*[in]*/ BSTR bstrKey, /*[in]*/ VARIANT varId, /*[out, retval]*/ IProperty **ppIReturn);
  56. STDMETHOD(CreateProperty)(/*[in]*/ BSTR bstrKey, /*[in]*/ VARIANT varId, /*[out, retval]*/ IProperty **ppIReturn);
  57. STDMETHOD(DeleteProperty)(/*[in]*/ BSTR bstrKey, /*[in]*/ VARIANT varId);
  58. STDMETHOD(CheckSchema)(/*[in]*/ BSTR bstrMachine, /*[out, retval]*/ ICheckErrorCollection **ppIReturn);
  59. STDMETHOD(CheckKey)(/*[in]*/ BSTR bstrKey, /*[out, retval]*/ ICheckErrorCollection **ppIReturn);
  60. STDMETHOD(ExpandString)(/*[in]*/ BSTR bstrIn, /*[out, retval]*/ BSTR *pbstrRet);
  61. STDMETHOD(PropIdToName)(/*[in]*/ BSTR bstrKey, /*[in]*/ long lId, /*[out, retval]*/ BSTR *pbstrName);
  62. STDMETHOD(PropNameToId)(/*[in]*/ BSTR bstrKey, /*[in]*/ BSTR bstrName, /*[out, retval]*/ long *plId);
  63. STDMETHOD(get_Config)(/*[in]*/ BSTR bstrSetting, /*[out, retval]*/ VARIANT *pvarValue);
  64. STDMETHOD(put_Config)(/*[in]*/ BSTR bstrSetting, /*[in]*/ VARIANT varValue);
  65. private:
  66. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  67. CComPtr<IMSAdminBase> m_pIMeta;
  68. // Schema table
  69. CMetaSchemaTable *m_pCSchemaTable;
  70. // Configuration variables
  71. DWORD m_dwMaxPropSize;
  72. DWORD m_dwMaxKeySize;
  73. DWORD m_dwMaxNumErrors;
  74. // General check methods
  75. void AddError(CComObject<CCheckErrorCollection> *pCErrorCol, long lId, long lSeverity, LPCTSTR tszKey, LPCTSTR tszSubKey, DWORD dwProperty);
  76. BOOL KeyExists(METADATA_HANDLE hMDKey, LPTSTR tszSubKey);
  77. BOOL PropertyExists(METADATA_HANDLE hMDKey, LPTSTR tszSubKey, DWORD dwId);
  78. // CheckSchema specific methods
  79. HRESULT CheckPropertyNames(CComObject<CCheckErrorCollection> *pCErrorCol, METADATA_HANDLE hMDMachine, LPTSTR tszMachine);
  80. HRESULT CheckPropertyTypes(CComObject<CCheckErrorCollection> *pCErrorCol, METADATA_HANDLE hMDMachine, LPTSTR tszMachine);
  81. HRESULT CheckClasses(CComObject<CCheckErrorCollection> *pCErrorCol, METADATA_HANDLE hMDMachine, LPTSTR tszMachine);
  82. HRESULT CheckClassProperties(CComObject<CCheckErrorCollection> *pCErrorCol, METADATA_HANDLE hMDClassKey, LPTSTR tszClassKey, LPTSTR tszClassSubKey);
  83. // CheckKey specific methods
  84. BOOL CheckCLSID(LPCTSTR tszCLSID);
  85. BOOL CheckMTXPackage(LPCTSTR tszPackId);
  86. HRESULT CheckKeyType(CComObject<CCheckErrorCollection> *pCErrorCol, METADATA_HANDLE hMDKey, LPTSTR tszKey);
  87. HRESULT CheckIfFileExists(LPCTSTR pszFSPath, BOOL *pfExists);
  88. };
  89. // Methods also supported by the collections
  90. HRESULT CreateKey(CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszKey);
  91. HRESULT DeleteKey(CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszKey);
  92. HRESULT CopyKey(CComPtr<IMSAdminBase> &pIMeta, LPTSTR tszSrcKey, LPTSTR tszDestKey, BOOL fOverwrite, BOOL fCopy);
  93. HRESULT GetProperty(CComPtr<IMSAdminBase> &pIMeta, CMetaSchemaTable *pCSchemaTable, LPCTSTR tszKey, VARIANT varId, IProperty **ppIReturn);
  94. HRESULT CreateProperty(CComPtr<IMSAdminBase> &pIMeta, CMetaSchemaTable *pCSchemaTable, LPCTSTR tszKey, VARIANT varId, IProperty **ppIReturn);
  95. HRESULT DeleteProperty(CComPtr<IMSAdminBase> &pIMeta, CMetaSchemaTable *pCSchemaTable, LPTSTR tszKey, VARIANT varId);
  96. // Utility
  97. HRESULT VarToMetaId(CMetaSchemaTable *pCSchemaTable, LPCTSTR tszKey, VARIANT varId, DWORD *pdwId);
  98. // Schema Error Constants (*_S is severity)
  99. #define MUTIL_CHK_NO_SCHEMA 1000
  100. #define MUTIL_CHK_NO_SCHEMA_S 1
  101. #define MUTIL_CHK_NO_PROPERTIES 1001
  102. #define MUTIL_CHK_NO_PROPERTIES_S 1
  103. #define MUTIL_CHK_NO_PROP_NAMES 1002
  104. #define MUTIL_CHK_NO_PROP_NAMES_S 1
  105. #define MUTIL_CHK_NO_PROP_TYPES 1003
  106. #define MUTIL_CHK_NO_PROP_TYPES_S 1
  107. #define MUTIL_CHK_NO_CLASSES 1004
  108. #define MUTIL_CHK_NO_CLASSES_S 1
  109. #define MUTIL_CHK_PROP_NAME_BAD_TYPE 1100
  110. #define MUTIL_CHK_PROP_NAME_BAD_TYPE_S 1
  111. #define MUTIL_CHK_PROP_NAME_NOT_UNIQUE 1101
  112. #define MUTIL_CHK_PROP_NAME_NOT_UNIQUE_S 1
  113. #define MUTIL_CHK_PROP_NAME_NOT_CASE_UNIQUE 1102
  114. #define MUTIL_CHK_PROP_NAME_NOT_CASE_UNIQUE_S 1
  115. #define MUTIL_CHK_PROP_TYPE_BAD_TYPE 1200
  116. #define MUTIL_CHK_PROP_TYPE_BAD_TYPE_S 1
  117. #define MUTIL_CHK_PROP_TYPE_BAD_DATA 1201
  118. #define MUTIL_CHK_PROP_TYPE_BAD_DATA_S 2
  119. #define MUTIL_CHK_CLASS_NO_MANDATORY 1300
  120. #define MUTIL_CHK_CLASS_NO_MANDATORY_S 1
  121. #define MUTIL_CHK_CLASS_NO_OPTIONAL 1301
  122. #define MUTIL_CHK_CLASS_NO_OPTIONAL_S 1
  123. #define MUTIL_CHK_CLASS_NOT_CASE_UNIQUE 1302
  124. #define MUTIL_CHK_CLASS_NOT_CASE_UNIQUE_S 2
  125. #define MUTIL_CHK_CLASS_PROP_NO_TYPE 1303
  126. #define MUTIL_CHK_CLASS_PROP_NO_TYPE_S 2
  127. #define MUTIL_CHK_CLASS_PROP_BAD_DATA_TYPE 1304
  128. #define MUTIL_CHK_CLASS_PROP_BAD_DATA_TYPE_S 2
  129. #define MUTIL_CHK_CLASS_PROP_BAD_USER_TYPE 1305
  130. #define MUTIL_CHK_CLASS_PROP_BAD_USER_TYPE_S 2
  131. #define MUTIL_CHK_CLASS_PROP_BAD_ATTR 1306
  132. #define MUTIL_CHK_CLASS_PROP_BAD_ATTR_S 2
  133. #define MUTIL_CHK_DATA_TOO_BIG 2000
  134. #define MUTIL_CHK_DATA_TOO_BIG_S 3
  135. #define MUTIL_CHK_KEY_TOO_BIG 2001
  136. #define MUTIL_CHK_KEY_TOO_BIG_S 3
  137. #define MUTIL_CHK_CLSID_NOT_FOUND 2002
  138. #define MUTIL_CHK_CLSID_NOT_FOUND_S 1
  139. #define MUTIL_CHK_MTX_PACK_ID_NOT_FOUND 2003
  140. #define MUTIL_CHK_MTX_PACK_ID_NOT_FOUND_S 1
  141. #define MUTIL_CHK_PATH_NOT_FOUND 2004
  142. #define MUTIL_CHK_PATH_NOT_FOUND_S 1
  143. #define MUTIL_CHK_NO_NAME_ENTRY 2100
  144. #define MUTIL_CHK_NO_NAME_ENTRY_S 3
  145. #define MUTIL_CHK_NO_TYPE_ENTRY 2101
  146. #define MUTIL_CHK_NO_TYPE_ENTRY_S 3
  147. #define MUTIL_CHK_BAD_DATA_TYPE 2102
  148. #define MUTIL_CHK_BAD_DATA_TYPE_S 2
  149. #define MUTIL_CHK_BAD_USER_TYPE 2103
  150. #define MUTIL_CHK_BAD_USER_TYPE_S 2
  151. #define MUTIL_CHK_BAD_ATTR 2104
  152. #define MUTIL_CHK_BAD_ATTR_S 2
  153. #define MUTIL_CHK_NO_KEYTYPE 2200
  154. #define MUTIL_CHK_NO_KEYTYPE_S 3
  155. #define MUTIL_CHK_NO_KEYTYPE_NOT_FOUND 2201
  156. #define MUTIL_CHK_NO_KEYTYPE_NOT_FOUND_S 1
  157. #define MUTIL_CHK_MANDATORY_PROP_MISSING 2202
  158. #define MUTIL_CHK_MANDATORY_PROP_MISSING_S 2
  159. #define MUTIL_CHK_TOO_MANY_ERRORS 9000
  160. #define MUTIL_CHK_TOO_MANY_ERRORS_S 3
  161. #endif //__METAUTIL_H_