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.

1023 lines
33 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ConfigAlertEmail.cpp
  7. //
  8. // Description:
  9. // implement the class CConfigAlertEmail
  10. //
  11. // Dependency files:
  12. // ConfigAlertEmail.h
  13. //
  14. // History:
  15. // 1. lustar.li (Guogang Li), creation date in 18-DEC-2000
  16. //
  17. // Notes:
  18. //
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include <regstr.h>
  23. #include <comdef.h>
  24. #include <comutil.h>
  25. #include "SetAlertEmail.h"
  26. #include "appliancetask.h"
  27. #include "taskctx.h"
  28. #include "ConfigAlertEmail.h"
  29. #include "appsrvcs.h"
  30. #include "alertemailmsg.h"
  31. //
  32. // Name and parameters for SetAlertEmail Task
  33. //
  34. const WCHAR SET_ALERT_EMAIL_TASK[] = L"SetAlertEmail";
  35. const WCHAR PARAM_ENABLE_ALERT_EMAIL[] = L"EnableAlertEmail";
  36. const WCHAR PARAM_SEND_EMAIL_TYPE[] = L"SendEmailType";
  37. const WCHAR PARAM_RECEIVER_EMAIL_ADDRESS[] = L"ReceiverEmailAddress";
  38. //
  39. // Alert source information
  40. //
  41. const WCHAR ALERT_LOG_NAME[]=L"MSSAKitComm";
  42. const WCHAR ALERT_SOURCE []=L"";
  43. //
  44. // Registry locations
  45. //
  46. const WCHAR REGKEY_SA_ALERTEMAIL[] =
  47. L"Software\\Microsoft\\ServerAppliance\\AlertEmail";
  48. const WCHAR REGSTR_VAL_ENABLE_ALERT_EMAIL[] = L"EnableAlertEmail";
  49. const WCHAR REGSTR_VAL_ALERTEMAIL_RAISEALERT[] = L"RaiseAlert";
  50. const WCHAR REGSTR_VAL_SEND_EMAIL_TYPE[] = L"SendEmailType";
  51. const WCHAR REGSTR_VAL_RECEIVER_EMAIL_ADDRESS[] = L"ReceiverEmailAddress";
  52. //
  53. // Various strings used in the program
  54. //
  55. const WCHAR SZ_METHOD_NAME[]=L"MethodName";
  56. const WCHAR SZ_APPLIANCE_INITIALIZATION_TASK []=L"ApplianceInitializationTask";
  57. ///////////////////////////////////////////////////////////////////////////////
  58. //
  59. // Function: CConfigAlertEmail::OnTaskExecute
  60. //
  61. // Synopsis: This function is the entry point for AppMgr.
  62. //
  63. // Arguments: pTaskContext - The TaskContext object contains the method name
  64. // and parameters as name value pairs
  65. //
  66. // Returns: HRESULT
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. STDMETHODIMP
  70. CConfigAlertEmail::OnTaskExecute(IUnknown *pTaskContext)
  71. {
  72. HRESULT hrRet=E_FAIL;
  73. CComPtr<ITaskContext> pTaskParameters;
  74. SET_ALERT_EMAIL_TASK_TYPE saetChoice;
  75. ASSERT(pTaskContext);
  76. TRACE(("CConfigAlertEmail::OnTaskExecute"));
  77. try
  78. {
  79. do
  80. {
  81. if(NULL == pTaskContext)
  82. {
  83. TRACE("CConfigAlertEmail::OnTaskExecute got NULL pTaskContext");
  84. break;
  85. }
  86. hrRet = pTaskContext->QueryInterface(IID_ITaskContext,
  87. (void **)&pTaskParameters);
  88. if(FAILED(hrRet))
  89. {
  90. TRACE1("CConfigAlertEmail::OnTaskExecute pTaskContext QI failed \
  91. for pTaskParameters, %X",hrRet);
  92. break;
  93. }
  94. // Check which Task is being executed and call that method
  95. saetChoice = GetMethodName(pTaskParameters);
  96. switch (saetChoice)
  97. {
  98. case SET_ALERT_EMAIL:
  99. hrRet = SetAlertEmailSettings(pTaskParameters);
  100. TRACE1(("SetAlertEmailSettings returned %X"), hrRet);
  101. break;
  102. case RAISE_SET_ALERT_EMAIL_ALERT:
  103. //
  104. // Alert will be raised on OnTaskExcute
  105. //
  106. hrRet = S_OK;
  107. TRACE(("RaiseSetAlertEmailAlert method called"));
  108. break;
  109. default:
  110. TRACE("GetMethodName() failed to get method name in OnTaskExecute");
  111. hrRet = E_INVALIDARG;
  112. break;
  113. }
  114. }
  115. while(false);
  116. }
  117. catch(...)
  118. {
  119. TRACE("CConfigAlertEmail::OnTaskExecute caught unknown exception");
  120. hrRet=E_FAIL;
  121. }
  122. TRACE1("CConfigAlertEmail::OnTaskExecute returning %X", hrRet);
  123. return hrRet;
  124. }
  125. //////////////////////////////////////////////////////////////////////////////
  126. //
  127. // Function: CConfigAlertEmail::OnTaskComplete
  128. //
  129. // Synopsis:
  130. //
  131. // Arguments: pTaskContext - The TaskContext object contains the method name
  132. // and parameters as name value pairs
  133. //
  134. // Returns: HRESULT
  135. //
  136. //////////////////////////////////////////////////////////////////////////////
  137. STDMETHODIMP
  138. CConfigAlertEmail::OnTaskComplete(IUnknown *pTaskContext,
  139. LONG lTaskResult)
  140. {
  141. HRESULT hrRet = E_FAIL;
  142. CComPtr<ITaskContext> pTaskParameters;
  143. SET_ALERT_EMAIL_TASK_TYPE saetChoice;
  144. ASSERT(pTaskContext);
  145. TRACE(("CConfigAlertEmail::OnTaskComplete"));
  146. try
  147. {
  148. do
  149. {
  150. hrRet = pTaskContext->QueryInterface(IID_ITaskContext,
  151. (void **)&pTaskParameters);
  152. if (FAILED(hrRet))
  153. {
  154. TRACE1("CConfigAlertEmail::OnTaskComplete failed in pTaskContext \
  155. QI for pTaskParameters, %X", hrRet);
  156. break;
  157. }
  158. //
  159. // Check which Task is being executed and call that method
  160. //
  161. saetChoice = GetMethodName(pTaskParameters);
  162. switch (saetChoice)
  163. {
  164. case SET_ALERT_EMAIL:
  165. if (lTaskResult == SA_TASK_RESULT_COMMIT)
  166. {
  167. //
  168. // Clear any existing CConfigAlertEmail alert,
  169. // do not raise the alert on subsequent boots
  170. //
  171. ClearSetAlertEmailAlert();
  172. DoNotRaiseSetAlertEmailAlert();
  173. TRACE("No rollback in OnTaskComplete");
  174. hrRet = S_OK;
  175. }
  176. else
  177. {
  178. hrRet = RollbackSetAlertEmailSettings(pTaskParameters);
  179. TRACE1(("RollbackSetAlertEmailSettings returned %X"), hrRet);
  180. }
  181. break;
  182. case RAISE_SET_ALERT_EMAIL_ALERT:
  183. if (lTaskResult == SA_TASK_RESULT_COMMIT)
  184. {
  185. if (TRUE == ShouldRaiseSetAlertEmailAlert())
  186. {
  187. hrRet = RaiseSetAlertEmailAlert();
  188. if (FAILED(hrRet))
  189. {
  190. TRACE1(("RaiseSetAlertEmailAlert returned %X"), hrRet);
  191. }
  192. }
  193. else
  194. {
  195. TRACE("No need to raise the alert email alert");
  196. }
  197. }
  198. else
  199. {
  200. //
  201. // Do nothing on Commit failure
  202. //
  203. hrRet = S_OK;
  204. }
  205. break;
  206. default:
  207. TRACE("GetMethodName() failed to get method name in OnTaskComplete");
  208. hrRet = E_INVALIDARG;
  209. break;
  210. }
  211. }
  212. while(false);
  213. }
  214. catch(...)
  215. {
  216. TRACE("CConfigAlertEmail::OnTaskComplete caught unknown exception");
  217. hrRet=E_FAIL;
  218. }
  219. TRACE1("CConfigAlertEmail::OnTaskComplete returning %X", hrRet);
  220. return hrRet;
  221. }
  222. //////////////////////////////////////////////////////////////////////////////
  223. //
  224. // Function: CConfigAlertEmail::RaiseSetAlertEmailAlert
  225. //
  226. // Synopsis: Raises the initial "Alert email not set up" alert during appliance
  227. // initialization
  228. //
  229. // Arguments: None
  230. //
  231. // Returns: HRESULT
  232. //
  233. //////////////////////////////////////////////////////////////////////////////
  234. STDMETHODIMP
  235. CConfigAlertEmail::RaiseSetAlertEmailAlert()
  236. {
  237. CComPtr<IApplianceServices> pAppSrvcs;
  238. DWORD dwAlertType = SA_ALERT_TYPE_ATTENTION;
  239. DWORD dwAlertId = SA_ALERTEMAIL_SETTINGS_NOTSET_ALERT_CAPTION;
  240. HRESULT hrRet = E_FAIL;
  241. _bstr_t bstrAlertLog(ALERT_LOG_NAME);
  242. _bstr_t bstrAlertSource(ALERT_SOURCE);
  243. _variant_t varReplacementStrings;
  244. _variant_t varRawData;
  245. LONG lCookie;
  246. TRACE("Entering RaiseSetAlertEmailAlert");
  247. try
  248. {
  249. do
  250. {
  251. hrRet = CoCreateInstance(CLSID_ApplianceServices,
  252. NULL,
  253. CLSCTX_INPROC_SERVER,
  254. IID_IApplianceServices,
  255. (void**)&pAppSrvcs);
  256. if (FAILED(hrRet))
  257. {
  258. ASSERTMSG(FALSE,
  259. L"RaiseSetAlertEmailAlert failed at CoCreateInstance");
  260. TRACE1("RaiseSetAlertEmailAlert failed at CoCreateInstance, %x",
  261. hrRet);
  262. break;
  263. }
  264. ASSERT(pAppSrvcs);
  265. //
  266. // Initialize() is called prior to using other component services.
  267. //Performscomponent initialization operations.
  268. //
  269. hrRet = pAppSrvcs->Initialize();
  270. if (FAILED(hrRet))
  271. {
  272. ASSERTMSG(FALSE,
  273. L"RaiseSetAlertEmailAlert failed at pAppSrvcs->Initialize");
  274. TRACE1("RaiseSetAlertEmailAlert failed at pAppSrvcs->Initialize, %x",
  275. hrRet);
  276. break;
  277. }
  278. hrRet = pAppSrvcs->RaiseAlert(
  279. dwAlertType,
  280. dwAlertId,
  281. bstrAlertLog,
  282. bstrAlertSource,
  283. SA_ALERT_DURATION_ETERNAL,
  284. &varReplacementStrings,
  285. &varRawData,
  286. &lCookie
  287. );
  288. if (FAILED(hrRet))
  289. {
  290. ASSERTMSG(FALSE,
  291. TEXT("RaiseSetAlertEmailAlert failed at pAppSrvcs->RaiseAlert"));
  292. TRACE1("RaiseSetAlertEmailAlert failed at pAppSrvcs->RaiseAlert, %x",
  293. hrRet);
  294. break;
  295. }
  296. }
  297. while(false);
  298. }
  299. catch(...)
  300. {
  301. TRACE("CConfigAlertEmail::RaiseSetAlertEmailAlert exception caught");
  302. hrRet=E_FAIL;
  303. }
  304. return hrRet;
  305. }
  306. //////////////////////////////////////////////////////////////////////////////
  307. //
  308. // Function: CConfigAlertEmail::ShouldRaiseSetAlertEmailAlert
  309. //
  310. // Synopsis: Returns TRUE if the alert needs to be raised. Reads RaiseAlert
  311. // regkey to determine this.
  312. //
  313. // Arguments: None
  314. //
  315. // Returns: BOOL
  316. //
  317. //////////////////////////////////////////////////////////////////////////////
  318. BOOL
  319. CConfigAlertEmail::ShouldRaiseSetAlertEmailAlert()
  320. {
  321. LONG lReturnValue;
  322. HKEY hKey = NULL;
  323. DWORD dwSize, dwType, dwRaiseAlertEmailAlert = 0;
  324. BOOL bReturnCode = TRUE;
  325. TRACE("ShouldRaiseSetAlertEmailAlert");
  326. do
  327. {
  328. //
  329. // Open HKLM\Software\Microsoft\ServerAppliance\AlertEmail reg key
  330. //
  331. lReturnValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  332. REGKEY_SA_ALERTEMAIL,
  333. 0,
  334. KEY_READ,
  335. &hKey);
  336. if (lReturnValue != ERROR_SUCCESS)
  337. {
  338. TRACE1("RegOpenKeyEx failed with %X", lReturnValue);
  339. bReturnCode=FALSE;
  340. break;
  341. }
  342. //
  343. // Read the RaiseAlert reg key
  344. //
  345. dwSize = sizeof(DWORD);
  346. lReturnValue = RegQueryValueEx(hKey,
  347. REGSTR_VAL_ALERTEMAIL_RAISEALERT,
  348. 0,
  349. &dwType,
  350. (LPBYTE) &dwRaiseAlertEmailAlert,
  351. &dwSize);
  352. if (lReturnValue != ERROR_SUCCESS)
  353. {
  354. TRACE2("RegQueryValueEx of %ws failed with %X",
  355. REGSTR_VAL_ALERTEMAIL_RAISEALERT, lReturnValue);
  356. bReturnCode=FALSE;
  357. break;
  358. }
  359. if (0 == dwRaiseAlertEmailAlert)
  360. {
  361. bReturnCode = FALSE;
  362. }
  363. }
  364. while(false);
  365. if (NULL != hKey)
  366. {
  367. RegCloseKey(hKey);
  368. }
  369. return bReturnCode;
  370. }
  371. ///////////////////////////////////////////////////////////////////////////////
  372. //
  373. // Function: CConfigAlertEmail::DoNotRaiseSetAlertEmailAlert
  374. //
  375. // Synopsis: After alert email is setup the initial "Alert email not set up"
  376. // alert needs to be disabled. This function sets the RaiseAlert regkey
  377. // to 0 to prevent the alert to be raised.
  378. //
  379. // Arguments: None
  380. //
  381. // Returns: BOOL
  382. //
  383. ///////////////////////////////////////////////////////////////////////////////
  384. BOOL
  385. CConfigAlertEmail::DoNotRaiseSetAlertEmailAlert()
  386. {
  387. LONG lReturnValue;
  388. HKEY hKey = NULL;
  389. DWORD dwDisposition, dwRaiseAlertEmailAlert = 0;
  390. BOOL bReturnCode = FALSE;
  391. TRACE("Entering DoNotRaiseSetAlertEmailAlert");
  392. //
  393. // Write Settings to registry
  394. //
  395. do
  396. {
  397. lReturnValue = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  398. REGKEY_SA_ALERTEMAIL,
  399. 0,
  400. NULL,
  401. REG_OPTION_NON_VOLATILE,
  402. KEY_ALL_ACCESS,
  403. NULL,
  404. &hKey,
  405. &dwDisposition);
  406. if (lReturnValue != ERROR_SUCCESS)
  407. {
  408. TRACE1("RegCreateKeyEx failed with %X", lReturnValue);
  409. break;
  410. }
  411. //
  412. // Set RaiseAlert value to 0
  413. //
  414. dwRaiseAlertEmailAlert = 0;
  415. lReturnValue = RegSetValueEx(hKey,
  416. REGSTR_VAL_ALERTEMAIL_RAISEALERT,
  417. 0,
  418. REG_DWORD,
  419. (LPBYTE) &dwRaiseAlertEmailAlert,
  420. sizeof(DWORD));
  421. if (lReturnValue != ERROR_SUCCESS)
  422. {
  423. TRACE2("RegSetValueEx of %ws failed with %X",
  424. REGSTR_VAL_ALERTEMAIL_RAISEALERT, lReturnValue);
  425. break;
  426. }
  427. else
  428. {
  429. bReturnCode = TRUE;
  430. }
  431. }
  432. while(false);
  433. if (NULL != hKey)
  434. {
  435. RegCloseKey(hKey);
  436. }
  437. return bReturnCode;
  438. }
  439. //////////////////////////////////////////////////////////////////////////////
  440. //
  441. // Function: CConfigAlertEmail::ClearSetAlertEmailAlert
  442. //
  443. // Synopsis: Clear the alert email alert
  444. //
  445. // Arguments: NONE
  446. //
  447. // Returns: BOOL
  448. //
  449. //////////////////////////////////////////////////////////////////////////////
  450. BOOL
  451. CConfigAlertEmail::ClearSetAlertEmailAlert()
  452. {
  453. CComPtr<IApplianceServices> pAppSrvcs;
  454. HRESULT hrRet = E_FAIL;
  455. _bstr_t bstrAlertLog(ALERT_LOG_NAME);
  456. BOOL bReturnCode = FALSE;
  457. TRACE("ClearSetAlertEmailAlert");
  458. try
  459. {
  460. do
  461. {
  462. hrRet = CoCreateInstance(CLSID_ApplianceServices,
  463. NULL,
  464. CLSCTX_INPROC_SERVER,
  465. IID_IApplianceServices,
  466. (void**)&pAppSrvcs);
  467. if (FAILED(hrRet))
  468. {
  469. ASSERTMSG(FALSE,
  470. L"ClearSetAlertEmailAlert failed at CoCreateInstance");
  471. TRACE1("ClearSetAlertEmailAlert failed at CoCreateInstance, %x",
  472. hrRet);
  473. break;
  474. }
  475. ASSERT(pAppSrvcs);
  476. hrRet = pAppSrvcs->Initialize();
  477. if (FAILED(hrRet))
  478. {
  479. ASSERTMSG(FALSE,
  480. L"ClearSetAlertEmailAlert failed at pAppSrvcs->Initialize");
  481. TRACE1("ClearSetAlertEmailAlert failed at pAppSrvcs->Initialize, %x",
  482. hrRet);
  483. break;
  484. }
  485. //
  486. // Clear the Setup Chime Settings alert
  487. //
  488. hrRet = pAppSrvcs->ClearAlertAll(
  489. SA_ALERTEMAIL_SETTINGS_NOTSET_ALERT_CAPTION,
  490. bstrAlertLog
  491. );
  492. //
  493. // DISP_E_MEMBERNOTFOUND means that there were no matching alerts
  494. //
  495. if ((hrRet != DISP_E_MEMBERNOTFOUND) && (FAILED(hrRet)))
  496. {
  497. ASSERTMSG(FALSE,
  498. TEXT("ClearSetAlertEmailAlert failed at pAppSrvcs->RaiseAlert"));
  499. TRACE1("ClearSetAlertEmailAlert failed at pAppSrvcs->RaiseAlert, %x",
  500. hrRet);
  501. }
  502. else
  503. {
  504. bReturnCode = TRUE;
  505. }
  506. }
  507. while(false);
  508. }
  509. catch(...)
  510. {
  511. TRACE("CConfigAlertEmail::ClearSetAlertEmailAlert caught unknown exception");
  512. bReturnCode=FALSE;
  513. }
  514. return bReturnCode;
  515. }
  516. //////////////////////////////////////////////////////////////////////////////
  517. //
  518. // Function: CConfigAlertEmail::SetAlertEmailSettings
  519. //
  520. // Synopsis: Writes alert email settings passed by task context to registry
  521. //
  522. // Arguments: pTaskContext - The TaskContext object contains the method name
  523. // and parameters as name value pairs
  524. //
  525. // Returns: HRESULT
  526. //
  527. //////////////////////////////////////////////////////////////////////////////
  528. STDMETHODIMP
  529. CConfigAlertEmail::SetAlertEmailSettings(
  530. ITaskContext *pTaskContext
  531. )
  532. {
  533. HRESULT hrRet=E_FAIL;
  534. LONG lResult;
  535. CRegKey crKey;
  536. DWORD dwDisposition;
  537. DWORD dwCount=MAX_MAIL_ADDRESS_LENGH;
  538. BOOL bEnableAlertEmail=0;
  539. DWORD dwSendEmailType = 0;
  540. _bstr_t bstrReceriverEmailAddress;
  541. ASSERT(pTaskContext);
  542. try
  543. {
  544. do
  545. {
  546. //
  547. // Get all parameters from the TaskContext object
  548. //
  549. hrRet = GetSetAlertEmailSettingsParameters(
  550. pTaskContext,
  551. &bEnableAlertEmail,
  552. &dwSendEmailType,
  553. &bstrReceriverEmailAddress
  554. );
  555. if (S_OK != hrRet)
  556. {
  557. break;
  558. }
  559. //
  560. // Save current values - this will be used to restore the settings
  561. // if this task needs to be rolledback
  562. //
  563. lResult = crKey.Open(
  564. HKEY_LOCAL_MACHINE,
  565. REGKEY_SA_ALERTEMAIL,
  566. KEY_ALL_ACCESS
  567. );
  568. if (ERROR_SUCCESS == lResult)
  569. {
  570. if (ERROR_SUCCESS != crKey.QueryValue(m_bEnableAlertEmail,
  571. REGSTR_VAL_ENABLE_ALERT_EMAIL))
  572. {
  573. //
  574. // Could be due to bad setup - let log it and continue on
  575. //
  576. TRACE2("QueryValue of %ws failed in SetAlertEmailSettings, \
  577. %x", REGSTR_VAL_ENABLE_ALERT_EMAIL, lResult);
  578. }
  579. if (ERROR_SUCCESS != crKey.QueryValue(m_dwSendEmailType,
  580. REGSTR_VAL_SEND_EMAIL_TYPE))
  581. {
  582. //
  583. // Could be due to bad setup - let log it and continue on
  584. //
  585. TRACE2("QueryValue of %ws failed in SetChimeSettings, %x",
  586. REGSTR_VAL_SEND_EMAIL_TYPE, lResult);
  587. }
  588. if (ERROR_SUCCESS != crKey.QueryValue(m_szReceiverMailAddress,
  589. REGSTR_VAL_RECEIVER_EMAIL_ADDRESS,
  590. &dwCount))
  591. {
  592. //
  593. // Could be due to bad setup - let log it and continue on
  594. //
  595. TRACE2("QueryValue of %ws failed in ReceiverMailAddress, %x",
  596. REGSTR_VAL_RECEIVER_EMAIL_ADDRESS, lResult);
  597. }
  598. }
  599. else
  600. {
  601. //
  602. // If we couldn't open the key, it probably because the key does
  603. // not exist. Let's create it
  604. //
  605. lResult = crKey.Create(HKEY_LOCAL_MACHINE,
  606. REGKEY_SA_ALERTEMAIL,
  607. NULL,
  608. REG_OPTION_NON_VOLATILE,
  609. KEY_ALL_ACCESS,
  610. NULL,
  611. &dwDisposition);
  612. if (ERROR_SUCCESS != lResult)
  613. {
  614. TRACE1("Create failed in CConfigAlertEmail::SetAlertEmailSettings, \
  615. %x", lResult);
  616. hrRet=HRESULT_FROM_WIN32(lResult);
  617. break;
  618. }
  619. }
  620. //
  621. // Set the new values
  622. //
  623. lResult = crKey.SetValue(bEnableAlertEmail, REGSTR_VAL_ENABLE_ALERT_EMAIL);
  624. if (ERROR_SUCCESS != lResult)
  625. {
  626. TRACE2("SetValue of %ws failed, %x", REGSTR_VAL_ENABLE_ALERT_EMAIL,
  627. lResult);
  628. hrRet=HRESULT_FROM_WIN32(lResult);
  629. break;
  630. }
  631. lResult = crKey.SetValue(dwSendEmailType, REGSTR_VAL_SEND_EMAIL_TYPE);
  632. if (ERROR_SUCCESS != lResult)
  633. {
  634. TRACE2("SetValue of %ws failed, %x", REGSTR_VAL_SEND_EMAIL_TYPE,
  635. lResult);
  636. hrRet=HRESULT_FROM_WIN32(lResult);
  637. break;
  638. }
  639. lResult = crKey.SetValue(bstrReceriverEmailAddress,
  640. REGSTR_VAL_RECEIVER_EMAIL_ADDRESS);
  641. if (ERROR_SUCCESS != lResult)
  642. {
  643. TRACE2("SetValue of %ws failed, %x",
  644. REGSTR_VAL_RECEIVER_EMAIL_ADDRESS, lResult);
  645. hrRet=HRESULT_FROM_WIN32(lResult);
  646. break;
  647. }
  648. hrRet = S_OK;
  649. }
  650. while(false);
  651. }
  652. catch(...)
  653. {
  654. TRACE("CConfigAlertEmail::SetAlertEmailSettings caught unknown exception");
  655. hrRet=E_FAIL;
  656. }
  657. return hrRet;
  658. }
  659. //////////////////////////////////////////////////////////////////////////////
  660. //
  661. // Function: CConfigAlertEmail::RollbackSetAlertEmailSettings
  662. //
  663. // Synopsis:
  664. //
  665. // Arguments: pTaskContext - The TaskContext object contains the method name
  666. // and parameters as name value pairs
  667. //
  668. // Returns: HRESULT
  669. //
  670. //////////////////////////////////////////////////////////////////////////////
  671. STDMETHODIMP
  672. CConfigAlertEmail::RollbackSetAlertEmailSettings(
  673. ITaskContext *pTaskContext
  674. )
  675. {
  676. CRegKey crKey;
  677. LONG lResult;
  678. HRESULT hrRet = S_OK;
  679. ASSERT(pTaskContext);
  680. try
  681. {
  682. do
  683. {
  684. lResult = crKey.Open(HKEY_LOCAL_MACHINE,
  685. REGKEY_SA_ALERTEMAIL,
  686. KEY_WRITE);
  687. if (ERROR_SUCCESS != lResult)
  688. {
  689. TRACE1("CConfigAlertEmail::RollbackSetAlertEmailSettings failed \
  690. to open Chime regkey, %d",lResult);
  691. hrRet=HRESULT_FROM_WIN32(lResult);
  692. break;
  693. }
  694. //
  695. // Restore the old values
  696. //
  697. lResult = crKey.SetValue(m_bEnableAlertEmail, REGSTR_VAL_ENABLE_ALERT_EMAIL);
  698. if (ERROR_SUCCESS != lResult)
  699. {
  700. TRACE2("SetValue of %ws failed, %x", REGSTR_VAL_ENABLE_ALERT_EMAIL,
  701. lResult);
  702. hrRet=HRESULT_FROM_WIN32(lResult);
  703. break;
  704. }
  705. lResult = crKey.SetValue(m_dwSendEmailType, REGSTR_VAL_SEND_EMAIL_TYPE);
  706. if (ERROR_SUCCESS != lResult)
  707. {
  708. TRACE2("SetValue of %ws failed, %x", REGSTR_VAL_SEND_EMAIL_TYPE,
  709. lResult);
  710. hrRet=HRESULT_FROM_WIN32(lResult);
  711. break;
  712. }
  713. lResult = crKey.SetValue(m_szReceiverMailAddress,
  714. REGSTR_VAL_RECEIVER_EMAIL_ADDRESS);
  715. if (ERROR_SUCCESS != lResult)
  716. {
  717. TRACE2("SetValue of %ws failed, %x", REGSTR_VAL_RECEIVER_EMAIL_ADDRESS,
  718. lResult);
  719. hrRet=HRESULT_FROM_WIN32(lResult);
  720. break;
  721. }
  722. hrRet = S_OK;
  723. }
  724. while(false);
  725. }
  726. catch(...)
  727. {
  728. TRACE("CConfigAlertEmail::RollbackSetAlertEmailSettings caught unknown \
  729. exception");
  730. hrRet=E_FAIL;
  731. }
  732. return hrRet;
  733. }
  734. //////////////////////////////////////////////////////////////////////////////
  735. //
  736. // Function: CConfigAlertEmail::GetSetAlertEmailSettingsParameters
  737. //
  738. // Synopsis: Extracts AlertEmail settings parameters from task context
  739. //
  740. // Arguments: pTaskContext - The TaskContext object contains the method name
  741. // and parameters as name value pairs
  742. // pbEnableAlertEmail - Enable send alert email
  743. // pdwSendEmailType - Sent email type
  744. // pbstrMailAddress - Receiver email address
  745. //
  746. // Returns: HRESULT
  747. //
  748. //////////////////////////////////////////////////////////////////////////////
  749. STDMETHODIMP
  750. CConfigAlertEmail::GetSetAlertEmailSettingsParameters(
  751. ITaskContext *pTaskContext,
  752. BOOL *pbEnableAlertEmail,
  753. DWORD *pdwSendEmailType,
  754. _bstr_t *pbstrMailAddress
  755. )
  756. {
  757. HRESULT hrRet = S_OK;
  758. _variant_t varValue;
  759. _bstr_t bstrParamEnableAlertEmail(PARAM_ENABLE_ALERT_EMAIL);
  760. _bstr_t bstrParamSendEmailType(PARAM_SEND_EMAIL_TYPE);
  761. _bstr_t bstrParamReceiverEmailAddress(PARAM_RECEIVER_EMAIL_ADDRESS);
  762. ASSERT(pTaskContext && pbEnableAlertEmail && pdwSendEmailType&&
  763. pbstrMailAddress);
  764. //
  765. // Retrieve Parameters from TaskContext
  766. //
  767. try
  768. {
  769. do
  770. {
  771. //
  772. // Retrieve EnableAlertEmail from TaskContext
  773. //
  774. VariantClear(&varValue);
  775. hrRet = pTaskContext->GetParameter(bstrParamEnableAlertEmail,
  776. &varValue);
  777. if(FAILED(hrRet))
  778. {
  779. TRACE1("CConfigAlertEmail::GetSetAlertEmailSettingsParameters \
  780. failed in GetParameters, %X",hrRet);
  781. break;
  782. }
  783. if (V_VT(&varValue) != VT_BSTR)
  784. {
  785. TRACE2(("Non-BSTR (%X) parameter received for %ws in \
  786. GetParameter in CConfigAlertEmail:GetSetAlertEmailSettings\
  787. Parameters"), V_VT(&varValue), PARAM_ENABLE_ALERT_EMAIL);
  788. hrRet = E_INVALIDARG;
  789. break;
  790. }
  791. *pbEnableAlertEmail = _ttoi(V_BSTR(&varValue));
  792. //
  793. // Retrieve SendEmailType from TaskContext
  794. //
  795. VariantClear(&varValue);
  796. hrRet = pTaskContext->GetParameter(bstrParamSendEmailType,
  797. &varValue);
  798. if(FAILED(hrRet))
  799. {
  800. TRACE1("CConfigAlertEmail::GetSetAlertEmailSettings failed \
  801. in GetParameters, %X",hrRet);
  802. break;
  803. }
  804. if (V_VT(&varValue) != VT_BSTR)
  805. {
  806. TRACE2(("Non-BSTR(%X) parameter received for %ws in \
  807. GetParameter in CConfigAlertEmail::GetSetAlertEmailSettings"),
  808. V_VT(&varValue), PARAM_SEND_EMAIL_TYPE);
  809. hrRet = E_INVALIDARG;
  810. break;
  811. }
  812. *pdwSendEmailType = _ttol(V_BSTR(&varValue));
  813. //
  814. // Retrieve ReceiverEmailAddress from TaskContext
  815. //
  816. VariantClear(&varValue);
  817. hrRet = pTaskContext->GetParameter(bstrParamReceiverEmailAddress,
  818. &varValue);
  819. if(FAILED(hrRet))
  820. {
  821. TRACE1("CConfigAlertEmail::GetSetAlertEmailSettings failed \
  822. in GetParameters, %X",hrRet);
  823. break;
  824. }
  825. if (V_VT(&varValue) != VT_BSTR)
  826. {
  827. TRACE2(("Non-String(%X) parameter received for %ws in \
  828. GetParameter in CConfigAlertEmail::GetSetAlertEmailSettings"),
  829. V_VT(&varValue), PARAM_RECEIVER_EMAIL_ADDRESS);
  830. hrRet = E_INVALIDARG;
  831. break;
  832. }
  833. *pbstrMailAddress = V_BSTR(&varValue);
  834. TRACE1(("EnableAlertEmail = 0x%x"),*pbEnableAlertEmail);
  835. TRACE1(("SendEmailType = 0x%x"), *pdwSendEmailType);
  836. TRACE1(("ReceiverEmailAddress = %ws"), *pbstrMailAddress);
  837. }
  838. while(false);
  839. }
  840. catch(...)
  841. {
  842. TRACE1("CConfigAlertEmail::GetSetAlertEmailSettings exception caught",
  843. hrRet);
  844. hrRet=E_FAIL;
  845. }
  846. return hrRet;
  847. }
  848. /////////////////////////////////////////////////////////////////////////////
  849. //
  850. // Function: CConfigAlertEmail::GetMethodName
  851. //
  852. // Synopsis:
  853. //
  854. // Arguments: pTaskContext - The TaskContext object contains the method name
  855. // and parameters as name value pairs
  856. //
  857. // Returns: SET_CHIME_SETTINGS_TASK_TYPE
  858. //
  859. /////////////////////////////////////////////////////////////////////////////
  860. SET_ALERT_EMAIL_TASK_TYPE
  861. CConfigAlertEmail::GetMethodName(ITaskContext *pTaskParameter)
  862. {
  863. HRESULT hrRet;
  864. _variant_t varValue;
  865. _bstr_t bstrParamName(SZ_METHOD_NAME);
  866. SET_ALERT_EMAIL_TASK_TYPE saetChoice = NONE_FOUND;
  867. ASSERT(pTaskParameter);
  868. try
  869. {
  870. do
  871. {
  872. hrRet = pTaskParameter->GetParameter(bstrParamName,
  873. &varValue);
  874. if (FAILED(hrRet))
  875. {
  876. TRACE1(("GetParameter failed in CConfigAlertEmail::Ge \
  877. tMethodName %X"), hrRet);
  878. }
  879. if (V_VT(&varValue) != VT_BSTR)
  880. {
  881. TRACE1(("Non-strint(%X) parameter received in GetParameter \
  882. in CConfigAlertEmail::GetMethodName"), V_VT(&varValue));
  883. hrRet = E_INVALIDARG;
  884. break;
  885. }
  886. if (lstrcmp(V_BSTR(&varValue), SET_ALERT_EMAIL_TASK) == 0)
  887. {
  888. saetChoice = SET_ALERT_EMAIL;
  889. break;
  890. }
  891. if (lstrcmp(V_BSTR(&varValue),SZ_APPLIANCE_INITIALIZATION_TASK)==0)
  892. {
  893. saetChoice = RAISE_SET_ALERT_EMAIL_ALERT;
  894. break;
  895. }
  896. }
  897. while(false);
  898. }
  899. catch(...)
  900. {
  901. TRACE("SET_ALERT_EMAIL_TASK::GetMethodName caught unknown exception");
  902. hrRet=E_FAIL;
  903. }
  904. if (FAILED(hrRet))
  905. {
  906. saetChoice = NONE_FOUND;
  907. }
  908. return saetChoice;
  909. }