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.

277 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. sender.c
  5. Abstract:
  6. Implementation of functions work with sender
  7. FaxSetSenderInformation
  8. FaxGetSenderInformation
  9. Environment:
  10. FXSAPI.DLL
  11. Revision History:
  12. 10/13/99 -v-sashab-
  13. Created it.
  14. --*/
  15. #include "faxapi.h"
  16. #include "faxreg.h"
  17. #include "registry.h"
  18. HRESULT WINAPI
  19. FaxSetSenderInformation(
  20. PFAX_PERSONAL_PROFILE pfppSender
  21. )
  22. /*++
  23. Routine Description:
  24. Save the information about the sender in the registry
  25. Arguments:
  26. pfppSender - pointer to the sender information
  27. Return Value:
  28. S_OK - if success
  29. E_FAIL - otherwise or HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)
  30. --*/
  31. {
  32. HKEY hRegKey = NULL;
  33. HRESULT hResult = S_OK;
  34. DEBUG_FUNCTION_NAME(_T("FaxSetSenderInformation"));
  35. //
  36. // Validate Parameters
  37. //
  38. if (!pfppSender)
  39. {
  40. DebugPrintEx(DEBUG_ERR, _T("pfppSender is NULL."));
  41. hResult = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  42. goto exit;
  43. }
  44. if (pfppSender->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE))
  45. {
  46. DebugPrintEx(DEBUG_ERR, _T("pfppSender->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE)."));
  47. hResult = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  48. goto exit;
  49. }
  50. if ((hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_USERINFO,TRUE, KEY_ALL_ACCESS)))
  51. {
  52. SetRegistryString(hRegKey, REGVAL_FULLNAME, pfppSender->lptstrName);
  53. SetRegistryString(hRegKey, REGVAL_FAX_NUMBER, pfppSender->lptstrFaxNumber);
  54. SetRegistryString(hRegKey, REGVAL_COMPANY, pfppSender->lptstrCompany);
  55. SetRegistryString(hRegKey, REGVAL_ADDRESS, pfppSender->lptstrStreetAddress);
  56. SetRegistryString(hRegKey, REGVAL_CITY, pfppSender->lptstrCity);
  57. SetRegistryString(hRegKey, REGVAL_STATE, pfppSender->lptstrState);
  58. SetRegistryString(hRegKey, REGVAL_ZIP, pfppSender->lptstrZip);
  59. SetRegistryString(hRegKey, REGVAL_COUNTRY, pfppSender->lptstrCountry);
  60. SetRegistryString(hRegKey, REGVAL_TITLE, pfppSender->lptstrTitle);
  61. SetRegistryString(hRegKey, REGVAL_DEPT, pfppSender->lptstrDepartment);
  62. SetRegistryString(hRegKey, REGVAL_OFFICE, pfppSender->lptstrOfficeLocation);
  63. SetRegistryString(hRegKey, REGVAL_HOME_PHONE, pfppSender->lptstrHomePhone);
  64. SetRegistryString(hRegKey, REGVAL_OFFICE_PHONE, pfppSender->lptstrOfficePhone);
  65. SetRegistryString(hRegKey, REGVAL_BILLING_CODE, pfppSender->lptstrBillingCode);
  66. SetRegistryString(hRegKey, REGVAL_MAILBOX, pfppSender->lptstrEmail);
  67. RegCloseKey(hRegKey);
  68. }
  69. else
  70. {
  71. DebugPrintEx(DEBUG_ERR, _T("Can't open registry for READ/WRITE."));
  72. hResult = E_FAIL;
  73. goto exit;
  74. }
  75. //
  76. // turn on "user info configured" registry flag
  77. //
  78. hRegKey = OpenRegistryKey(HKEY_CURRENT_USER, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS);
  79. if(hRegKey)
  80. {
  81. SetRegistryDword(hRegKey, REGVAL_CFGWZRD_USER_INFO, TRUE);
  82. RegCloseKey(hRegKey);
  83. }
  84. else
  85. {
  86. DebugPrintEx(DEBUG_ERR, _T("OpenRegistryKey() is failed."));
  87. }
  88. exit:
  89. return hResult;
  90. }
  91. HRESULT WINAPI
  92. FaxGetSenderInformation(
  93. PFAX_PERSONAL_PROFILE pfppSender
  94. )
  95. /*++
  96. Routine Description:
  97. Restores the information about the sender from the registry
  98. Arguments:
  99. ppfppSender - pointer to restored sender informtion
  100. Return Value:
  101. S_OK if success
  102. error otherwise (may return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY)
  103. or HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER))
  104. --*/
  105. {
  106. HKEY hRegKey = NULL;
  107. HRESULT hResult = S_OK;
  108. LPCTSTR lpctstrCurrentUserName = NULL;
  109. LPCTSTR lpctstrRegisteredOrganization = NULL;
  110. DEBUG_FUNCTION_NAME(_T("FaxGetSenderInformation"));
  111. //
  112. // Validate Parameters
  113. //
  114. if (!pfppSender)
  115. {
  116. DebugPrintEx(DEBUG_ERR, _T("pfppSender is NULL."));
  117. hResult = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  118. goto exit;
  119. }
  120. if (pfppSender->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE))
  121. {
  122. DebugPrintEx(DEBUG_ERR, _T("pfppSender->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE)"));
  123. hResult = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  124. goto exit;
  125. }
  126. ZeroMemory(pfppSender, sizeof(FAX_PERSONAL_PROFILE));
  127. pfppSender->dwSizeOfStruct = sizeof(FAX_PERSONAL_PROFILE);
  128. lpctstrCurrentUserName = GetCurrentUserName();
  129. lpctstrRegisteredOrganization = GetRegisteredOrganization();
  130. hRegKey = GetUserInfoRegKey(REGKEY_FAX_USERINFO, REG_READONLY);
  131. //
  132. // If we failed to open the reg key, calls to GetRegistryString() will return default values - this is what we want.
  133. //
  134. if (!(pfppSender->lptstrName = GetRegistryString(hRegKey,
  135. REGVAL_FULLNAME,
  136. lpctstrCurrentUserName ? lpctstrCurrentUserName : TEXT(""))) ||
  137. !(pfppSender->lptstrFaxNumber = GetRegistryString(hRegKey, REGVAL_FAX_NUMBER, TEXT(""))) ||
  138. !(pfppSender->lptstrCompany = GetRegistryString(hRegKey,
  139. REGVAL_COMPANY,
  140. lpctstrRegisteredOrganization ? lpctstrRegisteredOrganization : TEXT(""))) ||
  141. !(pfppSender->lptstrStreetAddress = GetRegistryString(hRegKey, REGVAL_ADDRESS, TEXT(""))) ||
  142. !(pfppSender->lptstrCity = GetRegistryString(hRegKey, REGVAL_CITY, TEXT(""))) ||
  143. !(pfppSender->lptstrState = GetRegistryString(hRegKey, REGVAL_STATE, TEXT(""))) ||
  144. !(pfppSender->lptstrZip = GetRegistryString(hRegKey, REGVAL_ZIP, TEXT(""))) ||
  145. !(pfppSender->lptstrCountry = GetRegistryString(hRegKey, REGVAL_COUNTRY, TEXT(""))) ||
  146. !(pfppSender->lptstrTitle = GetRegistryString(hRegKey, REGVAL_TITLE, TEXT(""))) ||
  147. !(pfppSender->lptstrDepartment = GetRegistryString(hRegKey, REGVAL_DEPT, TEXT(""))) ||
  148. !(pfppSender->lptstrOfficeLocation = GetRegistryString(hRegKey, REGVAL_OFFICE, TEXT(""))) ||
  149. !(pfppSender->lptstrHomePhone = GetRegistryString(hRegKey, REGVAL_HOME_PHONE, TEXT(""))) ||
  150. !(pfppSender->lptstrOfficePhone = GetRegistryString(hRegKey, REGVAL_OFFICE_PHONE, TEXT(""))) ||
  151. !(pfppSender->lptstrBillingCode = GetRegistryString(hRegKey, REGVAL_BILLING_CODE, TEXT(""))) ||
  152. !(pfppSender->lptstrEmail = GetRegistryString(hRegKey, REGVAL_MAILBOX, TEXT(""))))
  153. {
  154. DebugPrintEx(DEBUG_ERR, _T("Memory allocation failed."));
  155. hResult = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  156. goto error;
  157. }
  158. goto exit;
  159. error:
  160. MemFree( pfppSender->lptstrName );
  161. MemFree( pfppSender->lptstrFaxNumber);
  162. MemFree( pfppSender->lptstrCompany );
  163. MemFree( pfppSender->lptstrStreetAddress);
  164. MemFree( pfppSender->lptstrCity);
  165. MemFree( pfppSender->lptstrState);
  166. MemFree( pfppSender->lptstrZip);
  167. MemFree( pfppSender->lptstrCountry);
  168. MemFree( pfppSender->lptstrTitle );
  169. MemFree( pfppSender->lptstrDepartment);
  170. MemFree( pfppSender->lptstrOfficeLocation);
  171. MemFree( pfppSender->lptstrHomePhone);
  172. MemFree( pfppSender->lptstrOfficePhone);
  173. MemFree( pfppSender->lptstrBillingCode);
  174. MemFree( pfppSender->lptstrEmail);
  175. exit:
  176. if (hRegKey)
  177. {
  178. RegCloseKey(hRegKey);
  179. }
  180. MemFree((PVOID)lpctstrCurrentUserName);
  181. MemFree((PVOID)lpctstrRegisteredOrganization);
  182. return hResult;
  183. }
  184. static HRESULT
  185. FaxFreePersonalProfileInformation(
  186. PFAX_PERSONAL_PROFILE lpPersonalProfileInfo
  187. )
  188. {
  189. if (lpPersonalProfileInfo) {
  190. MemFree(lpPersonalProfileInfo->lptstrName);
  191. MemFree(lpPersonalProfileInfo->lptstrFaxNumber);
  192. MemFree(lpPersonalProfileInfo->lptstrCompany);
  193. MemFree(lpPersonalProfileInfo->lptstrStreetAddress);
  194. MemFree(lpPersonalProfileInfo->lptstrCity);
  195. MemFree(lpPersonalProfileInfo->lptstrState);
  196. MemFree(lpPersonalProfileInfo->lptstrZip);
  197. MemFree(lpPersonalProfileInfo->lptstrCountry);
  198. MemFree(lpPersonalProfileInfo->lptstrTitle);
  199. MemFree(lpPersonalProfileInfo->lptstrDepartment);
  200. MemFree(lpPersonalProfileInfo->lptstrOfficeLocation);
  201. MemFree(lpPersonalProfileInfo->lptstrHomePhone);
  202. MemFree(lpPersonalProfileInfo->lptstrOfficePhone);
  203. MemFree(lpPersonalProfileInfo->lptstrEmail);
  204. MemFree(lpPersonalProfileInfo->lptstrBillingCode);
  205. MemFree(lpPersonalProfileInfo->lptstrTSID);
  206. }
  207. return S_OK;
  208. }
  209. HRESULT WINAPI
  210. FaxFreeSenderInformation(
  211. PFAX_PERSONAL_PROFILE pfppSender
  212. )
  213. /*++
  214. Routine Description:
  215. This function frees sender information
  216. Arguments:
  217. pfppSender - pointer to sender information
  218. Return Value:
  219. S_OK
  220. --*/
  221. {
  222. return FaxFreePersonalProfileInformation(pfppSender);
  223. }