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.

331 lines
11 KiB

  1. // cookie.h : Declaration of CFileMgmtCookie and related classes
  2. #ifndef __COOKIE_H_INCLUDED__
  3. #define __COOKIE_H_INCLUDED__
  4. #include "bitflag.hxx"
  5. extern HINSTANCE g_hInstanceSave; // Instance handle of the DLL (initialized during CFileMgmtComponent::Initialize)
  6. #include "stdcooki.h"
  7. #include "nodetype.h"
  8. #include "shlobj.h" // LPITEMIDLIST
  9. typedef enum _COLNUM_SERVICES {
  10. COLNUM_SERVICES_SERVICENAME = 0,
  11. COLNUM_SERVICES_DESCRIPTION,
  12. COLNUM_SERVICES_STATUS,
  13. COLNUM_SERVICES_STARTUPTYPE,
  14. COLNUM_SERVICES_SECURITYCONTEXT,
  15. } COLNUM_SERVICES;
  16. #ifdef SNAPIN_PROTOTYPER
  17. typedef enum ScopeType {
  18. HTML,
  19. CONTAINER
  20. } ScopeType;
  21. #endif
  22. // forward declarations
  23. class CFileMgmtComponentData;
  24. class CFileMgmtResultCookie;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // cookie
  27. //REVIEW -- using pointers to ID's is necessary because some compilers don't like
  28. //references as template arguments.
  29. /////////////////////////////////////////////////////////////////////
  30. class CFileMgmtCookie : public CCookie, public CHasMachineName
  31. {
  32. public:
  33. CFileMgmtCookie( FileMgmtObjectType objecttype )
  34. : m_objecttype( objecttype )
  35. {}
  36. FileMgmtObjectType QueryObjectType()
  37. { return m_objecttype; }
  38. // CFileMgmtDataObject uses these methods to obtain return values
  39. // for various clipboard formats
  40. virtual HRESULT GetTransport( OUT FILEMGMT_TRANSPORT* pTransport );
  41. virtual HRESULT GetShareName( OUT CString& strShareName );
  42. virtual HRESULT GetSharePIDList( OUT LPITEMIDLIST *ppidl );
  43. virtual HRESULT GetSessionClientName( OUT CString& strSessionClientName );
  44. virtual HRESULT GetSessionUserName( OUT CString& strSessionUserName );
  45. virtual HRESULT GetSessionID( DWORD* pdwSessionID );
  46. virtual HRESULT GetFileID( DWORD* pdwFileID );
  47. virtual HRESULT GetServiceName( OUT CString& strServiceName );
  48. virtual HRESULT GetServiceDisplayName( OUT CString& strServiceDisplayName );
  49. virtual HRESULT GetExplorerViewDescription( OUT CString& strExplorerViewDescription );
  50. // these functions are used when sorting columns
  51. inline virtual DWORD GetNumOfCurrentUses() { return 0; }
  52. inline virtual DWORD GetNumOfOpenFiles() { return 0; }
  53. inline virtual DWORD GetConnectedTime() { return 0; }
  54. inline virtual DWORD GetIdleTime() { return 0; }
  55. inline virtual DWORD GetNumOfLocks() { return 0; }
  56. inline virtual BSTR GetColumnText(int nCol)
  57. {
  58. UNREFERENCED_PARAMETER (nCol);
  59. return L"";
  60. }
  61. // The cookie should return the appropriate string to display.
  62. virtual BSTR QueryResultColumnText( int nCol, CFileMgmtComponentData& refcdata ) = 0;
  63. // return <0, 0 or >0
  64. virtual HRESULT CompareSimilarCookies( CCookie* pOtherCookie, int* pnResult);
  65. virtual void AddRefCookie() = 0;
  66. virtual void ReleaseCookie() = 0;
  67. virtual void GetDisplayName( OUT CString& strref, BOOL fStaticNode );
  68. protected:
  69. FileMgmtObjectType m_objecttype;
  70. }; // CFileMgmtCookie
  71. /*
  72. /////////////////////////////////////////////////////////////////////
  73. class CFileMgmtCookieBlock
  74. : public CCookieBlock<CFileMgmtCookie>,
  75. public CStoresMachineName
  76. {
  77. public:
  78. CFileMgmtCookieBlock(
  79. CFileMgmtCookie* aCookies,
  80. int cCookies,
  81. LPCTSTR lpcszMachineName = NULL )
  82. : CCookieBlock<CFileMgmtCookie>( aCookies, cCookies ),
  83. CStoresMachineName( lpcszMachineName )
  84. {
  85. for (int i = 0; i < cCookies; i++)
  86. {
  87. aCookies[i].ReadMachineNameFrom( (CHasMachineName*)this );
  88. aCookies[i].m_pContainedInCookieBlock = this;
  89. }
  90. }
  91. }; // CFileMgmtCookieBlock
  92. */
  93. class CNewResultCookie
  94. : public CFileMgmtCookie // CODEWORK should eventually move into framework
  95. , public CBaseCookieBlock
  96. , private CBitFlag
  97. {
  98. public:
  99. CNewResultCookie( PVOID pvCookieTypeMarker, FileMgmtObjectType objecttype );
  100. virtual ~CNewResultCookie();
  101. // required for CBaseCookieBlock
  102. virtual void AddRefCookie() { CRefcountedObject::AddRef(); }
  103. virtual void ReleaseCookie() { CRefcountedObject::Release(); }
  104. virtual CCookie* QueryBaseCookie(int i)
  105. {
  106. UNREFERENCED_PARAMETER (i);
  107. return (CCookie*)this;
  108. }
  109. virtual int QueryNumCookies() { return 1; }
  110. // Mark-and-sweep support in CBitFlag
  111. // ctor marks cookies as New
  112. #define NEWRESULTCOOKIE_NEW 0x0
  113. #define NEWRESULTCOOKIE_DELETE 0x1
  114. #define NEWRESULTCOOKIE_OLD 0x2
  115. #define NEWRESULTCOOKIE_CHANGE 0x3
  116. #define NEWRESULTCOOKIE_MASK 0x3
  117. void MarkState( ULONG state ) { _SetMask(state, NEWRESULTCOOKIE_MASK); }
  118. BOOL QueryState( ULONG state ) { return (state == _QueryMask(NEWRESULTCOOKIE_MASK)); }
  119. void MarkForDeletion() { MarkState(NEWRESULTCOOKIE_DELETE); }
  120. BOOL IsMarkedForDeletion() { return QueryState(NEWRESULTCOOKIE_DELETE); }
  121. void MarkAsOld() { MarkState(NEWRESULTCOOKIE_OLD); }
  122. BOOL IsMarkedOld() { return QueryState(NEWRESULTCOOKIE_OLD); }
  123. void MarkAsNew() { MarkState(NEWRESULTCOOKIE_NEW); }
  124. BOOL IsMarkedNew() { return QueryState(NEWRESULTCOOKIE_NEW); }
  125. void MarkAsChanged() { MarkState(NEWRESULTCOOKIE_CHANGE); }
  126. BOOL IsMarkedChanged() { return QueryState(NEWRESULTCOOKIE_CHANGE); }
  127. virtual HRESULT SimilarCookieIsSameObject( CNewResultCookie* pOtherCookie, BOOL* pbSame ) = 0;
  128. virtual BOOL CopySimilarCookie( CNewResultCookie* pcookie );
  129. BOOL IsSameType( CNewResultCookie* pcookie )
  130. { return (m_pvCookieTypeMarker == pcookie->m_pvCookieTypeMarker); }
  131. // CHasMachineName Interface
  132. STORES_MACHINE_NAME;
  133. private:
  134. PVOID m_pvCookieTypeMarker;
  135. }; // CNewResultCookie
  136. /////////////////////////////////////////////////////////////////////
  137. class CFileMgmtScopeCookie : public CFileMgmtCookie, public CBaseCookieBlock
  138. {
  139. public:
  140. CFileMgmtScopeCookie( LPCTSTR lpcszMachineName = NULL,
  141. FileMgmtObjectType objecttype = FILEMGMT_ROOT );
  142. virtual ~CFileMgmtScopeCookie();
  143. virtual CCookie* QueryBaseCookie(int i);
  144. virtual int QueryNumCookies();
  145. // This is only possible for scope cookies which are not further differentiated
  146. void SetObjectType( FileMgmtObjectType objecttype )
  147. {
  148. ASSERT( IsAutonomousObjectType( objecttype ) );
  149. m_objecttype = objecttype;
  150. }
  151. virtual BSTR QueryResultColumnText( int nCol, CFileMgmtComponentData& refcdata );
  152. // CODEWORK there are only used for FILEMGMT_SERVICES
  153. SC_HANDLE m_hScManager; // Handle to service control manager database
  154. BOOL m_fQueryServiceConfig2; // TRUE => Machine support QueryServiceConfig2() API
  155. HSCOPEITEM m_hScopeItemParent; // used only for extension nodes
  156. virtual void AddRefCookie() { CRefcountedObject::AddRef(); }
  157. virtual void ReleaseCookie() { CRefcountedObject::Release(); }
  158. // CHasMachineName Interface
  159. STORES_MACHINE_NAME;
  160. virtual void GetDisplayName( OUT CString& strref, BOOL fStaticNode );
  161. void MarkResultChildren( CBITFLAG_FLAGWORD state );
  162. void AddResultCookie( CNewResultCookie* pcookie )
  163. { m_listResultCookieBlocks.AddHead( pcookie ); }
  164. void ScanAndAddResultCookie( CNewResultCookie* pcookie );
  165. void RemoveMarkedChildren();
  166. }; // CFileMgmtScopeCookie
  167. /////////////////////////////////////////////////////////////////////
  168. class CFileMgmtResultCookie : public CFileMgmtCookie
  169. {
  170. // can only create via subclass
  171. protected:
  172. CFileMgmtResultCookie( FileMgmtObjectType objecttype )
  173. : CFileMgmtCookie( objecttype )
  174. , m_pobject( NULL )
  175. {
  176. ASSERT( IsValidObjectType( objecttype ) &&
  177. !IsAutonomousObjectType( objecttype ) );
  178. }
  179. // still pure virtual
  180. virtual void AddRefCookie() = 0;
  181. virtual void ReleaseCookie() = 0;
  182. public:
  183. PVOID m_pobject;
  184. }; // CFileMgmtResultCookie
  185. #ifdef SNAPIN_PROTOTYPER
  186. /////////////////////////////////////////////////////////////////////
  187. class CPrototyperScopeCookie : public CFileMgmtScopeCookie
  188. {
  189. public:
  190. CPrototyperScopeCookie( FileMgmtObjectType objecttype = FILEMGMT_ROOT )
  191. : CFileMgmtScopeCookie(NULL, objecttype )
  192. {
  193. ASSERT( IsAutonomousObjectType( objecttype ) );
  194. m_NumChildren = 0;
  195. m_NumLeafNodes = 0;
  196. }
  197. virtual BSTR QueryResultColumnText( int nCol, CFileMgmtComponentData& refcdata );
  198. CString m_DisplayName;
  199. CString m_Header;
  200. CString m_RecordData;
  201. CString m_HTMLURL;
  202. CString m_DefaultMenu;
  203. CString m_TaskMenu;
  204. CString m_NewMenu;
  205. CString m_DefaultMenuCommand;
  206. CString m_TaskMenuCommand;
  207. CString m_NewMenuCommand;
  208. int m_NumChildren;
  209. int m_NumLeafNodes;
  210. ScopeType m_ScopeType;
  211. }; // CPrototyperScopeCookie
  212. /////////////////////////////////////////////////////////////////////
  213. class CPrototyperScopeCookieBlock :
  214. public CCookieBlock<CPrototyperScopeCookie>,
  215. public CStoresMachineName
  216. {
  217. public:
  218. CPrototyperScopeCookieBlock( CPrototyperScopeCookie* aCookies,
  219. int cCookies, LPCTSTR lpcszMachineName = NULL)
  220. : CCookieBlock<CPrototyperScopeCookie>( aCookies, cCookies ),
  221. CStoresMachineName( lpcszMachineName )
  222. {
  223. ASSERT(NULL != aCookies && 0 < cCookies);
  224. for (int i = 0; i < cCookies; i++)
  225. {
  226. //aCookies[i].m_pContainedInCookieBlock = this;
  227. //aCookies[i].ReadMachineNameFrom( (CHasMachineName*)this );
  228. } // for
  229. }
  230. }; // CPrototyperScopeCookieBlock
  231. /////////////////////////////////////////////////////////////////////
  232. class CPrototyperResultCookie : public CFileMgmtResultCookie
  233. {
  234. public:
  235. CPrototyperResultCookie( FileMgmtObjectType objecttype = FILEMGMT_PROTOTYPER_LEAF )
  236. : CFileMgmtResultCookie( objecttype ) {}
  237. virtual BSTR QueryResultColumnText( int nCol, CFileMgmtComponentData& refcdata );
  238. CString m_DisplayName;
  239. CString m_RecordData;
  240. CString m_DefaultMenu;
  241. CString m_TaskMenu;
  242. CString m_NewMenu;
  243. CString m_DefaultMenuCommand;
  244. CString m_TaskMenuCommand;
  245. CString m_NewMenuCommand;
  246. virtual void AddRefCookie() {}
  247. virtual void ReleaseCookie() {}
  248. // CHasMachineName
  249. class CPrototyperResultCookieBlock * m_pCookieBlock;
  250. DECLARE_FORWARDS_MACHINE_NAME(m_pCookieBlock)
  251. }; // CPrototyperResultCookie
  252. /////////////////////////////////////////////////////////////////////
  253. class CPrototyperResultCookieBlock :
  254. public CCookieBlock<CPrototyperResultCookie>,
  255. public CStoresMachineName
  256. {
  257. public:
  258. CPrototyperResultCookieBlock( CPrototyperResultCookie* aCookies, int cCookies,
  259. LPCTSTR lpcszMachineName = NULL)
  260. : CCookieBlock<CPrototyperResultCookie>( aCookies, cCookies ),
  261. CStoresMachineName( lpcszMachineName )
  262. {
  263. ASSERT(NULL != aCookies && 0 < cCookies);
  264. for (int i = 0; i < cCookies; i++)
  265. {
  266. //aCookies[i].m_pContainedInCookieBlock = this;
  267. } // for
  268. }
  269. }; // CPrototyperResultCookieBlock
  270. #endif // SNAPIN_PROTOTYPER
  271. #endif // ~__COOKIE_H_INCLUDED__