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.

444 lines
10 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : DlgSMTPConfig.cpp //
  3. // //
  4. // DESCRIPTION : The CDlgSMTPConfig class implements the //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Jul 20 2000 yossg Create //
  10. // Oct 17 2000 yossg //
  11. // //
  12. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "DlgSMTPConfig.h"
  16. #include "DlgConfirmPassword.h"
  17. #include "FxsValid.h"
  18. #include "dlgutils.h"
  19. #include <htmlHelp.h>
  20. #include <faxreg.h>
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CDlgSMTPConfig
  23. CDlgSMTPConfig::CDlgSMTPConfig()
  24. {
  25. m_fIsPasswordDirty = FALSE;
  26. m_fIsDialogInitiated = FALSE;
  27. }
  28. CDlgSMTPConfig::~CDlgSMTPConfig()
  29. {
  30. }
  31. /*
  32. - CDlgSMTPConfig::InitSmtpDlg
  33. -
  34. * Purpose:
  35. * Initiates the configuration structure from RPC get Call,
  36. * and current assined devices own parameters
  37. *
  38. * Arguments:
  39. *
  40. * Return:
  41. * OLE error code
  42. */
  43. HRESULT CDlgSMTPConfig::InitSmtpDlg (FAX_ENUM_SMTP_AUTH_OPTIONS enumAuthOption, BSTR bstrUserName)
  44. {
  45. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::InitSmtpDlg"));
  46. HRESULT hRc = S_OK;
  47. m_enumAuthOption = enumAuthOption;
  48. m_bstrUserName = bstrUserName;
  49. if (!m_bstrUserName )
  50. {
  51. DebugPrintEx(DEBUG_ERR,
  52. _T("Out of memory - Failed to Init m_bstrUserName. (ec: %0X8)"), hRc);
  53. //MsgBox by Caller Function
  54. hRc = E_OUTOFMEMORY;
  55. goto Exit;
  56. }
  57. ATLASSERT(S_OK == hRc);
  58. Exit:
  59. return hRc;
  60. }
  61. /*
  62. + CDlgSMTPConfig::OnInitDialog
  63. +
  64. * Purpose:
  65. * Initiate all dialog controls.
  66. *
  67. * Arguments:
  68. * [in] uMsg : Value identifying the event.
  69. * [in] lParam : Message-specific value.
  70. * [in] wParam : Message-specific value.
  71. * [in] bHandled : bool value.
  72. *
  73. - Return:
  74. - 0 or 1
  75. */
  76. LRESULT
  77. CDlgSMTPConfig::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  78. {
  79. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::OnInitDialog"));
  80. HRESULT hRc = S_OK;
  81. switch (m_enumAuthOption)
  82. {
  83. case FAX_SMTP_AUTH_ANONYMOUS :
  84. CheckDlgButton(IDC_SMTP_ANONIM_RADIO1, BST_CHECKED);
  85. EnableCredentialsButton(IDC_SMTP_ANONIM_RADIO1);
  86. break;
  87. case FAX_SMTP_AUTH_BASIC :
  88. CheckDlgButton(IDC_SMTP_BASIC_RADIO2, BST_CHECKED);
  89. EnableCredentialsButton(IDC_SMTP_BASIC_RADIO2);
  90. break;
  91. case FAX_SMTP_AUTH_NTLM :
  92. CheckDlgButton(IDC_SMTP_NTLM_RADIO3, BST_CHECKED);
  93. EnableCredentialsButton(IDC_SMTP_NTLM_RADIO3);
  94. break;
  95. default:
  96. ATLASSERT(0);
  97. }
  98. m_fIsDialogInitiated = TRUE;
  99. EnableOK(FALSE);
  100. return 1; // Let the system set the focus
  101. }
  102. /*
  103. + CDlgSMTPConfig::OnOK
  104. +
  105. * Purpose:
  106. * Initiate all dialog controls.
  107. *
  108. * Arguments:
  109. * [in] uMsg : Value identifying the event.
  110. * [in] lParam : Message-specific value.
  111. * [in] wParam : Message-specific value.
  112. * [in] bHandled : bool value.
  113. *
  114. - Return:
  115. - 0 or 1
  116. */
  117. LRESULT
  118. CDlgSMTPConfig::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  119. {
  120. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::OnOK"));
  121. HRESULT hRc = S_OK;
  122. //
  123. // Set data member data
  124. //
  125. if (IsDlgButtonChecked(IDC_SMTP_ANONIM_RADIO1) == BST_CHECKED)
  126. {
  127. m_enumAuthOption = FAX_SMTP_AUTH_ANONYMOUS;
  128. }
  129. else
  130. {
  131. if (IsDlgButtonChecked(IDC_SMTP_NTLM_RADIO3) == BST_CHECKED)
  132. {
  133. m_enumAuthOption = FAX_SMTP_AUTH_NTLM;
  134. }
  135. else // IsDlgButtonChecked(IDC_SMTP_BASIC_RADIO2) == BST_CHECKED
  136. {
  137. m_enumAuthOption = FAX_SMTP_AUTH_BASIC;
  138. }
  139. }
  140. //
  141. // Step 4: Close the dialog
  142. //
  143. ATLASSERT(S_OK == hRc );
  144. EndDialog(wID);
  145. goto Exit;
  146. Exit:
  147. return FAILED(hRc) ? 0 : 1;
  148. }
  149. /*
  150. - CDlgSMTPConfig::EnableCredentialsButton
  151. -
  152. * Purpose:
  153. * Enable/disable Basic Authentication dialog controls.
  154. *
  155. * Arguments:
  156. * [in] iIDC - DWORD value for the radio button selected or the
  157. * radio above the credetials button that should be active.
  158. *
  159. * Return:
  160. * void
  161. */
  162. VOID CDlgSMTPConfig::EnableCredentialsButton(DWORD iIDC)
  163. {
  164. switch (iIDC)
  165. {
  166. case IDC_SMTP_ANONIM_RADIO1:
  167. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_BASIC_BUTTON), FALSE);
  168. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_NTLM_BUTTON), FALSE);
  169. break;
  170. case IDC_SMTP_BASIC_RADIO2:
  171. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_BASIC_BUTTON), TRUE);
  172. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_NTLM_BUTTON), FALSE);
  173. break;
  174. case IDC_SMTP_NTLM_RADIO3:
  175. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_NTLM_BUTTON), TRUE);
  176. ::EnableWindow(GetDlgItem(IDC_SMTP_CREDENTIALS_BASIC_BUTTON), FALSE);
  177. break;
  178. default:
  179. ATLASSERT( 0 ); // Unexpected value
  180. }
  181. }
  182. /*
  183. - CDlgSMTPConfig::OnRadioButtonClicked
  184. -
  185. * Purpose:
  186. * .
  187. *
  188. * Arguments:
  189. *
  190. * Return:
  191. * 1
  192. */
  193. LRESULT
  194. CDlgSMTPConfig::OnRadioButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  195. {
  196. UNREFERENCED_PARAMETER (wNotifyCode);
  197. UNREFERENCED_PARAMETER (hWndCtl);
  198. UNREFERENCED_PARAMETER (bHandled);
  199. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::OnRadioButtonClicked"));
  200. UINT fEnableOK;
  201. if (!m_fIsDialogInitiated) //event receieved in too early stage
  202. {
  203. return 0;
  204. }
  205. //
  206. // Activate OK button
  207. //
  208. if ( IsDlgButtonChecked(IDC_SMTP_ANONIM_RADIO1) == BST_CHECKED )
  209. {
  210. EnableOK(TRUE);
  211. }
  212. else //BASIC or NTLM
  213. {
  214. ATLASSERT(IDC_SMTP_BASIC_RADIO2 == wID || IDC_SMTP_NTLM_RADIO3 == wID );
  215. fEnableOK = ( m_bstrUserName.Length() > 0 );
  216. EnableOK(!!fEnableOK);
  217. }
  218. //
  219. // Activate the proper Credentials button
  220. //
  221. EnableCredentialsButton(wID);
  222. return 0;
  223. }
  224. /*
  225. - CDlgSMTPConfig::OnCredentialsButtonClicked
  226. -
  227. * Purpose:
  228. * Allow edit Credentials for the SMTP server configuration .
  229. *
  230. * Arguments:
  231. *
  232. * Return:
  233. * 1
  234. */
  235. LRESULT CDlgSMTPConfig::OnCredentialsButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  236. {
  237. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::OnCredentialsButtonClicked"));
  238. INT_PTR rc = IDCANCEL;
  239. HRESULT hRc = S_OK;
  240. DWORD dwRet = ERROR_SUCCESS;
  241. CDlgConfirmPassword DlgCredentialsConfig;
  242. //
  243. // Dialog to configure SMTP authentication mode
  244. //
  245. hRc = DlgCredentialsConfig.InitCredentialsDlg(m_bstrUserName);
  246. if (FAILED(hRc))
  247. {
  248. DlgMsgBox(this, IDS_MEMORY);
  249. goto Cleanup;
  250. }
  251. rc = DlgCredentialsConfig.DoModal();
  252. if (rc != IDOK)
  253. {
  254. goto Cleanup;
  255. }
  256. m_bstrUserName = DlgCredentialsConfig.GetUserName();
  257. if (!m_bstrUserName)
  258. {
  259. DebugPrintEx(
  260. DEBUG_ERR,
  261. TEXT("Null memeber BSTR - m_bstrUserName."));
  262. DlgMsgBox(this, IDS_MEMORY);
  263. goto Cleanup;
  264. }
  265. if ( DlgCredentialsConfig.IsPasswordModified() ) //If you got here password was also confirmed
  266. {
  267. m_bstrPassword = DlgCredentialsConfig.GetPassword();
  268. if (!m_bstrPassword)
  269. {
  270. DebugPrintEx(
  271. DEBUG_ERR,
  272. TEXT("Out of memory while setting m_bstrPassword"));
  273. DlgMsgBox(this, IDS_MEMORY);
  274. goto Cleanup;
  275. }
  276. m_fIsPasswordDirty = TRUE;
  277. }
  278. else
  279. {
  280. m_bstrPassword.Empty();
  281. }
  282. EnableOK(TRUE);
  283. Cleanup:
  284. return 1;
  285. }
  286. /*
  287. - CDlgSMTPConfig::EnableOK
  288. -
  289. * Purpose:
  290. * Enable (disable) apply button.
  291. *
  292. * Arguments:
  293. * [in] fEnable - the value to enable the button
  294. *
  295. * Return:
  296. * void
  297. */
  298. VOID
  299. CDlgSMTPConfig::EnableOK(BOOL fEnable)
  300. {
  301. HWND hwndOK = GetDlgItem(IDOK);
  302. ::EnableWindow(hwndOK, fEnable);
  303. }
  304. /*
  305. - CDlgSMTPConfig::OnCancel
  306. -
  307. * Purpose:
  308. * End dialog OnCancel.
  309. *
  310. * Arguments:
  311. *
  312. * Return:
  313. * 0
  314. */
  315. LRESULT
  316. CDlgSMTPConfig::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  317. {
  318. DEBUG_FUNCTION_NAME( _T("CDlgSMTPConfig::OnCancel"));
  319. EndDialog(wID);
  320. return 0;
  321. }
  322. //////////////////////////////////////////////////////////////////////////////
  323. /*++
  324. CDlgSMTPConfig::OnHelpRequest
  325. This is called in response to the WM_HELP Notify
  326. message and to the WM_CONTEXTMENU Notify message.
  327. WM_HELP Notify message.
  328. This message is sent when the user presses F1 or <Shift>-F1
  329. over an item or when the user clicks on the ? icon and then
  330. presses the mouse over an item.
  331. WM_CONTEXTMENU Notify message.
  332. This message is sent when the user right clicks over an item
  333. and then clicks "What's this?"
  334. --*/
  335. /////////////////////////////////////////////////////////////////////////////
  336. LRESULT
  337. CDlgSMTPConfig::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  338. {
  339. DEBUG_FUNCTION_NAME(_T("CDlgSMTPConfig::OnHelpRequest"));
  340. switch (uMsg)
  341. {
  342. case WM_HELP:
  343. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  344. break;
  345. case WM_CONTEXTMENU:
  346. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  347. break;
  348. }
  349. return TRUE;
  350. }
  351. /////////////////////////////////////////////////////////////////////////////