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.

418 lines
13 KiB

  1. #ifndef POP3Serversnap_h
  2. #define POP3Serversnap_h
  3. #include "resource.h"
  4. #include <atlsnap.h>
  5. #include <objidl.h>
  6. #include "pop3.h"
  7. #include "RootNode.h"
  8. #include <P3Admin.h>
  9. enum _node_icons {
  10. ROOTNODE_ICON = 0,
  11. SERVERNODE_ICON = 0,
  12. DOMAINNODE_ICON,
  13. USERNODE_ICON,
  14. DOMAINNODE_LOCKED_ICON,
  15. USERNODE_LOCKED_ICON,
  16. MAX_NODE_ICON
  17. };
  18. enum _notify_allviews {
  19. NAV_REFRESH,
  20. NAV_DELETE,
  21. NAV_ADD,
  22. NAV_REFRESHCHILD
  23. };
  24. class CPOP3ServerSnapComponent;
  25. //////////////////////////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CPOP3ServerSnapData
  28. //
  29. /////////////////////////////////////////////////////////////////////////////////////////////////
  30. class CPOP3ServerSnapData :
  31. public CComObjectRootEx<CComSingleThreadModel>,
  32. public CSnapInObjectRoot<1, CPOP3ServerSnapData>,
  33. public IComponentDataImpl<CPOP3ServerSnapData, CPOP3ServerSnapComponent>,
  34. public IExtendContextMenuImpl<CPOP3ServerSnapData>,
  35. public IExtendPropertySheetImpl<CPOP3ServerSnapData>,
  36. public CComCoClass<CPOP3ServerSnapData, &CLSID_POP3ServerSnap>,
  37. public IPersistStream,
  38. public ISnapinHelp2
  39. {
  40. public:
  41. CPOP3ServerSnapData()
  42. {
  43. m_pNode = new CRootNode;
  44. _ASSERTE(m_pNode != NULL);
  45. m_pComponentData = this;
  46. }
  47. virtual ~CPOP3ServerSnapData()
  48. {
  49. if( m_pNode )
  50. {
  51. delete m_pNode;
  52. m_pNode = NULL;
  53. }
  54. }
  55. BEGIN_COM_MAP(CPOP3ServerSnapData)
  56. COM_INTERFACE_ENTRY(IComponentData)
  57. COM_INTERFACE_ENTRY(ISnapinHelp2)
  58. COM_INTERFACE_ENTRY(IExtendContextMenu)
  59. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  60. COM_INTERFACE_ENTRY(IPersistStream)
  61. END_COM_MAP()
  62. DECLARE_NOT_AGGREGATABLE(CPOP3ServerSnapData)
  63. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  64. static void WINAPI ObjectMain(bool bStarting)
  65. {
  66. if ( bStarting )
  67. {
  68. CSnapInItem::Init();
  69. }
  70. }
  71. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  72. {
  73. // On a property change (Server only) we need to update all views of the Server Node completely.
  74. if( event == MMCN_PROPERTY_CHANGE && !lpDataObject && param )
  75. {
  76. CSnapInItem* pItem = (CSnapInItem*)param;
  77. HRESULT hr = pItem->Notify( MMCN_REFRESH, arg, param, m_pComponentData, NULL, CCT_SCOPE );
  78. if( SUCCEEDED(hr) )
  79. {
  80. // Get our Data Object
  81. CComPtr<IDataObject> spDataObject = NULL;
  82. pItem->GetDataObject(&spDataObject, CCT_SCOPE);
  83. if( !spDataObject ) return E_FAIL;
  84. // Call the Update, but don't update return result
  85. return m_spConsole->UpdateAllViews( spDataObject, 0, (LONG_PTR)NAV_ADD );
  86. }
  87. return hr;
  88. }
  89. if ( lpDataObject != NULL )
  90. {
  91. return IComponentDataImpl<CPOP3ServerSnapData, CPOP3ServerSnapComponent>::Notify(lpDataObject, event, arg, param);
  92. }
  93. return E_NOTIMPL;
  94. }
  95. // ISnapinHelp2
  96. STDMETHOD(GetHelpTopic)(LPOLESTR* ppszHelpFile);
  97. STDMETHOD(GetLinkedTopics)(LPOLESTR* ppszHelpFiles);
  98. // IPersistStream
  99. STDMETHOD(IsDirty)()
  100. {
  101. return S_FALSE;
  102. }
  103. STDMETHOD(Load)(IStream *pStream)
  104. {
  105. if( m_pNode )
  106. {
  107. return static_cast<CRootNode*>(m_pNode)->Load(pStream);
  108. }
  109. return E_FAIL;
  110. }
  111. STDMETHOD(Save)(IStream *pStream, BOOL fClearDirty)
  112. {
  113. if( m_pNode )
  114. {
  115. return static_cast<CRootNode*>(m_pNode)->Save(pStream);
  116. }
  117. return E_FAIL;
  118. }
  119. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize)
  120. {
  121. return E_NOTIMPL;
  122. }
  123. STDMETHOD(GetClassID)(CLSID *pClassID)
  124. {
  125. if( pClassID )
  126. {
  127. memcpy(pClassID, &CLSID_POP3ServerSnap, sizeof(CLSID));
  128. return S_OK;
  129. }
  130. return E_POINTER;
  131. }
  132. // Class registration method
  133. static HRESULT WINAPI UpdateRegistry(BOOL bRegister);
  134. };
  135. /////////////////////////////////////////////////////////////////////////////////
  136. //
  137. // CPOP3ServerSnapComponent
  138. //
  139. ////////////////////////////////////////////////////////////////////////////////
  140. class CPOP3ServerSnapComponent :
  141. public CComObjectRootEx<CComSingleThreadModel>,
  142. public CSnapInObjectRoot<2, CPOP3ServerSnapData>,
  143. public IExtendContextMenuImpl<CPOP3ServerSnapComponent>,
  144. public IExtendPropertySheetImpl<CPOP3ServerSnapComponent>,
  145. public IComponentImpl<CPOP3ServerSnapComponent>
  146. {
  147. public:
  148. BEGIN_COM_MAP(CPOP3ServerSnapComponent)
  149. COM_INTERFACE_ENTRY(IComponent)
  150. COM_INTERFACE_ENTRY(IExtendContextMenu)
  151. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  152. END_COM_MAP()
  153. public:
  154. CPOP3ServerSnapComponent()
  155. {
  156. m_pCurrentItem = NULL;
  157. }
  158. // IComponent
  159. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  160. {
  161. if( event == MMCN_SHOW )
  162. {
  163. if( arg )
  164. {
  165. // Cache the currently selected node
  166. CSnapInItem* pItem;
  167. DATA_OBJECT_TYPES type;
  168. m_pComponentData->GetDataClass(lpDataObject, &pItem, &type);
  169. m_pCurrentItem = pItem;
  170. }
  171. else
  172. {
  173. m_pCurrentItem = NULL;
  174. }
  175. }
  176. if( event == MMCN_VIEW_CHANGE )
  177. {
  178. CSnapInItem* pItem;
  179. DATA_OBJECT_TYPES type;
  180. m_pComponentData->GetDataClass(lpDataObject, &pItem, &type);
  181. if( pItem != m_pCurrentItem )
  182. {
  183. // Only Change view of selected item
  184. return S_FALSE;
  185. }
  186. }
  187. if( event == MMCN_PROPERTY_CHANGE )
  188. {
  189. // On a property change (Server only) we need to update all views of the Server Node completely.
  190. CSnapInItem* pItem = (CSnapInItem*)param;
  191. HRESULT hr = pItem->Notify( MMCN_REFRESH, arg, param, m_pComponentData, NULL, CCT_SCOPE );
  192. if( SUCCEEDED(hr) )
  193. {
  194. // Get our Data Object
  195. CComPtr<IDataObject> spDataObject = NULL;
  196. pItem->GetDataObject(&spDataObject, CCT_SCOPE);
  197. if( !spDataObject ) return E_FAIL;
  198. // Call the Update, but don't update return result
  199. return m_spConsole->UpdateAllViews( spDataObject, 0, (LONG_PTR)NAV_ADD );
  200. }
  201. return hr;
  202. }
  203. if ( lpDataObject )
  204. {
  205. return IComponentImpl<CPOP3ServerSnapComponent>::Notify(lpDataObject, event, arg, param);
  206. }
  207. return E_NOTIMPL;
  208. }
  209. protected:
  210. CSnapInItem* m_pCurrentItem;
  211. };
  212. //////////////////////////////////////////////////////////////////////////////////////////////////////
  213. //
  214. // CPOP3ServerSnapAbout
  215. //
  216. /////////////////////////////////////////////////////////////////////////////////////////////////////
  217. class ATL_NO_VTABLE CPOP3ServerSnapAbout : public ISnapinAbout,
  218. public CComObjectRoot,
  219. public CComCoClass< CPOP3ServerSnapAbout, &CLSID_POP3ServerSnapAbout>
  220. {
  221. public:
  222. DECLARE_REGISTRY(CPOP3ServerSnapAbout, _T("POP3ServerSnapAbout.1"), _T("POP3ServerSnapAbout.1"), IDS_POP3SERVERSNAP_DESC, THREADFLAGS_BOTH);
  223. HICON m_hIcon;
  224. BEGIN_COM_MAP(CPOP3ServerSnapAbout)
  225. COM_INTERFACE_ENTRY(ISnapinAbout)
  226. END_COM_MAP()
  227. CPOP3ServerSnapAbout()
  228. {
  229. m_hIcon = NULL;
  230. }
  231. STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
  232. {
  233. if( !lpDescription ) return E_INVALIDARG;
  234. USES_CONVERSION;
  235. // Load the string
  236. tstring strDescription = StrLoadString( IDS_POP3SERVERSNAP_DESC );
  237. if( strDescription.empty() ) return E_FAIL;
  238. // Make a copy to return
  239. *lpDescription = (LPOLESTR)CoTaskMemAlloc( (strDescription.length() + 1) * sizeof(OLECHAR) );
  240. if( *lpDescription == NULL ) return E_OUTOFMEMORY;
  241. ocscpy( *lpDescription, T2OLE((LPTSTR)strDescription.c_str()) );
  242. return S_OK;
  243. }
  244. STDMETHOD(GetProvider)(LPOLESTR *lpName)
  245. {
  246. if( !lpName ) return E_INVALIDARG;
  247. USES_CONVERSION;
  248. // Load the string
  249. tstring strProvider = StrLoadString( IDS_POP3SERVERSNAP_PROVIDER );
  250. if( strProvider.empty() ) return E_FAIL;
  251. // Make a copy to return
  252. *lpName = (LPOLESTR)CoTaskMemAlloc( (strProvider.length() + 1) * sizeof(OLECHAR) );
  253. if ( *lpName == NULL ) return E_OUTOFMEMORY;
  254. ocscpy( *lpName, T2OLE((LPTSTR)strProvider.c_str()) );
  255. return S_OK;
  256. }
  257. STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
  258. {
  259. if( !lpVersion ) return E_INVALIDARG;
  260. USES_CONVERSION;
  261. TCHAR szBuf[MAX_PATH+1] = {0};
  262. DWORD dwLen = GetModuleFileName( _Module.GetModuleInstance(), szBuf, MAX_PATH );
  263. if( dwLen < MAX_PATH )
  264. {
  265. LPDWORD pTranslation = NULL;
  266. UINT uNumTranslation = 0;
  267. DWORD dwHandle = NULL;
  268. DWORD dwSize = GetFileVersionInfoSize(szBuf, &dwHandle);
  269. if( !dwSize ) return E_FAIL;
  270. BYTE* pVersionInfo = new BYTE[dwSize];
  271. if( !pVersionInfo ) return E_OUTOFMEMORY;
  272. if (!GetFileVersionInfo( szBuf, dwHandle, dwSize, pVersionInfo ) ||
  273. !VerQueryValue( (const LPVOID)pVersionInfo, _T("\\VarFileInfo\\Translation"), (LPVOID*)&pTranslation, &uNumTranslation ) ||
  274. !pTranslation )
  275. {
  276. delete [] pVersionInfo;
  277. pVersionInfo = NULL;
  278. pTranslation = NULL;
  279. uNumTranslation = 0;
  280. return E_FAIL;
  281. }
  282. uNumTranslation /= sizeof(DWORD);
  283. tstring strQuery = _T("\\StringFileInfo\\");
  284. // 8 characters for the language/char-set,
  285. // 1 for the slash,
  286. // 1 for terminating NULL
  287. TCHAR szTranslation[128] = {0};
  288. _sntprintf( szTranslation, 127, _T("%04x%04x\\"), LOWORD(*pTranslation), HIWORD(*pTranslation));
  289. strQuery += szTranslation;
  290. strQuery += _T("FileVersion");
  291. LPBYTE lpVerValue = NULL;
  292. UINT uSize = 0;
  293. if (!VerQueryValue(pVersionInfo, (LPTSTR)strQuery.c_str(), (LPVOID *)&lpVerValue, &uSize))
  294. {
  295. delete [] pVersionInfo;
  296. return E_FAIL;
  297. }
  298. // check the version
  299. _tcsncpy( szBuf, (LPTSTR)lpVerValue, MAX_PATH-1 );
  300. delete [] pVersionInfo;
  301. }
  302. *lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  303. if( *lpVersion == NULL ) return E_OUTOFMEMORY;
  304. ocscpy( *lpVersion, T2OLE(szBuf) );
  305. return S_OK;
  306. }
  307. STDMETHOD(GetSnapinImage)(HICON* phAppIcon)
  308. {
  309. if( !phAppIcon ) return E_INVALIDARG;
  310. if ( !m_hIcon )
  311. {
  312. m_hIcon = LoadIcon(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDI_Icon));
  313. }
  314. *phAppIcon = m_hIcon;
  315. return S_OK;
  316. }
  317. STDMETHOD(GetStaticFolderImage)(HBITMAP* phSmallImage,
  318. HBITMAP* phSmallImageOpen,
  319. HBITMAP* phLargeImage,
  320. COLORREF* pcMask)
  321. {
  322. if( !phSmallImage || !phSmallImageOpen || !phLargeImage || !pcMask ) return E_INVALIDARG;
  323. *phSmallImage = LoadBitmap( _Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_RootSmall) );
  324. *phSmallImageOpen = LoadBitmap( _Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_RootSmall) );
  325. *phLargeImage = LoadBitmap( _Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_RootLarge) );
  326. *pcMask = RGB(255,0,255);
  327. return S_OK;
  328. }
  329. };
  330. // Extra helper functions
  331. HRESULT GetConsole( CSnapInObjectRootBase *pObj, IConsole** pConsole );
  332. #endif