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.

1881 lines
47 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : FaxServerNode.cpp //
  3. // //
  4. // DESCRIPTION : Fax Server MMC node creation. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Sep 22 1999 yossg Init . //
  10. // Nov 24 1999 yossg Rename file from FaxCfg //
  11. // Dec 9 1999 yossg Call InitDisplayName from parent //
  12. // Feb 7 2000 yossg Add Call to CreateSecurityPage //
  13. // Mar 16 2000 yossg Add service start-stop //
  14. // Jun 25 2000 yossg Add stream and command line primary snapin //
  15. // machine targeting. //
  16. // Oct 17 2000 yossg //
  17. // Dec 10 2000 yossg Update Windows XP //
  18. // //
  19. // Copyright (C) 1999 - 2000 Microsoft Corporation All Rights Reserved //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "StdAfx.h"
  22. #include "FaxServerNode.h"
  23. //
  24. //Child Nodes H files
  25. //
  26. #include "DevicesAndProviders.h"
  27. #include "OutboundRouting.h"
  28. #include "InboundRouting.h"
  29. #include "CoverPages.h"
  30. #include "SecurityInfo.h" //which includes also <aclui.h>
  31. #include "WzConnectToServer.h"
  32. #include <faxreg.h>
  33. #include "Icons.h"
  34. #include "oaidl.h"
  35. //
  36. //CFaxServerNode Class
  37. //
  38. /////////////////////////////////////////////////////////////////////////////
  39. // {7A4A6347-A42A-4d36-8538-6634CD3C3B15}
  40. static const GUID CFaxServerNodeGUID_NODETYPE =
  41. { 0x7a4a6347, 0xa42a, 0x4d36, { 0x85, 0x38, 0x66, 0x34, 0xcd, 0x3c, 0x3b, 0x15 } };
  42. const GUID* CFaxServerNode::m_NODETYPE = &CFaxServerNodeGUID_NODETYPE;
  43. const OLECHAR* CFaxServerNode::m_SZNODETYPE = OLESTR("7A4A6347-A42A-4d36-8538-6634CD3C3B15");
  44. const CLSID* CFaxServerNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  45. CColumnsInfo CFaxServerNode::m_ColsInfo;
  46. /*
  47. - CFaxServerNode::InsertColumns
  48. -
  49. * Purpose:
  50. * Adds columns to the default result pane.
  51. *
  52. * Arguments:
  53. * [in] pHeaderCtrl - IHeaderCtrl in the console-provided default result view pane
  54. *
  55. * Return:
  56. * OLE error code
  57. */
  58. HRESULT
  59. CFaxServerNode::InsertColumns(IHeaderCtrl *pHeaderCtrl)
  60. {
  61. HRESULT hRc;
  62. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::InsertColumns"));
  63. static ColumnsInfoInitData ColumnsInitData[] =
  64. {
  65. {IDS_FAX_COL_HEAD, FXS_LARGE_COLUMN_WIDTH},
  66. {LAST_IDS, 0}
  67. };
  68. hRc = m_ColsInfo.InsertColumnsIntoMMC(pHeaderCtrl,
  69. _Module.GetResourceInstance(),
  70. ColumnsInitData);
  71. if (hRc != S_OK)
  72. {
  73. DebugPrintEx(
  74. DEBUG_ERR,
  75. _T("Failed to InsertColumnsIntoMMC. hRc: %08X "),
  76. hRc);
  77. goto Cleanup;
  78. }
  79. Cleanup:
  80. return(hRc);
  81. }
  82. /*
  83. - CFaxServerNode::PopulateScopeChildrenList
  84. -
  85. * Purpose:
  86. * Create all the Fax nodes
  87. *
  88. * Arguments:
  89. *
  90. * Return:
  91. * OLE error code
  92. */
  93. HRESULT CFaxServerNode::PopulateScopeChildrenList()
  94. {
  95. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::PopulateScopeChildrenList"));
  96. HRESULT hRc = S_OK;
  97. CFaxDevicesAndProvidersNode * pDevicesAndProviders = NULL;
  98. CFaxInboundRoutingNode * pIn = NULL;
  99. CFaxOutboundRoutingNode * pOut = NULL;
  100. CFaxCoverPagesNode * pCoverPages = NULL;
  101. CFaxServer * pFaxServer = NULL;
  102. //
  103. // Prepare IConsoleNameSpace for case of failure
  104. //
  105. ATLASSERT(m_pComponentData);
  106. ATLASSERT( ((CSnapin*)m_pComponentData)->m_spConsole );
  107. CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace( ((CSnapin*)m_pComponentData)->m_spConsole );
  108. ATLASSERT( spConsoleNameSpace );
  109. HRESULT hr = S_OK;
  110. if (m_IsPrimaryModeSnapin)
  111. {
  112. if (m_IsLaunchedFromSavedMscFile)
  113. {
  114. hRc = ForceRedrawNode();
  115. if ( S_OK != hRc )
  116. {
  117. //msgbox and dbgerr by called func.
  118. return hRc;
  119. }
  120. }
  121. }
  122. //
  123. // Preliminary connection-test
  124. //
  125. pFaxServer = GetFaxServer();
  126. ATLASSERT(pFaxServer);
  127. if (!pFaxServer->GetFaxServerHandle())
  128. {
  129. DWORD ec= GetLastError();
  130. DebugPrintEx(DEBUG_ERR, _T("Failed to check connection to server. (ec: %ld)"), ec);
  131. pFaxServer->Disconnect();
  132. if(pFaxServer->GetServerAPIVersion() > CURRENT_FAX_API_VERSION)
  133. {
  134. //
  135. // Cannot manage later version of fax
  136. //
  137. NodeMsgBox(IDS_ERR_API_NEW_VERSION, MB_OK | MB_ICONSTOP);
  138. hRc = HRESULT_FROM_WIN32(ERROR_RMODE_APP);
  139. }
  140. else if(pFaxServer->IsDesktopSKUConnection())
  141. {
  142. //
  143. // Cannot manage WinXP desktop SKU fax
  144. //
  145. NodeMsgBox(IDS_ERR_DESKTOP_SKU_CONNECTION, MB_OK | MB_ICONSTOP);
  146. hRc = HRESULT_FROM_WIN32(ERROR_RMODE_APP);
  147. }
  148. else
  149. {
  150. NodeMsgBox(IDS_NETWORK_PROBLEMS, MB_OK | MB_ICONSTOP);
  151. hRc = HRESULT_FROM_WIN32(ec);
  152. }
  153. return hRc;
  154. }
  155. //
  156. //Devices And Providers
  157. //
  158. pDevicesAndProviders = new CFaxDevicesAndProvidersNode(this, m_pComponentData);
  159. if (!pDevicesAndProviders)
  160. {
  161. hRc = E_OUTOFMEMORY;
  162. NodeMsgBox(IDS_MEMORY);
  163. DebugPrintEx(
  164. DEBUG_ERR,
  165. TEXT("Out of memory"));
  166. goto Error;
  167. }
  168. else
  169. {
  170. pDevicesAndProviders->InitParentNode(this);
  171. hRc = pDevicesAndProviders->InitDisplayName();
  172. if ( FAILED(hRc) )
  173. {
  174. DebugPrintEx(DEBUG_ERR,_T("Failed to display node name. (hRc: %08X)"), hRc);
  175. NodeMsgBox(IDS_FAILTOADD_AllDEVICES);
  176. goto Error;
  177. }
  178. pDevicesAndProviders->SetIcons(IMAGE_FOLDER_CLOSE, IMAGE_FOLDER_OPEN);
  179. hRc = AddChild(pDevicesAndProviders, &pDevicesAndProviders->m_scopeDataItem);
  180. if (FAILED(hRc))
  181. {
  182. DebugPrintEx(
  183. DEBUG_ERR,
  184. TEXT("Fail to add devices and providers node. (hRc: %08X)"),
  185. hRc);
  186. NodeMsgBox(IDS_FAILTOADD_AllDEVICES);
  187. goto Error;
  188. }
  189. }
  190. //
  191. // Fax Inbound Routing
  192. //
  193. pIn = new CFaxInboundRoutingNode(this, m_pComponentData);
  194. if (!pIn)
  195. {
  196. hRc = E_OUTOFMEMORY;
  197. NodeMsgBox(IDS_MEMORY);
  198. DebugPrintEx(
  199. DEBUG_ERR,
  200. TEXT("Out of memory"));
  201. goto Error;
  202. }
  203. else
  204. {
  205. pIn->InitParentNode(this);
  206. pIn->SetIcons(IMAGE_FOLDER_CLOSE, IMAGE_FOLDER_OPEN);
  207. hRc = pIn->InitDisplayName();
  208. if ( FAILED(hRc) )
  209. {
  210. DebugPrintEx(DEBUG_ERR,_T("Failed to display node name. (hRc: %08X)"), hRc);
  211. NodeMsgBox(IDS_FAILTOADD_INBOUNDROUTING);
  212. goto Error;
  213. }
  214. hRc = AddChild(pIn, &pIn->m_scopeDataItem);
  215. if (FAILED(hRc))
  216. {
  217. DebugPrintEx(
  218. DEBUG_ERR,
  219. TEXT("Fail to add inbound routing node. (hRc: %08X)"),
  220. hRc);
  221. NodeMsgBox(IDS_FAILTOADD_INBOUNDROUTING);
  222. goto Error;
  223. }
  224. }
  225. //
  226. // Fax Outbound Routing
  227. //
  228. pOut = new CFaxOutboundRoutingNode(this, m_pComponentData);
  229. if (!pOut)
  230. {
  231. hRc = E_OUTOFMEMORY;
  232. NodeMsgBox(IDS_MEMORY);
  233. DebugPrintEx(
  234. DEBUG_ERR,
  235. TEXT("Out of memory"));
  236. goto Error;
  237. }
  238. else
  239. {
  240. pOut->InitParentNode(this);
  241. pOut->SetIcons(IMAGE_FOLDER_CLOSE, IMAGE_FOLDER_OPEN);
  242. hRc = pOut->InitDisplayName();
  243. if ( FAILED(hRc) )
  244. {
  245. DebugPrintEx(DEBUG_ERR,_T("Failed to display node name. (hRc: %08X)"), hRc);
  246. NodeMsgBox(IDS_FAILTOADD_OUTBOUNDROUTING);
  247. goto Error;
  248. }
  249. hRc = AddChild(pOut, &pOut->m_scopeDataItem);
  250. if (FAILED(hRc))
  251. {
  252. DebugPrintEx(
  253. DEBUG_ERR,
  254. TEXT("Fail to add outbound routing node. (hRc: %08X)"),
  255. hRc);
  256. NodeMsgBox(IDS_FAILTOADD_OUTBOUNDROUTING);
  257. goto Error;
  258. }
  259. }
  260. //
  261. // CoverPages
  262. //
  263. pCoverPages = new CFaxCoverPagesNode(this, m_pComponentData);
  264. if (!pCoverPages)
  265. {
  266. hRc = E_OUTOFMEMORY;
  267. NodeMsgBox(IDS_MEMORY);
  268. DebugPrintEx(
  269. DEBUG_ERR,
  270. TEXT("Out of memory"));
  271. goto Error;
  272. }
  273. else
  274. {
  275. pCoverPages->InitParentNode(this);
  276. hRc = pCoverPages->Init();
  277. if ( FAILED(hRc) )
  278. {
  279. if(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hRc)
  280. {
  281. DebugPrintEx(
  282. DEBUG_ERR, //Dbg Warning only !!!
  283. _T("Cover pages folder was not found. (hRc: %08X)"), hRc);
  284. NodeMsgBox(IDS_COVERPAGES_PATH_NOT_FOUND);
  285. }
  286. else
  287. {
  288. DebugPrintEx(DEBUG_ERR,_T("Failed to Init cover pages class. (hRc: %08X)"), hRc);
  289. NodeMsgBox(IDS_FAILTOADD_COVERPAGES);
  290. }
  291. goto Error;
  292. }
  293. hRc = pCoverPages->InitDisplayName();
  294. if ( FAILED(hRc) )
  295. {
  296. DebugPrintEx(DEBUG_ERR,_T("Failed to display node name. (hRc: %08X)"), hRc);
  297. NodeMsgBox(IDS_FAILTOADD_COVERPAGES);
  298. goto Error;
  299. }
  300. pCoverPages->SetIcons(IMAGE_FAX_COVERPAGES, IMAGE_FAX_COVERPAGES);
  301. hRc = AddChild(pCoverPages, &pCoverPages->m_scopeDataItem);
  302. if (FAILED(hRc))
  303. {
  304. DebugPrintEx(
  305. DEBUG_ERR,
  306. TEXT("Fail to add reports node. (hRc: %08X)"),
  307. hRc);
  308. NodeMsgBox(IDS_FAILTOADD_COVERPAGES);
  309. goto Error;
  310. }
  311. }
  312. ATLASSERT(S_OK == hRc);
  313. goto Exit;
  314. Error:
  315. ATLASSERT(S_OK != hRc);
  316. if ( NULL != pDevicesAndProviders )
  317. {
  318. if (0 != pDevicesAndProviders->m_scopeDataItem.ID )
  319. {
  320. hr = spConsoleNameSpace->DeleteItem(pDevicesAndProviders->m_scopeDataItem.ID, TRUE);
  321. if (hr != S_OK) // can be only E_UNEXPECTED [MSDN]
  322. {
  323. DebugPrintEx(
  324. DEBUG_ERR,
  325. TEXT("spConsoleNameSpace->DeleteItem() Failed - Unexpected error. (hRc: %08X)"),
  326. hr);
  327. ATLASSERT(FALSE);
  328. }
  329. }
  330. delete pDevicesAndProviders;
  331. pDevicesAndProviders = NULL;
  332. }
  333. if ( NULL != pIn )
  334. {
  335. if (0 != pIn->m_scopeDataItem.ID )
  336. {
  337. hr = spConsoleNameSpace->DeleteItem(pIn->m_scopeDataItem.ID, TRUE);
  338. if (hr != S_OK) // can be only E_UNEXPECTED [MSDN]
  339. {
  340. DebugPrintEx(
  341. DEBUG_ERR,
  342. TEXT("spConsoleNameSpace->DeleteItem() Failed - Unexpected error. (hRc: %08X)"),
  343. hr);
  344. ATLASSERT(FALSE);
  345. }
  346. }
  347. delete pIn;
  348. pIn = NULL;
  349. }
  350. if ( NULL != pOut )
  351. {
  352. if (0 != pOut->m_scopeDataItem.ID )
  353. {
  354. hr = spConsoleNameSpace->DeleteItem(pOut->m_scopeDataItem.ID, TRUE);
  355. if (hr != S_OK) // can be only E_UNEXPECTED [MSDN]
  356. {
  357. DebugPrintEx(
  358. DEBUG_ERR,
  359. TEXT("spConsoleNameSpace->DeleteItem() Failed - Unexpected error. (hRc: %08X)"),
  360. hr);
  361. ATLASSERT(FALSE);
  362. }
  363. }
  364. delete pOut;
  365. pOut = NULL;
  366. }
  367. if ( NULL != pCoverPages )
  368. {
  369. if (0 != pCoverPages->m_scopeDataItem.ID )
  370. {
  371. hr = spConsoleNameSpace->DeleteItem(pCoverPages->m_scopeDataItem.ID, TRUE);
  372. if (hr != S_OK) // can be only E_UNEXPECTED [MSDN]
  373. {
  374. DebugPrintEx(
  375. DEBUG_ERR,
  376. TEXT("spConsoleNameSpace->DeleteItem() Failed - Unexpected error. (hRc: %08X)"),
  377. hr);
  378. ATLASSERT(FALSE);
  379. }
  380. }
  381. delete pCoverPages;
  382. pCoverPages = NULL;
  383. }
  384. // Empty the list
  385. m_ScopeChildrenList.RemoveAll();
  386. m_bScopeChildrenListPopulated = FALSE;
  387. Exit:
  388. return hRc;
  389. }
  390. /*
  391. - CFaxServerNode::CreatePropertyPages
  392. -
  393. * Purpose:
  394. * Called when creating a property page of the object
  395. *
  396. * Arguments:
  397. * [in] lpProvider - The property sheet
  398. * [in] handle - Handle for routing notification
  399. * [in] pUnk - Pointer to the data object
  400. * [in] type - CCT_* (SCOPE, RESULT, ...)
  401. *
  402. * Return:
  403. * OLE error code
  404. * Out of memory error or last error occured
  405. */
  406. HRESULT
  407. CFaxServerNode::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  408. LONG_PTR handle,
  409. IUnknown *pUnk,
  410. DATA_OBJECT_TYPES type)
  411. {
  412. HRESULT hRc = S_OK;
  413. DWORD ec = ERROR_SUCCESS;
  414. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::CreatePropertyPages"));
  415. ATLASSERT(lpProvider);
  416. if( type == CCT_SNAPIN_MANAGER ) //invokes wizard
  417. {
  418. return CreateSnapinManagerPages(lpProvider, handle);
  419. }
  420. ATLASSERT(type == CCT_RESULT || type == CCT_SCOPE);
  421. m_pFaxServerGeneral = NULL;
  422. m_pFaxServerEmail = NULL;
  423. m_pFaxServerEvents = NULL;
  424. m_pFaxServerLogging = NULL;
  425. m_pFaxServerOutbox = NULL;
  426. m_pFaxServerInbox = NULL;
  427. m_pFaxServerSentItems = NULL;
  428. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  429. CFaxSecurityInformation * pSecurityInfo = NULL;
  430. CFaxServer * pFaxServer = NULL;
  431. HPROPSHEETPAGE hPage;
  432. BOOL fIsLocalServer = TRUE;
  433. //
  434. // Preliminary Access Check
  435. //
  436. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  437. ATLASSERT(pFaxServer);
  438. if (!pFaxServer->GetFaxServerHandle())
  439. {
  440. ec= GetLastError();
  441. DebugPrintEx(
  442. DEBUG_ERR,
  443. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  444. ec);
  445. NodeMsgBox(GetFaxServerErrorMsg(ec));
  446. hRc = HRESULT_FROM_WIN32(ec);
  447. goto Error;
  448. }
  449. if (!FaxAccessCheckEx(pFaxServer->GetFaxServerHandle(),
  450. FAX_ACCESS_QUERY_CONFIG,
  451. NULL))
  452. {
  453. ec = GetLastError();
  454. if (ERROR_SUCCESS == ec)
  455. {
  456. DebugPrintEx(
  457. DEBUG_MSG,
  458. _T("FaxAccessCheckEx returns ACCESS DENIED for FAX_ACCESS_QUERY_CONFIG."));
  459. goto Security;
  460. }
  461. else
  462. {
  463. DebugPrintEx(
  464. DEBUG_ERR,
  465. _T("Fail check access for FAX_ACCESS_QUERY_CONFIG."));
  466. NodeMsgBox(GetFaxServerErrorMsg(ec));
  467. hRc = HRESULT_FROM_WIN32(ec);
  468. goto Error;
  469. }
  470. }
  471. if ( 0 != (pFaxServer->GetServerName()).Length() )
  472. {
  473. fIsLocalServer = FALSE;
  474. }
  475. //
  476. // General
  477. //
  478. m_pFaxServerGeneral = new CppFaxServerGeneral(
  479. handle,
  480. this,
  481. TRUE,
  482. _Module.GetResourceInstance());
  483. if (!m_pFaxServerGeneral)
  484. {
  485. hRc = E_OUTOFMEMORY;
  486. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  487. goto Error;
  488. }
  489. hRc = m_pFaxServerGeneral->InitRPC();
  490. if (FAILED(hRc))
  491. {
  492. DebugPrintEx(
  493. DEBUG_ERR,
  494. TEXT("Fail to call RPC to init property page for General Tab. (hRc: %08X)"),
  495. hRc);
  496. goto Error;
  497. }
  498. hPage = NULL;
  499. hPage = m_pFaxServerGeneral->Create();
  500. if ((!hPage))
  501. {
  502. hRc = HRESULT_FROM_WIN32(GetLastError());
  503. DebugPrintEx(
  504. DEBUG_ERR,
  505. TEXT("Fail to Create() property page. (hRc: %08X)"),
  506. hRc);
  507. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  508. goto Error;
  509. }
  510. hRc = lpProvider->AddPage(hPage);
  511. if (FAILED(hRc))
  512. {
  513. DebugPrintEx(
  514. DEBUG_ERR,
  515. TEXT("Fail to add property page for General Tab. (hRc: %08X)"),
  516. hRc);
  517. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  518. goto Error;
  519. }
  520. //
  521. // Receipts - Notification delivery
  522. //
  523. m_pFaxServerEmail = new CppFaxServerReceipts(
  524. handle,
  525. this,
  526. TRUE,
  527. _Module.GetResourceInstance());
  528. if (!m_pFaxServerEmail)
  529. {
  530. hRc = E_OUTOFMEMORY;
  531. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  532. goto Error;
  533. }
  534. hRc = m_pFaxServerEmail->InitRPC();
  535. if (FAILED(hRc))
  536. {
  537. DebugPrintEx(
  538. DEBUG_ERR,
  539. TEXT("Fail to call RPC to init property page for mail Tab.(hRc: %08X)"),
  540. hRc);
  541. goto Error;
  542. }
  543. hPage = NULL;
  544. hPage = m_pFaxServerEmail->Create();
  545. if ((!hPage))
  546. {
  547. hRc = HRESULT_FROM_WIN32(GetLastError());
  548. DebugPrintEx(
  549. DEBUG_ERR,
  550. TEXT("Fail to Create() property page. (hRc: %08X)"),
  551. hRc);
  552. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  553. goto Error;
  554. }
  555. hRc = lpProvider->AddPage(hPage);
  556. if (FAILED(hRc))
  557. {
  558. DebugPrintEx(
  559. DEBUG_ERR,
  560. TEXT("Fail to add property page for Email Tab.(hRc: %08X)"),
  561. hRc);
  562. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  563. goto Error;
  564. }
  565. //
  566. // Event Reports ("Logging Categories")
  567. //
  568. m_pFaxServerEvents = new CppFaxServerEvents(
  569. handle,
  570. this,
  571. TRUE,
  572. _Module.GetResourceInstance());
  573. if (!m_pFaxServerEvents)
  574. {
  575. hRc = E_OUTOFMEMORY;
  576. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  577. goto Error;
  578. }
  579. hRc = m_pFaxServerEvents->InitRPC();
  580. if (FAILED(hRc))
  581. {
  582. DebugPrintEx(
  583. DEBUG_ERR,
  584. TEXT("Fail to call RPC to init property page for event reports Tab. (hRc: %08X)"),
  585. hRc);
  586. goto Error;
  587. }
  588. hPage = NULL;
  589. hPage = m_pFaxServerEvents->Create();
  590. if ((!hPage))
  591. {
  592. hRc = HRESULT_FROM_WIN32(GetLastError());
  593. DebugPrintEx(
  594. DEBUG_ERR,
  595. TEXT("Fail to Create() property page. (hRc: %08X)"),
  596. hRc);
  597. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  598. goto Error;
  599. }
  600. hRc = lpProvider->AddPage(hPage);
  601. if (FAILED(hRc))
  602. {
  603. DebugPrintEx(
  604. DEBUG_ERR,
  605. TEXT("Fail to add property page for Events Tab.(hRc: %08X)"),
  606. hRc);
  607. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  608. goto Error;
  609. }
  610. //
  611. // Logging
  612. //
  613. m_pFaxServerLogging = new CppFaxServerLogging(
  614. handle,
  615. this,
  616. fIsLocalServer,
  617. _Module.GetResourceInstance());
  618. if (!m_pFaxServerLogging)
  619. {
  620. hRc = E_OUTOFMEMORY;
  621. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  622. goto Error;
  623. }
  624. hRc = m_pFaxServerLogging->InitRPC();
  625. if (FAILED(hRc))
  626. {
  627. DebugPrintEx(
  628. DEBUG_ERR,
  629. TEXT("Fail to call RPC to init property page for Logging tab.(hRc: %08X)"),
  630. hRc);
  631. goto Error;
  632. }
  633. hPage = NULL;
  634. hPage = m_pFaxServerLogging->Create();
  635. if ((!hPage))
  636. {
  637. hRc = HRESULT_FROM_WIN32(GetLastError());
  638. DebugPrintEx(
  639. DEBUG_ERR,
  640. TEXT("Fail to Create() property page. (hRc: %08X)"),
  641. hRc);
  642. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  643. goto Error;
  644. }
  645. hRc = lpProvider->AddPage(hPage);
  646. if (FAILED(hRc))
  647. {
  648. DebugPrintEx(
  649. DEBUG_ERR,
  650. TEXT("Fail to add property page for Logging Tab.(hRc: %08X)"),
  651. hRc);
  652. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  653. goto Error;
  654. }
  655. //
  656. // Outbox
  657. //
  658. m_pFaxServerOutbox = new CppFaxServerOutbox(
  659. handle,
  660. this,
  661. TRUE,
  662. _Module.GetResourceInstance());
  663. if (!m_pFaxServerOutbox)
  664. {
  665. hRc= E_OUTOFMEMORY;
  666. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  667. goto Error;
  668. }
  669. hRc = m_pFaxServerOutbox->InitRPC();
  670. if (FAILED(hRc))
  671. {
  672. DebugPrintEx(
  673. DEBUG_ERR,
  674. TEXT("Fail to call RPC to init property page for Outbox tab. (hRc: %08X)"),
  675. hRc);
  676. goto Error;
  677. }
  678. hPage = NULL;
  679. hPage = m_pFaxServerOutbox->Create();
  680. if ((!hPage))
  681. {
  682. hRc = HRESULT_FROM_WIN32(GetLastError());
  683. DebugPrintEx(
  684. DEBUG_ERR,
  685. TEXT("Fail to Create() property page. (hRc: %08X)"),
  686. hRc);
  687. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  688. goto Error;
  689. }
  690. hRc = lpProvider->AddPage(hPage);
  691. if (FAILED(hRc))
  692. {
  693. DebugPrintEx(
  694. DEBUG_ERR,
  695. TEXT("Fail to add property page for Outbox Tab.(hRc: %08X)"),
  696. hRc);
  697. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  698. goto Error;
  699. }
  700. //
  701. // Inbox Archive
  702. //
  703. m_pFaxServerInbox = new CppFaxServerInbox(
  704. handle,
  705. this,
  706. fIsLocalServer,
  707. _Module.GetResourceInstance());
  708. if (!m_pFaxServerInbox)
  709. {
  710. hRc = E_OUTOFMEMORY;
  711. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  712. goto Error;
  713. }
  714. hRc = m_pFaxServerInbox->InitRPC();
  715. if (FAILED(hRc))
  716. {
  717. DebugPrintEx(
  718. DEBUG_ERR,
  719. TEXT("Fail to call RPC to init property page for Inbox Tab.(hRc: %08X)"),
  720. hRc);
  721. goto Error;
  722. }
  723. hPage = NULL;
  724. hPage = m_pFaxServerInbox->Create();
  725. if ((!hPage))
  726. {
  727. hRc = HRESULT_FROM_WIN32(GetLastError());
  728. DebugPrintEx(
  729. DEBUG_ERR,
  730. TEXT("Fail to Create() property page. (hRc: %08X)"),
  731. hRc);
  732. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  733. goto Error;
  734. }
  735. hRc = lpProvider->AddPage(hPage);
  736. if (FAILED(hRc))
  737. {
  738. DebugPrintEx(
  739. DEBUG_ERR,
  740. TEXT("Fail to add property page for Inbox Tab. (hRc: %08X)"),
  741. hRc);
  742. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  743. goto Error;
  744. }
  745. //
  746. // Sent Items Archive
  747. //
  748. m_pFaxServerSentItems = new CppFaxServerSentItems(
  749. handle,
  750. this,
  751. fIsLocalServer,
  752. _Module.GetResourceInstance());
  753. if (!m_pFaxServerSentItems)
  754. {
  755. hRc = E_OUTOFMEMORY;
  756. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  757. goto Error;
  758. }
  759. hRc = m_pFaxServerSentItems->InitRPC();
  760. if (FAILED(hRc))
  761. {
  762. DebugPrintEx(
  763. DEBUG_ERR,
  764. TEXT("Fail to call RPC to init property page for Sent items tab. (hRc: %08X)"),
  765. hRc);
  766. goto Error;
  767. }
  768. hPage = NULL;
  769. hPage = m_pFaxServerSentItems->Create();
  770. if ((!hPage))
  771. {
  772. hRc = HRESULT_FROM_WIN32(GetLastError());
  773. DebugPrintEx(
  774. DEBUG_ERR,
  775. TEXT("Fail to Create() property page. (hRc: %08X)"),
  776. hRc);
  777. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  778. goto Error;
  779. }
  780. hRc = lpProvider->AddPage(hPage);
  781. if (FAILED(hRc))
  782. {
  783. DebugPrintEx(
  784. DEBUG_ERR,
  785. TEXT("Fail to add property page for SentItems Tab. (hRc: %08X)"),
  786. hRc);
  787. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  788. goto Error;
  789. }
  790. Security: //Must be last tab!!!
  791. //
  792. // Security
  793. //
  794. pSecurityInfo = new CComObject<CFaxSecurityInformation>;
  795. if (!pSecurityInfo)
  796. {
  797. hRc = E_OUTOFMEMORY;
  798. goto Error;
  799. }
  800. pSecurityInfo->Init(this);
  801. hPage = NULL;
  802. hPage = CreateSecurityPage( pSecurityInfo );
  803. if ((!hPage))
  804. {
  805. hRc = HRESULT_FROM_WIN32(GetLastError());
  806. DebugPrintEx(
  807. DEBUG_ERR,
  808. TEXT("Fail to Create() property page. (hRc: %08X)"),
  809. hRc);
  810. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  811. goto Error;
  812. }
  813. hRc = lpProvider->AddPage( hPage );
  814. if (FAILED(hRc))
  815. {
  816. DebugPrintEx(
  817. DEBUG_ERR,
  818. TEXT("Fail to add property page for Inbox Tab. (hRc: %08X)"),
  819. hRc);
  820. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  821. goto Error;
  822. }
  823. ATLASSERT(S_OK == hRc);
  824. goto Exit;
  825. Error:
  826. ATLASSERT(S_OK != hRc);
  827. if ( NULL != m_pFaxServerGeneral )
  828. {
  829. delete m_pFaxServerGeneral;
  830. m_pFaxServerGeneral = NULL;
  831. }
  832. if ( NULL != m_pFaxServerEmail )
  833. {
  834. delete m_pFaxServerEmail;
  835. m_pFaxServerEmail = NULL;
  836. }
  837. if ( NULL != m_pFaxServerEvents )
  838. {
  839. delete m_pFaxServerEvents;
  840. m_pFaxServerEvents = NULL;
  841. }
  842. if ( NULL != m_pFaxServerLogging )
  843. {
  844. delete m_pFaxServerLogging;
  845. m_pFaxServerLogging = NULL;
  846. }
  847. if ( NULL != m_pFaxServerOutbox )
  848. {
  849. delete m_pFaxServerOutbox;
  850. m_pFaxServerOutbox = NULL;
  851. }
  852. if ( NULL != m_pFaxServerInbox )
  853. {
  854. delete m_pFaxServerInbox;
  855. m_pFaxServerInbox = NULL;
  856. }
  857. if ( NULL != m_pFaxServerSentItems )
  858. {
  859. delete m_pFaxServerSentItems;
  860. m_pFaxServerSentItems = NULL;
  861. }
  862. if ( NULL != pSecurityInfo )
  863. {
  864. delete pSecurityInfo;
  865. pSecurityInfo = NULL;
  866. }
  867. Exit:
  868. if (NULL != pSecurityDescriptor )
  869. {
  870. FaxFreeBuffer( (PVOID)pSecurityDescriptor );
  871. }
  872. return hRc;
  873. }
  874. /*
  875. - CFaxServerNode::CreateSnapinManagerPages
  876. -
  877. * Purpose:
  878. * Called to create wizard by snapin manager
  879. * CreatePropertyPages with ( type == CCT_SNAPIN_MANAGER )
  880. *
  881. *
  882. * Arguments:
  883. * [in] lpProvider - The property sheet
  884. * [in] handle - Handle for routing notification
  885. *
  886. * Return:
  887. * OLE error code
  888. */
  889. HRESULT CFaxServerNode::CreateSnapinManagerPages(
  890. LPPROPERTYSHEETCALLBACK lpProvider,
  891. LONG_PTR handle)
  892. {
  893. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::CreateSnapinManagerPages"));
  894. // This page will take care of deleting itself when it
  895. // receives the PSPCB_RELEASE message.
  896. CWzConnectToServer * pWzPageConnect = new CWzConnectToServer(this);
  897. HPROPSHEETPAGE hPage = NULL;
  898. HRESULT hRc = S_OK;
  899. hPage = pWzPageConnect->Create();
  900. if ((!hPage))
  901. {
  902. hRc = HRESULT_FROM_WIN32(GetLastError());
  903. DebugPrintEx(
  904. DEBUG_ERR,
  905. TEXT("Fail to Create() property page. (hRc: %08X)"),
  906. hRc);
  907. PageErrorEx(IDS_FAX_CONNECT, IDS_FAIL_TO_OPEN_TARGETING_WIZARD, NULL);
  908. return hRc;
  909. }
  910. hRc = lpProvider->AddPage(hPage);
  911. if (FAILED(hRc))
  912. {
  913. DebugPrintEx(
  914. DEBUG_ERR,
  915. TEXT("Fail to add the connect to server property page to wizard. (hRc: %08X)"),
  916. hRc);
  917. PageErrorEx(IDS_FAX_CONNECT, IDS_FAIL_TO_OPEN_TARGETING_WIZARD, NULL);
  918. return hRc;
  919. }
  920. return hRc;
  921. }
  922. /*
  923. - CFaxServerNode::SetVerbs
  924. -
  925. * Purpose:
  926. * What verbs to enable/disable when this object is selected
  927. *
  928. * Arguments:
  929. * [in] pConsoleVerb - MMC ConsoleVerb interface
  930. *
  931. * Return:
  932. * OLE Error code
  933. */
  934. HRESULT CFaxServerNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  935. {
  936. HRESULT hr = S_OK;
  937. CFaxServer* pFaxServer = NULL;
  938. pFaxServer = GetFaxServer();
  939. ATLASSERT(pFaxServer);
  940. if(!pFaxServer->IsServerRunningFaxService())
  941. {
  942. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  943. return hr;
  944. }
  945. //
  946. // Init server API version information
  947. //
  948. pFaxServer->GetFaxServerHandle();
  949. if(pFaxServer->GetServerAPIVersion() > CURRENT_FAX_API_VERSION ||
  950. pFaxServer->IsDesktopSKUConnection())
  951. {
  952. //
  953. // Cannot manage later version of fax or WinXP desktop SKU fax
  954. //
  955. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  956. return hr;
  957. }
  958. //
  959. // Display verbs that we support:
  960. // 1. Properties
  961. //
  962. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  963. //
  964. // We want the default verb to be Properties
  965. //
  966. hr = pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  967. return hr;
  968. }
  969. /*
  970. - CFaxServerNode::OnRefresh
  971. -
  972. * Purpose:
  973. * Called when refreshing the object.
  974. *
  975. * Arguments:
  976. *
  977. * Return:
  978. * OLE error code
  979. */
  980. HRESULT
  981. CFaxServerNode::OnRefresh(LPARAM arg,
  982. LPARAM param,
  983. IComponentData *pComponentData,
  984. IComponent * pComponent,
  985. DATA_OBJECT_TYPES type)
  986. {
  987. return S_OK;
  988. }
  989. /*
  990. - CFaxServerNode::UpdateMenuState
  991. -
  992. * Purpose:
  993. * Overrides the ATL CSnapInItemImpl::UpdateMenuState
  994. * which only have one line inside it "return;"
  995. * This function implements the grayed\ungrayed view for the
  996. * the Enable and the Disable menus.
  997. *
  998. * Arguments:
  999. *
  1000. * [in] id - unsigned int with the menu IDM value
  1001. * [out] pBuf - string
  1002. * [out] flags - pointer to flags state combination unsigned int
  1003. *
  1004. * Return:
  1005. * no return value - void function
  1006. */
  1007. void CFaxServerNode::UpdateMenuState(UINT id, LPTSTR pBuf, UINT *flags)
  1008. {
  1009. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::UpdateMenuState"));
  1010. UNREFERENCED_PARAMETER (pBuf);
  1011. BOOL fIsRunning = FALSE;
  1012. ATLASSERT(GetFaxServer());
  1013. fIsRunning = GetFaxServer()->IsServerRunningFaxService();
  1014. switch (id)
  1015. {
  1016. case IDM_SRV_START:
  1017. *flags = (fIsRunning ? MF_GRAYED : MF_ENABLED );
  1018. break;
  1019. case IDM_SRV_STOP:
  1020. *flags = (!fIsRunning ? MF_GRAYED : MF_ENABLED );
  1021. break;
  1022. case IDM_LAUNCH_CONSOLE:
  1023. *flags = IsFaxComponentInstalled(FAX_COMPONENT_CONSOLE) ? MF_ENABLED : MF_GRAYED;
  1024. break;
  1025. default:
  1026. break;
  1027. }
  1028. return;
  1029. }
  1030. /*
  1031. - CFaxServerNode::UpdateToolbarButton
  1032. -
  1033. * Purpose:
  1034. * Overrides the ATL CSnapInItemImpl::UpdateToolbarButton
  1035. * This function aloow us to decide if to the activate\grayed a toolbar button
  1036. * It treating only the Enable state.
  1037. *
  1038. * Arguments:
  1039. *
  1040. * [in] id - unsigned int for the toolbar button ID
  1041. * [in] fsState - state to be cosidered ENABLE ?HIDDEN etc.
  1042. *
  1043. * Return:
  1044. * BOOL TRUE to activate state FALSE to disabled the state for this button
  1045. */
  1046. BOOL CFaxServerNode::UpdateToolbarButton(UINT id, BYTE fsState)
  1047. {
  1048. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::UpdateToolbarButton"));
  1049. BOOL bRet = FALSE;
  1050. BOOL fIsRunning = FALSE;
  1051. ATLASSERT(GetFaxServer());
  1052. fIsRunning = GetFaxServer()->IsServerRunningFaxService();
  1053. // Set whether the buttons should be enabled.
  1054. if (fsState == ENABLED)
  1055. {
  1056. switch ( id )
  1057. {
  1058. case ID_START_BUTTON:
  1059. bRet = ( fIsRunning ? FALSE : TRUE );
  1060. break;
  1061. case ID_STOP_BUTTON:
  1062. bRet = ( fIsRunning ? TRUE : FALSE );
  1063. break;
  1064. case ID_CLIENTCONSOLE_BUTTON:
  1065. bRet = IsFaxComponentInstalled(FAX_COMPONENT_CONSOLE);
  1066. break;
  1067. default:
  1068. break;
  1069. }
  1070. }
  1071. // For all other possible button ID's and states,
  1072. // the correct answer here is FALSE.
  1073. return bRet;
  1074. }
  1075. /*
  1076. - CFaxServerNode::OnServiceStartCommand
  1077. -
  1078. * Purpose:
  1079. * To start Fax Server Service
  1080. *
  1081. * Arguments:
  1082. *
  1083. * Return:
  1084. * OLE error code
  1085. */
  1086. HRESULT CFaxServerNode::OnServiceStartCommand(bool &bHandled, CSnapInObjectRootBase *pRoot)
  1087. {
  1088. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::OnServiceStartCommand"));
  1089. BOOL bRet = FALSE;
  1090. HRESULT hRc = S_OK;
  1091. SCOPEDATAITEM* pScopeData;
  1092. CComPtr<IConsole> spConsole;
  1093. //
  1094. // 0) Service status check
  1095. //
  1096. ATLASSERT(GetFaxServer());
  1097. if (GetFaxServer()->IsServerRunningFaxService())
  1098. {
  1099. DebugPrintEx(
  1100. DEBUG_MSG,
  1101. _T("Service is already running. (ec: %ld)"));
  1102. NodeMsgBox(IDS_SRV_ALREADY_START);
  1103. bRet = TRUE; //to allow toolbar refresh to correct state
  1104. }
  1105. else
  1106. {
  1107. //
  1108. // 1) Start the service
  1109. //
  1110. // ATLASSERT(GetFaxServer()); was called above
  1111. bRet = EnsureFaxServiceIsStarted (GetFaxServer()->GetServerName());
  1112. if (!bRet)
  1113. {
  1114. NodeMsgBox(IDS_FAIL2START_SRV);
  1115. }
  1116. }
  1117. //
  1118. // 2) Update the toolbar.
  1119. //
  1120. if (bRet)
  1121. {
  1122. //
  1123. // Get the updated SCOPEDATAITEM
  1124. //
  1125. hRc = GetScopeData( &pScopeData );
  1126. if (FAILED(hRc))
  1127. {
  1128. DebugPrintEx(
  1129. DEBUG_ERR,
  1130. TEXT("Fail to get pScopeData. (hRc: %08X)"),
  1131. hRc);
  1132. NodeMsgBox(IDS_FAIL2UPDATE_SRVSTATUS_TOOLBAR);
  1133. }
  1134. else
  1135. {
  1136. //
  1137. // This will force MMC to redraw the scope node
  1138. //
  1139. spConsole = m_pComponentData->m_spConsole;
  1140. ATLASSERT(spConsole);
  1141. hRc = spConsole->SelectScopeItem( pScopeData->ID );
  1142. if (FAILED(hRc))
  1143. {
  1144. DebugPrintEx(
  1145. DEBUG_ERR,
  1146. TEXT("Fail to select scope Item. (hRc: %08X)"),
  1147. hRc);
  1148. NodeMsgBox(IDS_FAIL2UPDATE_SRVSTATUS_TOOLBAR);
  1149. }
  1150. }
  1151. }
  1152. return (bRet ? S_OK : E_FAIL);
  1153. }
  1154. /*
  1155. - CFaxServerNode::OnServiceStopCommand
  1156. -
  1157. * Purpose:
  1158. * To stop Fax Server Service
  1159. *
  1160. * Arguments:
  1161. *
  1162. * Return:
  1163. * OLE error code
  1164. */
  1165. HRESULT CFaxServerNode::OnServiceStopCommand(bool &bHandled, CSnapInObjectRootBase *pRoot)
  1166. {
  1167. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::OnServiceStopCommand"));
  1168. BOOL bRet = FALSE;
  1169. HRESULT hRc = S_OK;
  1170. CFaxServer * pFaxServer = NULL;
  1171. //
  1172. // 0) Service status check
  1173. //
  1174. pFaxServer = GetFaxServer();
  1175. ATLASSERT(pFaxServer);
  1176. if (pFaxServer->IsServerFaxServiceStopped())
  1177. {
  1178. DebugPrintEx(
  1179. DEBUG_MSG,
  1180. _T("Do not have to stop - Fax server service is not started. (ec: %ld)"));
  1181. NodeMsgBox(IDS_SRV_ALREADY_STOP);
  1182. bRet = TRUE; //to allow toolbar refresh to correct state
  1183. }
  1184. else
  1185. {
  1186. //
  1187. // 1) Stop the service
  1188. //
  1189. bRet = StopService(pFaxServer->GetServerName(), FAX_SERVICE_NAME, TRUE);
  1190. if (!bRet)
  1191. {
  1192. NodeMsgBox(IDS_FAIL2STOP_SRV);
  1193. }
  1194. }
  1195. //
  1196. // 2) Update the toolbar.
  1197. //
  1198. if (bRet)
  1199. {
  1200. pFaxServer->Disconnect();
  1201. SCOPEDATAITEM* pScopeData;
  1202. CComPtr<IConsole> spConsole;
  1203. //
  1204. // Get the updated SCOPEDATAITEM
  1205. //
  1206. hRc = GetScopeData( &pScopeData );
  1207. if (FAILED(hRc))
  1208. {
  1209. DebugPrintEx(
  1210. DEBUG_ERR,
  1211. TEXT("Fail to get pScopeData. (hRc: %08X)"),
  1212. hRc);
  1213. NodeMsgBox(IDS_FAIL2UPDATE_SRVSTATUS_TOOLBAR);
  1214. }
  1215. else
  1216. {
  1217. //
  1218. // This will force MMC to redraw the scope node
  1219. //
  1220. spConsole = m_pComponentData->m_spConsole;
  1221. ATLASSERT(spConsole);
  1222. hRc = spConsole->SelectScopeItem( pScopeData->ID );
  1223. if (FAILED(hRc))
  1224. {
  1225. DebugPrintEx(
  1226. DEBUG_ERR,
  1227. TEXT("Fail to select scope Item. (hRc: %08X)"),
  1228. hRc);
  1229. NodeMsgBox(IDS_FAIL2UPDATE_SRVSTATUS_TOOLBAR);
  1230. }
  1231. }
  1232. }
  1233. return (bRet ? S_OK : E_FAIL);
  1234. }
  1235. /*
  1236. - CFaxServerNode::OnLaunchClientConsole
  1237. -
  1238. * Purpose:
  1239. * To launch client console.
  1240. *
  1241. * Arguments:
  1242. *
  1243. * Return:
  1244. * OLE error code
  1245. */
  1246. HRESULT CFaxServerNode::OnLaunchClientConsole(bool &bHandled, CSnapInObjectRootBase *pRoot)
  1247. {
  1248. DEBUG_FUNCTION_NAME(_T("CFaxServerNode::OnLaunchClientConsole"));
  1249. DWORD dwRes = ERROR_SUCCESS;
  1250. HINSTANCE hClientConsole;
  1251. UINT idsRet;
  1252. //
  1253. // (-1) GetServerName
  1254. //
  1255. CComBSTR bstrServerName = L"";
  1256. bstrServerName = GetServerName();
  1257. if (!bstrServerName)
  1258. {
  1259. DebugPrintEx(
  1260. DEBUG_ERR,
  1261. _T("Launch client console failed due to failure during GetServerName."));
  1262. NodeMsgBox(IDS_MEMORY);
  1263. bstrServerName = L"";
  1264. return E_FAIL;
  1265. }
  1266. //
  1267. // start cover page editor
  1268. //
  1269. hClientConsole = ShellExecute( NULL,
  1270. TEXT("open"), // Command
  1271. FAX_CLIENT_CONSOLE_IMAGE_NAME,
  1272. bstrServerName,
  1273. NULL,
  1274. SW_RESTORE
  1275. );
  1276. if( (DWORD_PTR)hClientConsole <= 32 )
  1277. {
  1278. // ShellExecute fail
  1279. dwRes = PtrToUlong(hClientConsole);
  1280. DebugPrintEx(
  1281. DEBUG_ERR,
  1282. _T("Failed to run ShellExecute. (ec : %ld)"), dwRes);
  1283. ATLASSERT(dwRes >= 0);
  1284. //
  1285. // Select message to user
  1286. //
  1287. switch (dwRes)
  1288. {
  1289. case 0: //The operating system is out of memory or resources.
  1290. case SE_ERR_OOM: //There was not enough memory to complete the operation.
  1291. idsRet = IDS_MEMORY;
  1292. break;
  1293. case ERROR_FILE_NOT_FOUND: //The specified file was not found.
  1294. case ERROR_PATH_NOT_FOUND: //The specified path was not found.
  1295. case ERROR_BAD_FORMAT: //The .exe file is invalid (non-Win32� .exe or error in .exe image).
  1296. //case SE_ERR_PNF: value '3' already used //The specified path was not found.
  1297. //case SE_ERR_FNF: value '2' already used //The specified file was not found.
  1298. case SE_ERR_ASSOCINCOMPLETE: //The file name association is incomplete or invalid.
  1299. idsRet = IDS_FAXCONSOLE_NOTFOUND;
  1300. break;
  1301. case SE_ERR_ACCESSDENIED: //The operating system denied access to the specified file.
  1302. idsRet = IDS_FAXCONSOLE_ACCESSDENIED;
  1303. break;
  1304. case SE_ERR_DLLNOTFOUND: //The specified dynamic-link library was not found.
  1305. case SE_ERR_SHARE: //A sharing violation occurred.
  1306. default:
  1307. idsRet = IDS_FAIL2LAUNCH_FAXCONSOLE_GEN;
  1308. break;
  1309. }
  1310. NodeMsgBox(idsRet);
  1311. goto Exit;
  1312. }
  1313. ATLASSERT( ERROR_SUCCESS == dwRes);
  1314. Exit:
  1315. return HRESULT_FROM_WIN32( dwRes );
  1316. }
  1317. /*
  1318. - CFaxServerNode::InitDisplayName
  1319. -
  1320. * Purpose:
  1321. * To load the node's Displaed-Name string.
  1322. *
  1323. * Arguments:
  1324. *
  1325. * Return:
  1326. * OLE error code
  1327. */
  1328. HRESULT CFaxServerNode::InitDisplayName()
  1329. {
  1330. DEBUG_FUNCTION_NAME(_T("CFaxServerNode::InitDisplayName"));
  1331. HRESULT hRc = S_OK;
  1332. if (!m_bstrDisplayName.LoadString(_Module.GetResourceInstance(),
  1333. IDS_DISPLAY_STR_FAXSERVERNODE))
  1334. {
  1335. hRc = E_OUTOFMEMORY;
  1336. goto Error;
  1337. }
  1338. ATLASSERT( S_OK == hRc);
  1339. goto Exit;
  1340. Error:
  1341. ATLASSERT( S_OK != hRc);
  1342. m_bstrDisplayName = L"";
  1343. DebugPrintEx(
  1344. DEBUG_ERR,
  1345. TEXT("Fail to Load server name string."));
  1346. NodeMsgBox(IDS_MEMORY);
  1347. Exit:
  1348. return hRc;
  1349. }
  1350. /*
  1351. - CFaxServerNode::SetServerNameOnSnapinAddition()
  1352. -
  1353. * Purpose:
  1354. * Set server name and init the related node's Displaed-Name string.
  1355. *
  1356. * Arguments:
  1357. *
  1358. * Return:
  1359. * OLE error code
  1360. */
  1361. HRESULT CFaxServerNode::SetServerNameOnSnapinAddition(BSTR bstrServerName, BOOL fAllowOverrideServerName)
  1362. {
  1363. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::SetServerNameOnSnapinAddition"));
  1364. HRESULT hRc = S_OK;
  1365. hRc = UpdateServerName(bstrServerName);
  1366. if (S_OK != hRc)
  1367. {
  1368. DebugPrintEx(
  1369. DEBUG_ERR,
  1370. _T("Failed to UpdateServerName - out of memory"));
  1371. goto Exit;
  1372. }
  1373. hRc = InitDetailedDisplayName();
  1374. if ( S_OK != hRc)
  1375. {
  1376. DebugPrintEx(
  1377. DEBUG_ERR,
  1378. _T("Failed to InitDetailedDisplayName. (hRc: %08X)"),
  1379. hRc);
  1380. goto Exit;
  1381. }
  1382. ATLASSERT (S_OK == hRc);
  1383. //
  1384. // Update override status
  1385. //
  1386. m_fAllowOverrideServerName = fAllowOverrideServerName;
  1387. Exit:
  1388. return hRc;
  1389. }
  1390. /*
  1391. - CFaxServerNode::ForceRedrawNode
  1392. -
  1393. * Purpose:
  1394. * To show the new node's Displaed-Name string.
  1395. *
  1396. * Arguments:
  1397. *
  1398. * Return:
  1399. * OLE error code
  1400. */
  1401. HRESULT CFaxServerNode::ForceRedrawNode()
  1402. {
  1403. DEBUG_FUNCTION_NAME(_T("CFaxServerNode::ForceRedrawNode"));
  1404. HRESULT hRc = S_OK;
  1405. //
  1406. // Get IConsoleNameSpace
  1407. //
  1408. ATLASSERT( m_pComponentData != NULL );
  1409. ATLASSERT( m_pComponentData->m_spConsole != NULL );
  1410. CComPtr<IConsole> spConsole;
  1411. spConsole = m_pComponentData->m_spConsole;
  1412. CComQIPtr<IConsoleNameSpace,&IID_IConsoleNameSpace> spNamespace( spConsole );
  1413. //
  1414. // Get the updated SCOPEDATAITEM
  1415. //
  1416. SCOPEDATAITEM* pScopeData;
  1417. hRc = GetScopeData( &pScopeData );
  1418. if (FAILED(hRc))
  1419. {
  1420. DebugPrintEx(
  1421. DEBUG_ERR,
  1422. TEXT("Fail to get pScopeData. (hRc: %08X)"),
  1423. hRc);
  1424. goto Error;
  1425. }
  1426. //
  1427. // Update (*pScopeData).displayname
  1428. //
  1429. (*pScopeData).displayname = m_bstrDisplayName;
  1430. //
  1431. // Force MMC to redraw the scope node
  1432. //
  1433. hRc = spNamespace->SetItem( pScopeData );
  1434. if (FAILED(hRc))
  1435. {
  1436. DebugPrintEx(
  1437. DEBUG_ERR,
  1438. TEXT("Fail to set Item pScopeData. (hRc: %08X)"),
  1439. hRc);
  1440. goto Error;
  1441. }
  1442. ATLASSERT(S_OK == hRc);
  1443. goto Exit;
  1444. Error:
  1445. NodeMsgBox(IDS_FAIL2RENAME_NODE);
  1446. Exit:
  1447. return hRc;
  1448. }
  1449. /*
  1450. - CFaxServerNode::UpdateServerName
  1451. -
  1452. * Purpose:
  1453. * Update the server name for fax Server node and CFaxServer.
  1454. *
  1455. * Arguments:
  1456. *
  1457. * Return:
  1458. * OLE error code
  1459. */
  1460. HRESULT CFaxServerNode::UpdateServerName(BSTR bstrServerName)
  1461. {
  1462. DEBUG_FUNCTION_NAME( _T("CFaxServerNode::UpdateServerName"));
  1463. HRESULT hRc = S_OK;
  1464. ATLASSERT(GetFaxServer());
  1465. hRc = GetFaxServer()->SetServerName(bstrServerName);
  1466. if ( S_OK != hRc)
  1467. {
  1468. DebugPrintEx(
  1469. DEBUG_ERR,
  1470. _T("Failed Update FaxServer with the server name. (hRc: %08X)"),
  1471. hRc);
  1472. NodeMsgBox(IDS_MEMORY);
  1473. }
  1474. return hRc;
  1475. }
  1476. /*
  1477. - CFaxServerNode::InitDetailedDisplayName()
  1478. -
  1479. * Purpose:
  1480. * Load the node's Displaed-Name string with the server name.
  1481. *
  1482. * Arguments:
  1483. *
  1484. * Return:
  1485. * OLE error code
  1486. */
  1487. HRESULT CFaxServerNode::InitDetailedDisplayName()
  1488. {
  1489. DEBUG_FUNCTION_NAME(_T("CFaxServerNode::InitDetailedDisplayName"));
  1490. HRESULT hRc = S_OK;
  1491. CComBSTR bstrServerName;
  1492. CComBSTR bstrLeftBracket;
  1493. CComBSTR bstrRightBracket;
  1494. CComBSTR bstrLocal;
  1495. if (!m_bstrDisplayName.LoadString(_Module.GetResourceInstance(),
  1496. IDS_DISPLAY_STR_FAXSERVERNODE))
  1497. {
  1498. hRc = E_OUTOFMEMORY;
  1499. goto Error;
  1500. }
  1501. //
  1502. // Retreive the server name
  1503. //
  1504. bstrServerName = GetServerName();
  1505. if (!bstrServerName)
  1506. {
  1507. DebugPrintEx(
  1508. DEBUG_ERR,
  1509. _T("Fail to get the server name."));
  1510. NodeMsgBox(IDS_MEMORY);
  1511. bstrServerName = L"";
  1512. hRc = E_OUTOFMEMORY;
  1513. goto Error;
  1514. }
  1515. //
  1516. // Appends the sever name
  1517. //
  1518. if (!bstrLeftBracket.LoadString(_Module.GetResourceInstance(),
  1519. IDS_LEFTBRACKET_PLUSSPACE))
  1520. {
  1521. hRc = E_OUTOFMEMORY;
  1522. goto Error;
  1523. }
  1524. if (!bstrRightBracket.LoadString(_Module.GetResourceInstance(),
  1525. IDS_RIGHTBRACKET))
  1526. {
  1527. hRc = E_OUTOFMEMORY;
  1528. goto Error;
  1529. }
  1530. if (!bstrLocal.LoadString(_Module.GetResourceInstance(),
  1531. IDS_LOCAL_PLUSBRACKET_PLUSSPACE))
  1532. {
  1533. hRc = E_OUTOFMEMORY;
  1534. goto Error;
  1535. }
  1536. if ( 0 == bstrServerName.Length() ) //if equals L""
  1537. {
  1538. m_bstrDisplayName += bstrLocal;
  1539. }
  1540. else
  1541. {
  1542. m_bstrDisplayName += bstrLeftBracket;
  1543. m_bstrDisplayName += bstrServerName;
  1544. m_bstrDisplayName += bstrRightBracket;
  1545. }
  1546. ATLASSERT( S_OK == hRc);
  1547. //
  1548. // Setting this flag to allow pre connection check
  1549. // during first FaxServerNode expand.
  1550. //
  1551. m_IsPrimaryModeSnapin = TRUE;
  1552. goto Exit;
  1553. Error:
  1554. ATLASSERT( S_OK != hRc);
  1555. DebugPrintEx(
  1556. DEBUG_ERR,
  1557. TEXT("Fail to Load server name string."));
  1558. NodeMsgBox(IDS_MEMORY);
  1559. Exit:
  1560. return hRc;
  1561. }
  1562. const CComBSTR& CFaxServerNode::GetServerName()
  1563. {
  1564. DEBUG_FUNCTION_NAME(_T("CFaxServerNode::GetServerName"));
  1565. ATLASSERT(GetFaxServer());
  1566. return GetFaxServer()->GetServerName();
  1567. }
  1568. /*
  1569. +
  1570. + CFaxServerNode::OnShowContextHelp
  1571. *
  1572. * Purpose:
  1573. * Overrides CSnapinNode::OnShowContextHelp.
  1574. *
  1575. * Arguments:
  1576. *
  1577. * Return:
  1578. - OLE error code
  1579. -
  1580. */
  1581. HRESULT CFaxServerNode::OnShowContextHelp(
  1582. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  1583. {
  1584. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_INTRO);
  1585. }
  1586. /////////////////////////////////////////////////////////////////