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.

598 lines
14 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Registry.c
  5. Abstract:
  6. Environment:
  7. Fax driver
  8. Revision History:
  9. 10/13/99 -v-sashab-
  10. Created it.
  11. --*/
  12. #include "faxui.h"
  13. #include "Registry.h"
  14. #include "faxreg.h"
  15. #include "registry.h"
  16. #include "faxlib.h"
  17. HRESULT
  18. SaveLastReciptInfo(
  19. DWORD dwReceiptDeliveryType,
  20. LPTSTR szReceiptAddress
  21. )
  22. /*++
  23. Routine Description:
  24. Save the information about the last recipt in the registry
  25. Arguments:
  26. dwReceiptDeliveryType - specifice delivery type: REGVAL_RECEIPT_MSGBOX, REGVAL_RECEIPT_EMAIL, REGVAL_RECEIPT_NO_RECEIPT
  27. szReceiptDeliveryProfile - specifies delivery profile (e-mail address)
  28. Return Value:
  29. S_OK - if success
  30. E_FAIL - otherwise
  31. --*/
  32. {
  33. HKEY hRegKey = NULL;
  34. HRESULT hResult = S_OK;
  35. if (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO, TRUE,REG_READWRITE) )
  36. {
  37. if (dwReceiptDeliveryType == DRT_NONE)
  38. {
  39. SetRegistryDword(hRegKey, REGVAL_RECEIPT_NO_RECEIPT, 1);
  40. }
  41. else
  42. {
  43. SetRegistryDword(hRegKey, REGVAL_RECEIPT_NO_RECEIPT, 0);
  44. }
  45. if (dwReceiptDeliveryType & DRT_GRP_PARENT)
  46. {
  47. SetRegistryDword(hRegKey, REGVAL_RECEIPT_GRP_PARENT, 1);
  48. }
  49. else
  50. {
  51. SetRegistryDword(hRegKey, REGVAL_RECEIPT_GRP_PARENT, 0);
  52. }
  53. if (dwReceiptDeliveryType & DRT_MSGBOX)
  54. {
  55. SetRegistryDword(hRegKey, REGVAL_RECEIPT_MSGBOX, 1);
  56. }
  57. else
  58. {
  59. SetRegistryDword(hRegKey, REGVAL_RECEIPT_MSGBOX, 0);
  60. }
  61. if (dwReceiptDeliveryType & DRT_EMAIL)
  62. {
  63. SetRegistryDword(hRegKey, REGVAL_RECEIPT_EMAIL, 1);
  64. }
  65. else
  66. {
  67. SetRegistryDword(hRegKey, REGVAL_RECEIPT_EMAIL, 0);
  68. }
  69. if (dwReceiptDeliveryType & DRT_ATTACH_FAX)
  70. {
  71. SetRegistryDword(hRegKey, REGVAL_RECEIPT_ATTACH_FAX, 1);
  72. }
  73. else
  74. {
  75. SetRegistryDword(hRegKey, REGVAL_RECEIPT_ATTACH_FAX, 0);
  76. }
  77. if ((dwReceiptDeliveryType & DRT_EMAIL) && szReceiptAddress)
  78. {
  79. //
  80. // Save profile (address) only for mail receipt types
  81. //
  82. // if this function failes, it prints a warning message inside
  83. SetRegistryString(hRegKey, REGVAL_RECEIPT_ADDRESS, szReceiptAddress);
  84. }
  85. RegCloseKey(hRegKey);
  86. }
  87. else
  88. {
  89. Error(("SaveLastReciptInfo: Can't open registry for READ/WRITE\n"));
  90. hResult = E_FAIL;
  91. }
  92. return hResult;
  93. }
  94. HRESULT
  95. RestoreLastReciptInfo(
  96. DWORD * pdwReceiptDeliveryType,
  97. LPTSTR * lpptReceiptAddress
  98. )
  99. /*++
  100. Routine Description:
  101. Restores the information about the last receipt from the registry
  102. Arguments:
  103. pdwReceiptDeliveryType - specifice delivery type: REGVAL_RECEIPT_MSGBOX, REGVAL_RECEIPT_EMAIL, REGVAL_RECEIPT_NO_RECEIPT
  104. szReceiptDeliveryProfile - specifies delivery profile (e-mail address)
  105. Return Value:
  106. S_OK - if success
  107. E_FAIL - otherwise
  108. --*/
  109. {
  110. HKEY hRegKey = NULL;
  111. HRESULT hResult = S_OK;
  112. Assert(pdwReceiptDeliveryType);
  113. Assert(lpptReceiptAddress);
  114. *pdwReceiptDeliveryType = DRT_NONE;
  115. *lpptReceiptAddress = NULL;
  116. if ((hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READWRITE)))
  117. {
  118. if (!GetRegistryDword(hRegKey, REGVAL_RECEIPT_NO_RECEIPT) &&
  119. !GetRegistryDword(hRegKey, REGVAL_RECEIPT_GRP_PARENT) &&
  120. !GetRegistryDword(hRegKey, REGVAL_RECEIPT_MSGBOX) &&
  121. !GetRegistryDword(hRegKey, REGVAL_RECEIPT_EMAIL))
  122. {
  123. Verbose (("RestoreLastReciptInfo runs for the very first time\n"));
  124. }
  125. else
  126. {
  127. if (GetRegistryDword(hRegKey, REGVAL_RECEIPT_GRP_PARENT) == 1)
  128. {
  129. *pdwReceiptDeliveryType |= DRT_GRP_PARENT;
  130. }
  131. if (GetRegistryDword(hRegKey, REGVAL_RECEIPT_MSGBOX) == 1)
  132. {
  133. *pdwReceiptDeliveryType |= DRT_MSGBOX;
  134. }
  135. if (GetRegistryDword(hRegKey, REGVAL_RECEIPT_EMAIL) == 1)
  136. {
  137. *pdwReceiptDeliveryType |= DRT_EMAIL;
  138. }
  139. if (GetRegistryDword(hRegKey, REGVAL_RECEIPT_ATTACH_FAX) == 1)
  140. {
  141. *pdwReceiptDeliveryType |= DRT_ATTACH_FAX;
  142. }
  143. if (!(*lpptReceiptAddress = GetRegistryString(hRegKey, REGVAL_RECEIPT_ADDRESS, TEXT(""))))
  144. {
  145. Error(("Memory allocation failed\n"));
  146. hResult = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  147. goto error;
  148. }
  149. }
  150. RegCloseKey(hRegKey);
  151. }
  152. else
  153. {
  154. Error(("SaveLastReciptInfo: Can't open registry for READ/WRITE\n"));
  155. hResult = E_FAIL;
  156. goto error;
  157. }
  158. goto exit;
  159. error:
  160. if (hRegKey)
  161. {
  162. RegCloseKey(hRegKey);
  163. }
  164. if (*lpptReceiptAddress)
  165. {
  166. MemFree(*lpptReceiptAddress);
  167. }
  168. exit:
  169. return hResult;
  170. }
  171. HRESULT
  172. SaveLastRecipientInfo(
  173. PFAX_PERSONAL_PROFILE pfppRecipient,
  174. DWORD dwLastRecipientCountryId
  175. )
  176. /*++
  177. Routine Description:
  178. Save the information about the last recipient in the registry
  179. Arguments:
  180. pfppRecipient [in] - Recipient personal info
  181. dwLastRecipientCountryId [in] - Last recipient country ID
  182. Return Value:
  183. S_OK - if success
  184. E_FAIL - otherwise
  185. --*/
  186. {
  187. HKEY hRegKey = NULL;
  188. HRESULT hResult = S_OK;
  189. Assert(pfppRecipient);
  190. if (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO, TRUE,REG_READWRITE) )
  191. {
  192. SetRegistryString(hRegKey, REGVAL_LAST_RECNAME, pfppRecipient->lptstrName);
  193. SetRegistryString(hRegKey, REGVAL_LAST_RECNUMBER, pfppRecipient->lptstrFaxNumber);
  194. SetRegistryDword( hRegKey, REGVAL_LAST_COUNTRYID, dwLastRecipientCountryId);
  195. RegCloseKey(hRegKey);
  196. }
  197. else
  198. {
  199. Error(("SaveLastRecipientInfo: Can't open registry for READ/WRITE\n"));
  200. hResult = E_FAIL;
  201. }
  202. return hResult;
  203. }
  204. HRESULT
  205. RestoreLastRecipientInfo(
  206. DWORD* pdwNumberOfRecipients,
  207. PFAX_PERSONAL_PROFILE* lppFaxSendWizardData,
  208. DWORD* pdwLastRecipientCountryId
  209. )
  210. /*++
  211. Routine Description:
  212. Restores the information about the last recipient from the registry
  213. Arguments:
  214. pdwNumberOfRecipients [out] - Number of recipients
  215. lppFaxSendWizardData [out] - Recipient personal info
  216. pdwLastRecipientCountryId [out] - Last recipient country ID
  217. Return Value:
  218. S_OK - if success
  219. E_FAIL - otherwise
  220. --*/
  221. {
  222. HKEY hRegKey = NULL;
  223. LPTSTR lptstrName = NULL, lptstrFaxNumber = NULL;
  224. HRESULT hResult = S_OK;
  225. //
  226. // validate parameters
  227. //
  228. Assert (pdwNumberOfRecipients);
  229. Assert (lppFaxSendWizardData);
  230. Assert (pdwLastRecipientCountryId);
  231. *pdwNumberOfRecipients = 0;
  232. *lppFaxSendWizardData = NULL;
  233. *pdwLastRecipientCountryId = 0;
  234. if (hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READONLY))
  235. {
  236. if (!(lptstrName = GetRegistryString(hRegKey, REGVAL_LAST_RECNAME, TEXT(""))) ||
  237. !(lptstrFaxNumber = GetRegistryString(hRegKey, REGVAL_LAST_RECNUMBER, TEXT(""))))
  238. {
  239. Error(("GetRegistryString failed\n"));
  240. hResult = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  241. goto error;
  242. }
  243. if (!(*lppFaxSendWizardData = MemAllocZ(sizeof(FAX_PERSONAL_PROFILE))))
  244. {
  245. Error(("Memory allocation failed\n"));
  246. hResult = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  247. goto error;
  248. }
  249. *pdwLastRecipientCountryId = GetRegistryDword(hRegKey, REGVAL_LAST_COUNTRYID);
  250. *pdwNumberOfRecipients = 1;
  251. (*lppFaxSendWizardData)[0].lptstrName = lptstrName;
  252. (*lppFaxSendWizardData)[0].lptstrFaxNumber = lptstrFaxNumber;
  253. RegCloseKey(hRegKey);
  254. }
  255. else
  256. {
  257. Error(("RestoreLastRecipientInfo: Can't open registry for READ/WRITE\n"));
  258. hResult = E_FAIL;
  259. goto error;
  260. }
  261. goto exit;
  262. error:
  263. MemFree ( lptstrName );
  264. MemFree ( lptstrFaxNumber );
  265. if (hRegKey)
  266. RegCloseKey(hRegKey);
  267. exit:
  268. return hResult;
  269. }
  270. HRESULT
  271. RestoreCoverPageInfo(
  272. LPTSTR * lpptstrCoverPageFileName
  273. )
  274. /*++
  275. Routine Description:
  276. Restores the information about the cover page from the registry
  277. Arguments:
  278. lpptstrCoverPageFileName - pointer to restore coverd page file name
  279. Return Value:
  280. S_OK if success
  281. error otherwise (may return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY))
  282. --*/
  283. {
  284. HKEY hRegKey = NULL;
  285. HRESULT hResult = S_OK;
  286. //
  287. // validate parameter
  288. //
  289. Assert(lpptstrCoverPageFileName);
  290. //
  291. // Retrieve the most recently used cover page settings
  292. //
  293. *lpptstrCoverPageFileName = NULL;
  294. if (hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READONLY))
  295. {
  296. if (!(*lpptstrCoverPageFileName = GetRegistryString(hRegKey, REGVAL_COVERPG, TEXT("") )))
  297. {
  298. Error(("Memory allocation failed\n"));
  299. hResult = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  300. goto error;
  301. }
  302. RegCloseKey(hRegKey);
  303. }
  304. else
  305. {
  306. Error(("RestoreCoverPageInfo: Can't open registry for READ/WRITE\n"));
  307. hResult = E_FAIL;
  308. goto error;
  309. }
  310. goto exit;
  311. error:
  312. if (hRegKey)
  313. RegCloseKey(hRegKey);
  314. exit:
  315. return hResult;
  316. }
  317. HRESULT
  318. SaveCoverPageInfo(
  319. LPTSTR lptstrCoverPageFileName
  320. )
  321. /*++
  322. Routine Description:
  323. Save the information about the cover page settings in the registry
  324. Arguments:
  325. lptstrCoverPageFileName - pointer to cover page file name
  326. Return Value:
  327. S_OK - if success
  328. E_FAIL - otherwise
  329. --*/
  330. {
  331. HKEY hRegKey = NULL;
  332. HRESULT hResult = S_OK;
  333. if (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO, TRUE,REG_READWRITE) ) {
  334. SetRegistryString(hRegKey, REGVAL_COVERPG, lptstrCoverPageFileName);
  335. RegCloseKey(hRegKey);
  336. }
  337. else
  338. {
  339. Error(("SaveCoverPageInfo: Can't open registry for READ/WRITE\n"));
  340. hResult = E_FAIL;
  341. }
  342. return hResult;
  343. }
  344. HRESULT
  345. RestoreUseDialingRules(
  346. BOOL* pbUseDialingRules,
  347. BOOL* pbUseOutboundRouting
  348. )
  349. /*++
  350. Routine Description:
  351. Restore UseDialingRules / UseOutboundRouting option from the registry
  352. Arguments:
  353. pbUseDialingRules - [out] TRUE if the option is selected
  354. pbUseOutboundRouting - [out] TRUE if the option is selected
  355. Return Value:
  356. S_OK - if success
  357. E_FAIL - otherwise
  358. --*/
  359. {
  360. HKEY hRegKey = NULL;
  361. HRESULT hResult = S_OK;
  362. Assert(pbUseDialingRules && pbUseOutboundRouting);
  363. *pbUseDialingRules = FALSE;
  364. hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READONLY);
  365. if(hRegKey)
  366. {
  367. *pbUseDialingRules = GetRegistryDword(hRegKey, REGVAL_USE_DIALING_RULES);
  368. *pbUseOutboundRouting = GetRegistryDword(hRegKey, REGVAL_USE_OUTBOUND_ROUTING);
  369. RegCloseKey(hRegKey);
  370. }
  371. else
  372. {
  373. Error(("RestoreUseDialingRules: GetUserInfoRegKey failed\n"));
  374. hResult = E_FAIL;
  375. }
  376. return hResult;
  377. }
  378. HRESULT
  379. SaveUseDialingRules(
  380. BOOL bUseDialingRules,
  381. BOOL bUseOutboundRouting
  382. )
  383. /*++
  384. Routine Description:
  385. Save UseDialingRules / UseOutboundRouting option in the registry
  386. Arguments:
  387. bUseDialingRules - [in] TRUE if the option selected
  388. bUseOutboundRouting - [in] TRUE if the option selected
  389. Return Value:
  390. S_OK - if success
  391. E_FAIL - otherwise
  392. --*/
  393. {
  394. HKEY hRegKey = NULL;
  395. HRESULT hResult = S_OK;
  396. hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READWRITE);
  397. if(hRegKey)
  398. {
  399. if(!SetRegistryDword(hRegKey, REGVAL_USE_DIALING_RULES, bUseDialingRules))
  400. {
  401. Error(("SaveUseDialingRules: SetRegistryDword failed\n"));
  402. hResult = E_FAIL;
  403. }
  404. if(!SetRegistryDword(hRegKey, REGVAL_USE_OUTBOUND_ROUTING, bUseOutboundRouting))
  405. {
  406. Error(("SaveUseDialingRules: SetRegistryDword failed\n"));
  407. hResult = E_FAIL;
  408. }
  409. RegCloseKey(hRegKey);
  410. }
  411. else
  412. {
  413. Error(("SaveUseDialingRules: GetUserInfoRegKey failed\n"));
  414. hResult = E_FAIL;
  415. }
  416. return hResult;
  417. }
  418. BOOL
  419. IsOutlookDefaultClient()
  420. /*++
  421. Routine Description:
  422. Determine if the Microsoft Outlook is default mail client
  423. Return Value:
  424. TRUE - if yes
  425. FALSE - otherwise
  426. --*/
  427. {
  428. BOOL bRes = FALSE;
  429. DWORD dwRes = ERROR_SUCCESS;
  430. HKEY hRegKey = NULL;
  431. TCHAR tszMailClient[64] = {0};
  432. DWORD dwType;
  433. DWORD dwSize = sizeof(tszMailClient)-2;
  434. dwRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  435. REGKEY_MAIL_CLIENT,
  436. 0,
  437. KEY_READ,
  438. &hRegKey);
  439. if(ERROR_SUCCESS != dwRes)
  440. {
  441. Error(("IsOutlookDefaultClient: RegOpenKeyEx failed: ec = 0x%X\n", GetLastError()));
  442. return bRes;
  443. }
  444. dwRes = RegQueryValueEx(hRegKey,
  445. NULL,
  446. NULL,
  447. &dwType,
  448. (LPBYTE)tszMailClient,
  449. &dwSize);
  450. if(ERROR_SUCCESS != dwRes)
  451. {
  452. Error(("IsOutlookDefaultClient: RegQueryValueEx failed: ec = 0x%X\n", GetLastError()));
  453. }
  454. else
  455. {
  456. if((REG_SZ == dwType) && !_tcsicmp(tszMailClient, REGVAL_MS_OUTLOOK))
  457. {
  458. bRes = TRUE;
  459. }
  460. }
  461. RegCloseKey(hRegKey);
  462. return bRes;
  463. }