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.

507 lines
13 KiB

  1. #include "stdafx.h"
  2. #include "T30PropSheetExt.h"
  3. #include "T30Config.h"
  4. #include <t30ext.h>
  5. #include <faxutil.h>
  6. #include <faxreg.h>
  7. #include <faxres.h>
  8. #include <faxuiconstants.h>
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CT30ConfigComponentData
  11. static const GUID CT30ConfigExtGUID_NODETYPE = FAXSRV_DEVICE_NODETYPE_GUID;
  12. //{ 0x3115a19a, 0x6251, 0x46ac, { 0x94, 0x25, 0x14, 0x78, 0x28, 0x58, 0xb8, 0xc9 } };
  13. const GUID* CT30ConfigExtData::m_NODETYPE = &CT30ConfigExtGUID_NODETYPE;
  14. const OLECHAR* CT30ConfigExtData::m_SZNODETYPE = FAXSRV_DEVICE_NODETYPE_GUID_STR;
  15. //OLESTR("3115A19A-6251-46ac-9425-14782858B8C9");
  16. const OLECHAR* CT30ConfigExtData::m_SZDISPLAY_NAME = OLESTR("T30Config");
  17. const CLSID* CT30ConfigExtData::m_SNAPIN_CLASSID = &CLSID_T30Config;
  18. void DisplayRpcErrorMessage(DWORD ec, HWND hWnd);
  19. void DisplayErrorMessage(UINT uMsgId, HWND hWnd, BOOL bCommon = FALSE);
  20. HRESULT GetDWORDFromDataObject(
  21. IDataObject * lpDataObject,
  22. CLIPFORMAT uFormat,
  23. LPDWORD lpdwValue
  24. );
  25. HRESULT GetStringFromDataObject(
  26. IDataObject * lpDataObject,
  27. CLIPFORMAT uFormat,
  28. LPWSTR lpwstrBuf,
  29. DWORD dwBufLen
  30. );
  31. HRESULT CT30ConfigExtData::QueryPagesFor(DATA_OBJECT_TYPES type)
  32. {
  33. DEBUG_FUNCTION_NAME(TEXT("CT30ConfigExtData::QueryPagesFor"));
  34. if (type == CCT_SCOPE || type == CCT_RESULT)
  35. {
  36. WCHAR szFSPGuid[FAXSRV_MAX_GUID_LEN + 1];
  37. HRESULT hr;
  38. hr = GetStringFromDataObject(m_pDataObject,m_CCF_FSP_GUID, szFSPGuid,sizeof(szFSPGuid)/sizeof(WCHAR));
  39. if (FAILED(hr))
  40. {
  41. DebugPrintEx(
  42. DEBUG_ERR,
  43. TEXT("GetFSPGUIDFromDataObject failed. hr = 0x%08X"),
  44. hr);
  45. return hr;
  46. }
  47. if (CSTR_EQUAL == CompareString(LOCALE_INVARIANT,
  48. NORM_IGNORECASE,
  49. szFSPGuid,
  50. -1,
  51. REGVAL_T30_PROVIDER_GUID_STRING,
  52. -1))
  53. {
  54. return S_OK;
  55. }
  56. else
  57. {
  58. return S_FALSE;
  59. }
  60. }
  61. return S_FALSE;
  62. }
  63. HRESULT CT30ConfigExtData::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  64. LONG_PTR handle,
  65. IUnknown* pUnk,
  66. DATA_OBJECT_TYPES type)
  67. {
  68. DEBUG_FUNCTION_NAME(TEXT("CT30ConfigExtData::CreatePropertyPages"));
  69. WCHAR szFSPGuid[FAXSRV_MAX_GUID_LEN + 1];
  70. WCHAR szServer[FAXSRV_MAX_SERVER_NAME + 1];
  71. DWORD dwDeviceId;
  72. HRESULT hr;
  73. hr = GetStringFromDataObject(m_pDataObject,m_CCF_FSP_GUID, szFSPGuid,sizeof(szFSPGuid)/sizeof(WCHAR));
  74. if (FAILED(hr))
  75. {
  76. DebugPrintEx(
  77. DEBUG_ERR,
  78. TEXT("GetFSPGUIDFromDataObject for m_CCF_FSP_GUID failed. hr = 0x%08X"),
  79. hr);
  80. return hr;
  81. }
  82. if (CSTR_EQUAL != CompareString(LOCALE_INVARIANT,
  83. NORM_IGNORECASE,
  84. szFSPGuid,
  85. -1,
  86. REGVAL_T30_PROVIDER_GUID_STRING,
  87. -1))
  88. {
  89. return E_UNEXPECTED;
  90. }
  91. hr = GetStringFromDataObject(m_pDataObject,m_CCF_SERVER_NAME, szServer,sizeof(szServer)/sizeof(WCHAR));
  92. if (FAILED(hr))
  93. {
  94. DebugPrintEx(
  95. DEBUG_ERR,
  96. TEXT("GetFSPGUIDFromDataObject for m_CCF_SERVER_NAME failed. hr = 0x%08X"),
  97. hr);
  98. return hr;
  99. }
  100. hr = GetDWORDFromDataObject(m_pDataObject,m_CCF_FSP_DEVICE_ID,&dwDeviceId);
  101. if (FAILED(hr))
  102. {
  103. DebugPrintEx(
  104. DEBUG_ERR,
  105. TEXT("GetDeviceIdFromDataObject failed. hr = 0x%08X"),
  106. hr);
  107. return hr;
  108. }
  109. CComBSTR bstrPageTitle;
  110. bstrPageTitle.LoadString(IDS_T30PAGE_TITLE);
  111. if (!bstrPageTitle)
  112. {
  113. return E_UNEXPECTED;
  114. }
  115. CT30ConfigPage* pPage = new CT30ConfigPage(handle, true, bstrPageTitle); // true = only one page
  116. if (!pPage)
  117. {
  118. DebugPrintEx(
  119. DEBUG_ERR,
  120. TEXT("Failed to allocate CT30ConfigPage")
  121. );
  122. return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  123. }
  124. hr = pPage->Init(szServer, dwDeviceId);
  125. if (SUCCEEDED(hr))
  126. {
  127. lpProvider->AddPage(pPage->Create());
  128. }
  129. else
  130. {
  131. return E_UNEXPECTED;
  132. }
  133. return S_OK;
  134. }
  135. HRESULT CT30ConfigPage::Init(LPCTSTR lpctstrServerName, DWORD dwDeviceId)
  136. {
  137. DEBUG_FUNCTION_NAME(TEXT("CT30ConfigPage::Init"));
  138. LPT30_EXTENSION_DATA lpExtData = NULL;
  139. DWORD dwDataSize = 0;
  140. DWORD ec = ERROR_SUCCESS;
  141. m_dwDeviceId = dwDeviceId;
  142. m_bstrServerName = lpctstrServerName;
  143. if (!m_bstrServerName)
  144. {
  145. DebugPrintEx(
  146. DEBUG_ERR,
  147. TEXT("Out of memory while copying server name (ec: %ld)")
  148. );
  149. ec = ERROR_NOT_ENOUGH_MEMORY;
  150. DisplayRpcErrorMessage(ERROR_NOT_ENOUGH_MEMORY, m_hWnd);
  151. goto exit;
  152. }
  153. if (!FaxConnectFaxServer(lpctstrServerName,&m_hFax))
  154. {
  155. ec = GetLastError();
  156. DebugPrintEx(
  157. DEBUG_ERR,
  158. TEXT("FaxConnectFaxServer failed (ec: %ld)"),
  159. ec);
  160. DisplayRpcErrorMessage(ec, m_hWnd);
  161. goto exit;
  162. }
  163. if(!FaxGetExtensionData(
  164. m_hFax,
  165. m_dwDeviceId,
  166. GUID_T30_EXTENSION_DATA,
  167. (PVOID *)&lpExtData,
  168. &dwDataSize
  169. ))
  170. {
  171. ec = GetLastError();
  172. lpExtData = NULL;
  173. if (ERROR_FILE_NOT_FOUND == ec)
  174. {
  175. DebugPrintEx(
  176. DEBUG_ERR,
  177. TEXT("T30 Data not found. Device: 0x%08X, GUID: %s"),
  178. m_dwDeviceId,
  179. GUID_T30_EXTENSION_DATA);
  180. ec = ERROR_SUCCESS;
  181. m_bAdaptiveAnsweringEnabled = FALSE;
  182. }
  183. else
  184. {
  185. DebugPrintEx(
  186. DEBUG_ERR,
  187. TEXT("T30 FaxGetExtensionData() failed. GUID = %s (ec: %ld)"),
  188. GUID_T30_EXTENSION_DATA,
  189. ec);
  190. DisplayRpcErrorMessage(ec, m_hWnd);
  191. }
  192. goto exit;
  193. }
  194. if (dwDataSize != sizeof(T30_EXTENSION_DATA))
  195. {
  196. DebugPrintEx(
  197. DEBUG_ERR,
  198. TEXT("T30 FaxGetExtensionData() returned mismatched data size (%ld)"),
  199. dwDataSize);
  200. ec = ERROR_BAD_FORMAT;
  201. DisplayErrorMessage(IDS_ERR_BAD_T30_CONFIGURATION, m_hWnd);
  202. goto exit;
  203. }
  204. m_bAdaptiveAnsweringEnabled = lpExtData->bAdaptiveAnsweringEnabled;
  205. Assert(ERROR_SUCCESS == ec);
  206. exit:
  207. if ((ERROR_SUCCESS != ec) && m_hFax)
  208. {
  209. if (!FaxClose(m_hFax))
  210. {
  211. DebugPrintEx(
  212. DEBUG_ERR,
  213. TEXT("FaxClose() failed on fax handle (0x%08X : %s). (ec: %ld)"),
  214. m_hFax,
  215. m_bstrServerName,
  216. GetLastError());
  217. }
  218. m_hFax = NULL;
  219. }
  220. if (lpExtData)
  221. {
  222. FaxFreeBuffer(lpExtData);
  223. lpExtData = NULL;
  224. }
  225. return HRESULT_FROM_WIN32(ec);
  226. }
  227. LRESULT CT30ConfigPage::OnInitDialog(
  228. UINT uiMsg,
  229. WPARAM wParam,
  230. LPARAM lParam,
  231. BOOL& fHandled )
  232. {
  233. DEBUG_FUNCTION_NAME( _T("CT30ConfigPage::OnInitDialog"));
  234. m_btnAdaptiveEnabled.Attach(GetDlgItem(IDC_ADAPTIVE_ANSWERING));
  235. m_btnAdaptiveEnabled.SetCheck(m_bAdaptiveAnsweringEnabled ? BST_CHECKED : BST_UNCHECKED);
  236. return 1;
  237. }
  238. BOOL CT30ConfigPage::OnApply()
  239. {
  240. DEBUG_FUNCTION_NAME(TEXT("CT30ConfigPage::OnApply"));
  241. BOOL bRet = FALSE;
  242. T30_EXTENSION_DATA ExtData;
  243. memset(&ExtData,0,sizeof(ExtData));
  244. ExtData.bAdaptiveAnsweringEnabled = (BST_CHECKED == m_btnAdaptiveEnabled.GetCheck());
  245. if(!FaxSetExtensionData(
  246. m_hFax,
  247. m_dwDeviceId,
  248. GUID_T30_EXTENSION_DATA,
  249. (LPVOID)&ExtData,
  250. sizeof(ExtData)
  251. ))
  252. {
  253. DWORD ec = GetLastError();
  254. DebugPrintEx(
  255. DEBUG_ERR,
  256. TEXT("T30 FaxGetExtensionData() failed. GUID = %s (ec: %ld)"),
  257. GUID_T30_EXTENSION_DATA,
  258. ec);
  259. DisplayRpcErrorMessage(ec, m_hWnd);
  260. }
  261. else
  262. {
  263. bRet = TRUE;
  264. }
  265. return bRet;
  266. }
  267. HRESULT GetDWORDFromDataObject(
  268. IDataObject * lpDataObject,
  269. CLIPFORMAT uFormat,
  270. LPDWORD lpdwValue
  271. )
  272. {
  273. DEBUG_FUNCTION_NAME(TEXT("GetDWORDFromDataObject"));
  274. Assert(lpdwValue);
  275. Assert(0 != uFormat);
  276. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  277. FORMATETC formatetc = {
  278. uFormat,
  279. NULL,
  280. DVASPECT_CONTENT,
  281. -1,
  282. TYMED_HGLOBAL
  283. };
  284. stgmedium.hGlobal = GlobalAlloc(0, sizeof(DWORD));
  285. if (stgmedium.hGlobal == NULL)
  286. {
  287. DebugPrintEx(
  288. DEBUG_ERR,
  289. TEXT("GlobalAlloc() failed. (ec: %ld)"),
  290. GetLastError());
  291. return E_OUTOFMEMORY;
  292. }
  293. HRESULT hr = lpDataObject->GetDataHere(&formatetc, &stgmedium);
  294. if (SUCCEEDED(hr))
  295. {
  296. *lpdwValue = *((LPDWORD)stgmedium.hGlobal);
  297. }
  298. else
  299. {
  300. DebugPrintEx(
  301. DEBUG_ERR,
  302. TEXT("GetDataHere() failed. (hr = 0x%08X)"),
  303. hr);
  304. }
  305. GlobalFree(stgmedium.hGlobal);
  306. return hr;
  307. }
  308. HRESULT GetStringFromDataObject(
  309. IDataObject * lpDataObject,
  310. CLIPFORMAT uFormat,
  311. LPWSTR lpwstrBuf,
  312. DWORD dwBufLen
  313. )
  314. {
  315. DEBUG_FUNCTION_NAME(TEXT("GetStringFromDataObject"));
  316. Assert(lpDataObject);
  317. Assert(lpwstrBuf);
  318. Assert(dwBufLen>0);
  319. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  320. FORMATETC formatetc =
  321. {
  322. uFormat,
  323. NULL,
  324. DVASPECT_CONTENT,
  325. -1,
  326. TYMED_HGLOBAL
  327. };
  328. stgmedium.hGlobal = GlobalAlloc(0, dwBufLen*sizeof(WCHAR));
  329. if (stgmedium.hGlobal == NULL)
  330. {
  331. DebugPrintEx(
  332. DEBUG_ERR,
  333. TEXT("GlobalAlloc() failed. (ec: %ld)"),
  334. GetLastError());
  335. return E_OUTOFMEMORY;
  336. }
  337. HRESULT hr = lpDataObject->GetDataHere(&formatetc, &stgmedium);
  338. if (SUCCEEDED(hr))
  339. {
  340. lstrcpyn(lpwstrBuf,(LPWSTR)stgmedium.hGlobal,dwBufLen);
  341. lpwstrBuf[dwBufLen-1]=L'\0';
  342. }
  343. else
  344. {
  345. DebugPrintEx(
  346. DEBUG_ERR,
  347. TEXT("GetDataHere() failed. (hr = 0x%08X)"),
  348. hr);
  349. }
  350. GlobalFree(stgmedium.hGlobal);
  351. return hr;
  352. }
  353. void DisplayRpcErrorMessage(DWORD ec, HWND hWnd)
  354. {
  355. UINT uMsgId;
  356. uMsgId = GetErrorStringId(ec);
  357. DisplayErrorMessage(uMsgId, hWnd, TRUE); // use the common error messages DLL
  358. }
  359. void DisplayErrorMessage(UINT uMsgId, HWND hWnd, BOOL bCommon)
  360. {
  361. static CComBSTR bstrCaption = TEXT("");
  362. CComBSTR bstrMsg;
  363. if (!lstrcmp(bstrCaption.m_str,TEXT("")))
  364. {
  365. bstrCaption.LoadString(IDS_T30PAGE_TITLE);
  366. if (!bstrCaption)
  367. {
  368. bstrCaption = TEXT("");
  369. return;
  370. }
  371. }
  372. if (bCommon)
  373. {
  374. bstrMsg.LoadString(_Module.GetResourceInstance(), uMsgId);
  375. }
  376. else
  377. {
  378. bstrMsg.LoadString(uMsgId);
  379. }
  380. if (bstrMsg)
  381. {
  382. AlignedMessageBox(hWnd, bstrMsg, bstrCaption, MB_OK|MB_ICONEXCLAMATION);
  383. }
  384. }
  385. //////////////////////////////////////////////////////////////////////////////
  386. /*++
  387. CppFaxServerOutbox::OnHelpRequest
  388. This is called in response to the WM_HELP Notify
  389. message and to the WM_CONTEXTMENU Notify message.
  390. WM_HELP Notify message.
  391. This message is sent when the user presses F1 or <Shift>-F1
  392. over an item or when the user clicks on the ? icon and then
  393. presses the mouse over an item.
  394. WM_CONTEXTMENU Notify message.
  395. This message is sent when the user right clicks over an item
  396. and then clicks "What's this?"
  397. --*/
  398. /////////////////////////////////////////////////////////////////////////////
  399. LRESULT
  400. CT30ConfigPage::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  401. {
  402. DEBUG_FUNCTION_NAME(_T("CT30ConfigPage::OnHelpRequest"));
  403. ULONG_PTR dwHelpId = 0;
  404. if(WM_HELP == uMsg)
  405. {
  406. dwHelpId = ((LPHELPINFO)lParam)->dwContextId;
  407. }
  408. else if(WM_CONTEXTMENU == uMsg)
  409. {
  410. dwHelpId = ::GetWindowContextHelpId((HWND)wParam);
  411. }
  412. if(dwHelpId)
  413. {
  414. ::WinHelp(m_hWnd,
  415. FXS_ADMIN_HLP_FILE,
  416. HELP_CONTEXTPOPUP,
  417. dwHelpId);
  418. }
  419. return TRUE;
  420. }