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.

479 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : Providers.cpp //
  3. // //
  4. // DESCRIPTION : Fax Providers MMC node. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Sep 29 1999 yossg create //
  10. // Oct 17 2000 yossg //
  11. // //
  12. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "FaxServer.h"
  16. #include "FaxServerNode.h"
  17. #include "DevicesAndProviders.h"
  18. #include "Providers.h"
  19. #include "Provider.h"
  20. #include "Icons.h"
  21. #include "oaidl.h"
  22. ///////////////////////////////////////////////////////////////////////////////////////////////
  23. // {3EC48359-53C9-4881-8109-AEB3D99BAF23}
  24. static const GUID CFaxProvidersNodeGUID_NODETYPE =
  25. { 0x3ec48359, 0x53c9, 0x4881, { 0x81, 0x9, 0xae, 0xb3, 0xd9, 0x9b, 0xaf, 0x23 } };
  26. const GUID* CFaxProvidersNode::m_NODETYPE = &CFaxProvidersNodeGUID_NODETYPE;
  27. const OLECHAR* CFaxProvidersNode::m_SZNODETYPE = OLESTR("3EC48359-53C9-4881-8109-AEB3D99BAF23");
  28. const CLSID* CFaxProvidersNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  29. CColumnsInfo CFaxProvidersNode::m_ColsInfo;
  30. /*
  31. - CFaxProvidersNode::InsertColumns
  32. -
  33. * Purpose:
  34. * Adds columns to the default result pane.
  35. *
  36. * Arguments:
  37. * [in] pHeaderCtrl - IHeaderCtrl in the console-provided default result view pane
  38. *
  39. * Return:
  40. * OLE error code
  41. */
  42. HRESULT
  43. CFaxProvidersNode::InsertColumns(IHeaderCtrl *pHeaderCtrl)
  44. {
  45. HRESULT hRc = S_OK;
  46. DEBUG_FUNCTION_NAME( _T("CFaxProvidersNode::InsertColumns"));
  47. static ColumnsInfoInitData ColumnsInitData[] =
  48. {
  49. {IDS_PROVIDERS_COL1, FXS_LARGE_COLUMN_WIDTH},
  50. {IDS_PROVIDERS_COL2, AUTO_WIDTH},
  51. {IDS_PROVIDERS_COL3, FXS_WIDE_COLUMN_WIDTH},
  52. {IDS_PROVIDERS_COL4, FXS_LARGE_COLUMN_WIDTH},
  53. {LAST_IDS, 0}
  54. };
  55. hRc = m_ColsInfo.InsertColumnsIntoMMC(pHeaderCtrl,
  56. _Module.GetResourceInstance(),
  57. ColumnsInitData);
  58. CHECK_RETURN_VALUE_AND_PRINT_DEBUG (_T("m_ColsInfo.InsertColumnsIntoMMC"))
  59. Cleanup:
  60. return(hRc);
  61. }
  62. /*
  63. - CFaxProvidersNode::initRPC
  64. -
  65. * Purpose:
  66. * Initiates the configuration structure from RPC get Call.
  67. *
  68. * Arguments:
  69. *
  70. * Return:
  71. * OLE error code
  72. */
  73. HRESULT CFaxProvidersNode::InitRPC(PFAX_DEVICE_PROVIDER_INFO *pFaxProvidersConfig)
  74. {
  75. DEBUG_FUNCTION_NAME( _T("CFaxProvidersNode::InitRPC"));
  76. HRESULT hRc = S_OK;
  77. DWORD ec = ERROR_SUCCESS;
  78. CFaxServer * pFaxServer = NULL;
  79. ATLASSERT(NULL == (*pFaxProvidersConfig) );
  80. //
  81. // get Fax Handle
  82. //
  83. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  84. ATLASSERT(pFaxServer);
  85. if (!pFaxServer->GetFaxServerHandle())
  86. {
  87. ec= GetLastError();
  88. DebugPrintEx(
  89. DEBUG_ERR,
  90. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  91. ec);
  92. goto Error;
  93. }
  94. //
  95. // Retrieve the fax providers configuration
  96. //
  97. if (!FaxEnumerateProviders(pFaxServer->GetFaxServerHandle(),
  98. pFaxProvidersConfig,
  99. &m_dwNumOfProviders))
  100. {
  101. ec = GetLastError();
  102. DebugPrintEx(
  103. DEBUG_ERR,
  104. _T("Fail to get providers configuration. (ec: %ld)"),
  105. ec);
  106. if (IsNetworkError(ec))
  107. {
  108. DebugPrintEx(
  109. DEBUG_ERR,
  110. _T("Network Error was found. (ec: %ld)"),
  111. ec);
  112. pFaxServer->Disconnect();
  113. }
  114. goto Error;
  115. }
  116. //For max verification
  117. ATLASSERT(*pFaxProvidersConfig);
  118. ATLASSERT(ERROR_SUCCESS == ec);
  119. DebugPrintEx( DEBUG_MSG,
  120. _T("Succeed to get providers configuration."));
  121. goto Exit;
  122. Error:
  123. ATLASSERT(ERROR_SUCCESS != ec);
  124. hRc = HRESULT_FROM_WIN32(ec);
  125. NodeMsgBox(GetFaxServerErrorMsg(ec));
  126. Exit:
  127. return (hRc);
  128. }
  129. /*
  130. - CFaxProvidersNode::PopulateResultChildrenList
  131. -
  132. * Purpose:
  133. * Create the FaxProviders children nodes
  134. *
  135. * Arguments:
  136. *
  137. * Return:
  138. * OLE error code
  139. */
  140. HRESULT CFaxProvidersNode::PopulateResultChildrenList()
  141. {
  142. DEBUG_FUNCTION_NAME( _T("CFaxProvidersNode::PopulateResultChildrenList"));
  143. HRESULT hRc = S_OK;
  144. CFaxProviderNode * pProvider = NULL;
  145. PFAX_DEVICE_PROVIDER_INFO pFaxProvidersConfig = NULL ;
  146. DWORD i;
  147. //
  148. // Get the Config. structure with FaxEnumerateProviders
  149. //
  150. hRc = InitRPC(&pFaxProvidersConfig);
  151. if (FAILED(hRc))
  152. {
  153. //DebugPrint and MsgBox by called func.
  154. //to be safe actually done by InitRPC on error.
  155. pFaxProvidersConfig = NULL;
  156. goto Error;
  157. }
  158. ATLASSERT(NULL != pFaxProvidersConfig);
  159. for ( i=0; i< m_dwNumOfProviders; i++ )
  160. {
  161. pProvider = new CFaxProviderNode(this, m_pComponentData);
  162. if (!pProvider)
  163. {
  164. hRc = E_OUTOFMEMORY;
  165. NodeMsgBox(IDS_MEMORY);
  166. DebugPrintEx(
  167. DEBUG_ERR,
  168. TEXT("Out of memory. (hRc: %08X)"),
  169. hRc);
  170. goto Error;
  171. }
  172. else
  173. {
  174. pProvider->InitParentNode(this);
  175. hRc = pProvider->Init(&pFaxProvidersConfig[i]);
  176. if (FAILED(hRc))
  177. {
  178. DebugPrintEx(
  179. DEBUG_ERR,
  180. TEXT("Fail to add provider node. (hRc: %08X)"),
  181. hRc);
  182. NodeMsgBox(IDS_FAILED2INIT_PROVIDER);
  183. goto Error;
  184. }
  185. hRc = this->AddChildToList(pProvider);
  186. if (FAILED(hRc))
  187. {
  188. DebugPrintEx(
  189. DEBUG_ERR,
  190. TEXT("Fail to add provider to the view. (hRc: %08X)"),
  191. hRc);
  192. NodeMsgBox(IDS_FAILED2ADD_PROVIDER);
  193. goto Error;
  194. }
  195. else
  196. {
  197. pProvider = NULL;
  198. }
  199. }
  200. }
  201. ATLASSERT(S_OK == hRc);
  202. goto Exit;
  203. Error:
  204. ATLASSERT(S_OK != hRc);
  205. if ( NULL != pProvider )
  206. {
  207. delete pProvider;
  208. pProvider = NULL;
  209. }
  210. //
  211. // Get rid of what we had.
  212. //
  213. {
  214. // Delete each node in the list of children
  215. int iSize = m_ResultChildrenList.GetSize();
  216. for (int j = 0; j < iSize; j++)
  217. {
  218. pProvider = (CFaxProviderNode *)
  219. m_ResultChildrenList[j];
  220. ATLASSERT(pProvider);
  221. delete pProvider;
  222. pProvider = NULL;
  223. }
  224. // Empty the list
  225. m_ResultChildrenList.RemoveAll();
  226. // We no longer have a populated list.
  227. m_bResultChildrenListPopulated = FALSE;
  228. }
  229. Exit:
  230. if (NULL != pFaxProvidersConfig)
  231. {
  232. FaxFreeBuffer(pFaxProvidersConfig);
  233. }
  234. return hRc;
  235. }
  236. /*
  237. - CFaxProvidersNode::SetVerbs
  238. -
  239. * Purpose:
  240. * What verbs to enable/disable when this object is selected
  241. *
  242. * Arguments:
  243. * [in] pConsoleVerb - MMC ConsoleVerb interface
  244. *
  245. * Return:
  246. * OLE Error code
  247. */
  248. HRESULT CFaxProvidersNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  249. {
  250. HRESULT hRc = S_OK;
  251. //
  252. // Refresh
  253. //
  254. hRc = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  255. //
  256. // We want the default verb to be expand node children
  257. //
  258. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  259. return hRc;
  260. }
  261. /*
  262. - CFaxProvidersNode::OnRefresh
  263. -
  264. * Purpose:
  265. * Called when refreshing the object.
  266. *
  267. * Arguments:
  268. *
  269. * Return:
  270. * OLE error code
  271. */
  272. /* virtual */HRESULT
  273. CFaxProvidersNode::OnRefresh(LPARAM arg,
  274. LPARAM param,
  275. IComponentData *pComponentData,
  276. IComponent * pComponent,
  277. DATA_OBJECT_TYPES type)
  278. {
  279. DEBUG_FUNCTION_NAME( _T("CFaxProvidersNode::OnRefresh"));
  280. HRESULT hRc = S_OK;
  281. //
  282. // Call the base class
  283. //
  284. hRc = CBaseFaxProvidersNode::OnRefresh(arg,
  285. param,
  286. pComponentData,
  287. pComponent,
  288. type);
  289. if ( FAILED(hRc) )
  290. {
  291. DebugPrintEx(
  292. DEBUG_ERR,
  293. _T("Fail to call base class's OnRefresh. (hRc: %08X)"),
  294. hRc);
  295. goto Exit;
  296. }
  297. Exit:
  298. return hRc;
  299. }
  300. /*
  301. - CFaxProvidersNode::DoRefresh
  302. -
  303. * Purpose:
  304. * Refresh the view
  305. *
  306. * Arguments:
  307. * [in] pRoot - The root node
  308. *
  309. * Return:
  310. * OLE Error code
  311. */
  312. HRESULT
  313. CFaxProvidersNode::DoRefresh(CSnapInObjectRootBase *pRoot)
  314. {
  315. CComPtr<IConsole> spConsole;
  316. //
  317. // Repopulate childs
  318. //
  319. RepopulateResultChildrenList();
  320. if (pRoot)
  321. {
  322. //
  323. // Get the console pointer
  324. //
  325. ATLASSERT(pRoot->m_nType == 1 || pRoot->m_nType == 2);
  326. if (pRoot->m_nType == 1)
  327. {
  328. //
  329. // m_ntype == 1 means the IComponentData implementation
  330. //
  331. CSnapin *pCComponentData = static_cast<CSnapin *>(pRoot);
  332. spConsole = pCComponentData->m_spConsole;
  333. }
  334. else
  335. {
  336. //
  337. // m_ntype == 2 means the IComponent implementation
  338. //
  339. CSnapinComponent *pCComponent = static_cast<CSnapinComponent *>(pRoot);
  340. spConsole = pCComponent->m_spConsole;
  341. }
  342. }
  343. else
  344. {
  345. ATLASSERT(m_pComponentData);
  346. spConsole = m_pComponentData->m_spConsole;
  347. }
  348. ATLASSERT(spConsole);
  349. spConsole->UpdateAllViews(NULL, NULL, NULL);
  350. return S_OK;
  351. }
  352. /*
  353. - CFaxProvidersNode::InitDisplayName
  354. -
  355. * Purpose:
  356. * To load the node's Displaed-Name string.
  357. *
  358. * Arguments:
  359. *
  360. * Return:
  361. * OLE error code
  362. */
  363. HRESULT CFaxProvidersNode::InitDisplayName()
  364. {
  365. DEBUG_FUNCTION_NAME(_T("CFaxProvidersNode::InitDisplayName"));
  366. HRESULT hRc = S_OK;
  367. if (!m_bstrDisplayName.LoadString(_Module.GetResourceInstance(),
  368. IDS_DISPLAY_STR_PROVIDERSNODE))
  369. {
  370. hRc = E_OUTOFMEMORY;
  371. goto Error;
  372. }
  373. ATLASSERT( S_OK == hRc);
  374. goto Exit;
  375. Error:
  376. ATLASSERT( S_OK != hRc);
  377. m_bstrDisplayName = L"";
  378. DebugPrintEx(
  379. DEBUG_ERR,
  380. TEXT("Fail to Load server name string."));
  381. NodeMsgBox(IDS_MEMORY);
  382. Exit:
  383. return hRc;
  384. }
  385. /*
  386. +
  387. + CFaxProvidersNode::OnShowContextHelp
  388. *
  389. * Purpose:
  390. * Overrides CSnapinNode::OnShowContextHelp.
  391. *
  392. * Arguments:
  393. *
  394. * Return:
  395. - OLE error code
  396. -
  397. */
  398. HRESULT CFaxProvidersNode::OnShowContextHelp(
  399. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  400. {
  401. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_DEVICES);
  402. }