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.

363 lines
16 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. BaseHSM.h
  5. Abstract:
  6. Implementation of CSakNode. This is the base class for any
  7. of the node implementations, providing common functionality.
  8. Author:
  9. Rohde Wakefield [rohde] 12-Aug-1997
  10. Revision History:
  11. --*/
  12. #ifndef _BASEHSM_H
  13. #define _BASEHSM_H
  14. #define BHSM_MAX_CHILD_PROPS 15
  15. #define BHSM_MAX_NAME 40
  16. #define BHSM_MAX_REG_NAME 512
  17. #define BHSM_MAX_NODE_TYPES 10
  18. // Toolbar buttons for all nodes
  19. #define TB_CMD_VOLUME_SETTINGS 100
  20. #define TB_CMD_VOLUME_TOOLS 101
  21. #define TB_CMD_VOLUME_RULES 102
  22. #define TB_CMD_VOLUME_LIST_SCHED 110
  23. #define TB_CMD_VOLUME_LIST_NEW 111
  24. #define TB_CMD_MESE_COPY 120
  25. #define TB_CMD_CAR_COPIES 130
  26. typedef struct _RS_MMCButton {
  27. INT nBitmap;
  28. INT idCommand;
  29. BYTE fsState;
  30. BYTE fsType;
  31. UINT idButtonText;
  32. UINT idTooltipText;
  33. } RS_MMCBUTTON;
  34. #define MAX_TOOLBAR_BUTTONS 20
  35. // This is a dataobject-related structure that maintains basic information that needs to be passed
  36. // from one dataobject-taking method to another.
  37. struct INTERNAL {
  38. DATA_OBJECT_TYPES m_type; // What context is the data object.
  39. };
  40. //
  41. // Declare array that can be added to or completely cleared
  42. // Grows as needed
  43. //
  44. class CRsNodeArray : public CArray<ISakNode*, ISakNode*>
  45. {
  46. public:
  47. CRsNodeArray( ) { SetSize( 0, 10 ); };
  48. ~CRsNodeArray( ) { Clear( ); };
  49. ISakNode** begin( ) { return( GetData( ) ); };
  50. ISakNode** end( ) { return( GetData( ) + length( ) ); } ;
  51. INT length( ) { return( (INT)GetUpperBound( ) + 1 ); };
  52. HRESULT Add( ISakNode* pNode )
  53. {
  54. HRESULT hr = S_OK;
  55. try {
  56. CWsbBstrPtr keyAdd, keyEnum;
  57. CComPtr<ISakNodeProp> pNodeProp, pEnumProp;
  58. WsbAffirmHr( RsQueryInterface( pNode, ISakNodeProp, pNodeProp ) );
  59. WsbAffirmHr( pNodeProp->get_DisplayName_SortKey( &keyAdd ) );
  60. ISakNode*pNodeEnum;
  61. INT index;
  62. for( index = 0; index < length( ); index++ ) {
  63. pNodeEnum = GetAt( index );
  64. if( pNodeEnum ) {
  65. keyEnum.Free( );
  66. pEnumProp.Release( );
  67. if( SUCCEEDED( RsQueryInterface( pNodeEnum, ISakNodeProp, pEnumProp ) ) ) {
  68. if( SUCCEEDED( pEnumProp->get_DisplayName_SortKey( &keyEnum ) ) ) {
  69. if( _wcsicmp( keyAdd, keyEnum ) <= 0 ) {
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. try {
  77. CArray<ISakNode*, ISakNode*>::InsertAt( index, pNode );
  78. } catch( CMemoryException* pException ) {
  79. pException->Delete();
  80. WsbThrow( E_OUTOFMEMORY );
  81. }
  82. pNode->AddRef( );
  83. } WsbCatch( hr );
  84. return( hr );
  85. };
  86. void Clear( void )
  87. {
  88. ISakNode*pNode;
  89. for( int index = 0; index < length( ); index++ ) {
  90. pNode = GetAt( index );
  91. SetAt( index, 0 );
  92. if( pNode ) pNode->Release( );
  93. }
  94. RemoveAll( );
  95. };
  96. HRESULT CopyTo( int Index, ISakNode** ppNode )
  97. {
  98. if( !ppNode ) return( E_POINTER );
  99. *ppNode = GetAt( Index );
  100. if( *ppNode ) (*ppNode)->AddRef( );
  101. return S_OK;
  102. };
  103. };
  104. class ATL_NO_VTABLE CSakNode :
  105. public CComObjectRoot,
  106. public ISakNode,
  107. public IHsmEvent,
  108. public CComDualImpl<ISakNodeProp, &IID_ISakNodeProp, &LIBID_HSMADMINLib>,
  109. public IDataObject
  110. {
  111. public:
  112. CSakNode( ) : m_rTypeGuid(&(GUID_NULL)) {}
  113. HRESULT FinalConstruct( void );
  114. void FinalRelease( void );
  115. ULONG InternalAddRef( );
  116. ULONG InternalRelease( );
  117. // ISakNode methods
  118. STDMETHOD( InitNode ) ( ISakSnapAsk* pSakSnapAsk, IUnknown* pHsmObj, ISakNode* pParent );
  119. STDMETHOD( TerminateNode ) ( void );
  120. STDMETHOD( GetPrivateData ) ( OUT RS_PRIVATE_DATA* pData );
  121. STDMETHOD( SetPrivateData ) ( IN RS_PRIVATE_DATA Data );
  122. STDMETHOD( GetHsmObj ) ( IUnknown** ppHsmObj );
  123. STDMETHOD( GetNodeType ) ( GUID *pNodeType );
  124. STDMETHOD( FindNodeOfType ) ( REFGUID nodetype, ISakNode** ppNode );
  125. STDMETHOD( GetEnumState ) ( BOOL* pState );
  126. STDMETHOD( SetEnumState ) ( BOOL State );
  127. STDMETHOD( GetScopeID ) ( HSCOPEITEM* pid );
  128. STDMETHOD( SetScopeID ) ( HSCOPEITEM id );
  129. STDMETHOD( GetParent ) ( ISakNode ** ppParent );
  130. STDMETHOD( IsContainer ) ( void );
  131. STDMETHOD( CreateChildren ) ( void );
  132. STDMETHOD( EnumChildren ) ( IEnumUnknown ** ppEnum );
  133. STDMETHOD( DeleteChildren ) ( void );
  134. STDMETHOD( DeleteAllChildren ) ( void );
  135. STDMETHOD( ChildrenAreValid ) ( void );
  136. STDMETHOD( InvalidateChildren ) ( void );
  137. STDMETHOD( HasDynamicChildren ) ( void );
  138. STDMETHOD( EnumChildDisplayProps ) ( IEnumString ** ppEnum );
  139. STDMETHOD( EnumChildDisplayTitles ) ( IEnumString ** ppEnum );
  140. STDMETHOD( EnumChildDisplayPropWidths ) ( IEnumString ** ppEnum );
  141. STDMETHOD( GetMenuHelp ) ( LONG sCmd, BSTR * szHelp );
  142. STDMETHOD( SupportsPropertiesNoEngine ) ( void );
  143. STDMETHOD( SupportsProperties ) ( BOOL bMutliSelec );
  144. STDMETHOD( SupportsRefresh ) ( BOOL bMutliSelect );
  145. STDMETHOD( SupportsRefreshNoEngine ) ( );
  146. STDMETHOD( SupportsDelete ) ( BOOL bMutliSelec );
  147. STDMETHOD( AddPropertyPages ) ( RS_NOTIFY_HANDLE handle, IUnknown* pUnkPropSheetCallback, IEnumGUID *pEnumGuid, IEnumUnknown *pEnumUnkNode);
  148. STDMETHOD( ActivateView ) ( OLE_HANDLE );
  149. STDMETHOD( RefreshObject ) ( void );
  150. STDMETHOD( DeleteObject ) ( void );
  151. STDMETHOD( GetObjectId ) ( GUID *pObjectId );
  152. STDMETHOD( SetObjectId ) ( GUID pObjectId );
  153. STDMETHOD( SetupToolbar ) ( IToolbar *pToolbar );
  154. STDMETHOD( HasToolbar ) ( void );
  155. STDMETHOD( OnToolbarButtonClick ) ( IDataObject *pDataObject, long cmdId );
  156. STDMETHOD( IsValid ) ( );
  157. // IHsmEvent methods
  158. STDMETHOD( OnStateChange ) ( void );
  159. // ISakNodeProp methods
  160. STDMETHOD( get_DisplayName ) ( BSTR *pszName );
  161. STDMETHOD( put_DisplayName ) ( OLECHAR *pszName );
  162. STDMETHOD( get_DisplayName_SortKey ) ( BSTR *pszName );
  163. STDMETHOD( put_DisplayName_SortKey ) ( OLECHAR *pszName );
  164. STDMETHOD( get_Type ) ( BSTR *pszType );
  165. STDMETHOD( put_Type ) ( OLECHAR *pszType );
  166. STDMETHOD( get_Type_SortKey ) ( BSTR *pszType );
  167. STDMETHOD( get_Description ) ( BSTR *pszDesc );
  168. STDMETHOD( put_Description ) ( OLECHAR *pszDesc );
  169. STDMETHOD( get_Description_SortKey ) ( BSTR *pszDesc );
  170. // IDataObject methods
  171. public:
  172. // Implemented
  173. STDMETHOD( SetData ) ( LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease );
  174. STDMETHOD( GetData ) ( LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium );
  175. STDMETHOD( GetDataHere ) ( LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium );
  176. STDMETHOD( EnumFormatEtc ) ( DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc );
  177. // IDataObject methods that are Not Implemented
  178. private:
  179. STDMETHOD( QueryGetData ) ( LPFORMATETC /*lpFormatetc*/ )
  180. { return E_NOTIMPL; };
  181. STDMETHOD( GetCanonicalFormatEtc ) ( LPFORMATETC /*lpFormatetcIn*/, LPFORMATETC /*lpFormatetcOut*/ )
  182. { return E_NOTIMPL; };
  183. STDMETHOD( DAdvise ) ( LPFORMATETC /*lpFormatetc*/, DWORD /*advf*/, LPADVISESINK /*pAdvSink*/, LPDWORD /*pdwConnection*/ )
  184. { return E_NOTIMPL; };
  185. STDMETHOD( DUnadvise ) ( DWORD /*dwConnection*/ )
  186. { return E_NOTIMPL; };
  187. STDMETHOD( EnumDAdvise ) ( LPENUMSTATDATA* /*ppEnumAdvise*/ )
  188. { return E_NOTIMPL; };
  189. // Implementation
  190. public:
  191. CRsNodeArray m_Children; // Child nodes
  192. BOOL m_bEnumState; // TRUE if children have been enumerated
  193. HSCOPEITEM m_scopeID; // MMC scope item id.
  194. BOOL m_bChildrenAreValid; // TRUE if list of children is up-to-date
  195. CWsbBstrPtr m_szName; // name of node
  196. CWsbBstrPtr m_szName_SortKey; // name of node
  197. CWsbBstrPtr m_szType; // type of node
  198. CWsbBstrPtr m_szDesc; // description of node
  199. BSTR m_rgszChildPropIds[BHSM_MAX_CHILD_PROPS]; // array of child node property Ids
  200. BSTR m_rgszChildPropTitles[BHSM_MAX_CHILD_PROPS];// array of child node title properties
  201. BSTR m_rgszChildPropWidths[BHSM_MAX_CHILD_PROPS];// array of child node width properties
  202. INT m_cChildProps; // number of child node properties
  203. INT m_cChildPropsShow; // number of child node properties to show
  204. CComPtr<ISakNode> m_pParent;
  205. CComPtr<ISakSnapAsk> m_pSakSnapAsk; // pointer to the saksnap "ask" interface
  206. CComPtr<IUnknown> m_pHsmObj; // pointer to the underlying HSM COM object this node encapsulates
  207. const GUID* m_rTypeGuid; // pointer to the type guid for this node type
  208. BOOL m_bSupportsPropertiesNoEngine; // TRUE if this node has property pages.
  209. BOOL m_bSupportsPropertiesSingle; // TRUE if this node has property pages.
  210. BOOL m_bSupportsPropertiesMulti; // TRUE if this node has property pages.
  211. BOOL m_bSupportsRefreshSingle; // TRUE if this node supports the refresh method.
  212. BOOL m_bSupportsRefreshMulti; // TRUE if this node supports the refresh method.
  213. BOOL m_bSupportsRefreshNoEngine; // TRUE if this node supports the refresh method.
  214. BOOL m_bSupportsDeleteSingle; // TRUE if this node supports the delete method.
  215. BOOL m_bSupportsDeleteMulti; // TRUE if this node supports the delete method.
  216. BOOL m_bIsContainer; // TRUE if this node is a container type (as opposed to leaf).
  217. BOOL m_bHasDynamicChildren; // TRUE if this nodes immediate children change
  218. protected:
  219. GUID m_ObjectId;
  220. RS_PRIVATE_DATA m_PrivateData;
  221. INT m_ToolbarBitmap;
  222. INT m_cToolbarButtons;
  223. RS_MMCBUTTON m_ToolbarButtons[MAX_TOOLBAR_BUTTONS];
  224. // Clipboard formats that are required by the console
  225. public:
  226. static UINT m_cfNodeType;
  227. static UINT m_cfNodeTypeString;
  228. static UINT m_cfDisplayName;
  229. static UINT m_cfInternal;
  230. static UINT m_cfClassId;
  231. static UINT m_cfComputerName;
  232. static UINT m_cfEventLogViews;
  233. private:
  234. // Generic "GetData" which will allocate if told to
  235. HRESULT GetDataGeneric( LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium, BOOL DoAlloc );
  236. // methods to retrieve particular "flavors" of data from a dataobject
  237. HRESULT RetrieveNodeTypeData( LPSTGMEDIUM lpMedium );
  238. HRESULT RetrieveNodeTypeStringData( LPSTGMEDIUM lpMedium );
  239. HRESULT RetrieveDisplayName( LPSTGMEDIUM lpMedium );
  240. HRESULT RetrieveInternal( LPSTGMEDIUM lpMedium );
  241. HRESULT RetrieveClsid( LPSTGMEDIUM lpMedium );
  242. HRESULT RetrieveComputerName( LPSTGMEDIUM lpMedium );
  243. HRESULT RetrieveEventLogViews( LPSTGMEDIUM lpMedium );
  244. // methods to store particular "flavors" of data from a dataobject
  245. HRESULT StoreInternal( LPSTGMEDIUM lpMedium );
  246. // helper method utilized by each of the above
  247. HRESULT Retrieve(const void* pBuffer, DWORD len, LPSTGMEDIUM lpMedium);
  248. HRESULT Store(void* pBuffer, DWORD len, LPSTGMEDIUM lpMedium);
  249. // actual data store in this dataobject.
  250. INTERNAL m_internal;
  251. // Maintain a connection point
  252. CComPtr<IUnknown> m_pUnkConnection;
  253. DWORD m_Advise;
  254. protected:
  255. void SetConnection( IUnknown *pUnkConnection );
  256. virtual HRESULT RefreshScopePane( );
  257. // Registry Helper Functions for derived classes. Not a part of any interface.
  258. static HRESULT LoadRegString( HKEY hKey, OLECHAR * szValName, OLECHAR * sz, OLECHAR * szDefault );
  259. static HRESULT LoadRegDWord( HKEY hKey, OLECHAR * szValName, DWORD * pdw, DWORD dwDefault );
  260. // Helper functions for derived classes to set result pane properties from resource strings
  261. HRESULT FreeChildProps();
  262. HRESULT SetChildProps (const TCHAR* ResIdPropsIds, LONG resIdPropsTitles, LONG resIdPropsWidths);
  263. // Helper Functions to create our children.
  264. static HRESULT NewChild( REFGUID nodetype, IUnknown** ppUnkChild );
  265. HRESULT InternalDelete( BOOL Recurse );
  266. HRESULT AddChild( ISakNode* pChild );
  267. // General Helper functions - not part of any interface.
  268. static HRESULT LoadContextMenu( UINT nId, HMENU *phMenu );
  269. static HRESULT GetCLSIDFromNodeType( REFGUID nodetype, const CLSID ** ppclsid );
  270. static const OLECHAR * CSakNode::GetClassNameFromNodeType( REFGUID Nodetype );
  271. static int AddScopeImage( UINT nId );
  272. static int AddResultImage( UINT nId );
  273. static BSTR SysAlloc64BitSortKey( LONGLONG Number );
  274. };
  275. // macro for multiple-inheritance (CSakNode and a ISakNode derived interface)
  276. // Forwards all CSakNode implemented members to CSakNode explicitly
  277. #define FORWARD_BASEHSM_IMPLS \
  278. STDMETHOD( get_DisplayName ) ( BSTR *pszName ) { return CSakNode::get_DisplayName( pszName ); } \
  279. STDMETHOD( put_DisplayName ) ( OLECHAR *pszName ) { return CSakNode::put_DisplayName( pszName ); } \
  280. STDMETHOD( get_DisplayName_SortKey ) ( BSTR *pszName ) { return CSakNode::get_DisplayName_SortKey( pszName ); } \
  281. STDMETHOD( put_DisplayName_SortKey ) ( OLECHAR *pszName ) { return CSakNode::put_DisplayName_SortKey( pszName ); } \
  282. STDMETHOD( get_Type ) ( BSTR *pszType ) { return CSakNode::get_Type( pszType ); } \
  283. STDMETHOD( put_Type ) ( OLECHAR *pszType ) { return CSakNode::put_Type( pszType ); } \
  284. STDMETHOD( get_Type_SortKey ) ( BSTR *pszType ) { return CSakNode::get_Type_SortKey( pszType ); } \
  285. STDMETHOD( get_Description ) ( BSTR *pszDesc ) { return CSakNode::get_Description( pszDesc ); } \
  286. STDMETHOD( put_Description ) ( OLECHAR *pszDesc ) { return CSakNode::put_Description( pszDesc ); } \
  287. STDMETHOD( get_Description_SortKey ) ( BSTR *pszDesc ) { return CSakNode::get_Description_SortKey( pszDesc ); } \
  288. // Typedef of class that implements IEnumUnknown
  289. typedef CComObject<CComEnum<IEnumUnknown, &IID_IEnumUnknown, IUnknown *,
  290. _CopyInterface<IUnknown> > > CEnumUnknown;
  291. // Typedef of class that implements IEnumVARIANT
  292. typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT,
  293. _Copy<VARIANT> > > CEnumVariant;
  294. // Typedef of class that implements IEnumString
  295. typedef CComObject<CComEnum<IEnumString, &IID_IEnumString, LPOLESTR,
  296. _Copy<LPOLESTR> > > CEnumString;
  297. // Typedef of class that implements IEnumGUID
  298. typedef CComObject<CComEnum<IEnumGUID, &IID_IEnumGUID, GUID,
  299. _Copy<GUID> > > CEnumGUID;
  300. #endif