Source code of Windows XP (NT5)
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.

279 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. reg.c
  5. Abstract:
  6. This module implements registry functions for the newfsp service provider
  7. --*/
  8. #include "newfsp.h"
  9. BOOL
  10. GetNewFspRegistryData(
  11. BOOL *bLoggingEnabled,
  12. LPWSTR lpszLoggingDirectory,
  13. PDEVICE_INFO *pDeviceInfo,
  14. LPDWORD pdwNumDevices
  15. )
  16. /*++
  17. Routine Description:
  18. Get the registry data for the newfsp service provider
  19. Arguments:
  20. bLoggingEnabled - indicates if logging is enabled
  21. lpszLoggingDirectory - indicates the logging directory
  22. pDeviceInfo - pointer to the virtual fax devices
  23. pdwNumDevice - pointer to the number of virtual fax devices
  24. Return Value:
  25. TRUE on success
  26. --*/
  27. {
  28. // hServiceProvidersKey is the handle to the fax service providers registry key
  29. HKEY hServiceProvidersKey;
  30. // hNewFspKey is the handle to the newfsp service provider registry key
  31. HKEY hNewFspKey;
  32. // hDevicesKey is the handle to the virtual fax devices registry key
  33. HKEY hDevicesKey;
  34. // dwSubkeys is the number of virtual fax device registry subkeys
  35. DWORD dwSubkeys;
  36. // dwIndex is a counter to enumerate each virtual fax device registry subkey
  37. DWORD dwIndex;
  38. // szDeviceSubkey is the name of a virtual fax device registry subkey
  39. WCHAR szDeviceSubkey[MAX_PATH];
  40. // hDeviceSubkey is the handle to a virtual fax device registry subkey
  41. HKEY hDeviceSubkey;
  42. DWORD dwType;
  43. // pCurrentDeviceInfo is a pointer to the current virtual fax device
  44. PDEVICE_INFO pCurrentDeviceInfo;
  45. DWORD dwLoggingEnabledSize;
  46. DWORD dwLoggingDirectorySize;
  47. DWORD dwDirectorySize;
  48. if (bLoggingEnabled != NULL) {
  49. *bLoggingEnabled = FALSE;
  50. }
  51. if (lpszLoggingDirectory != NULL) {
  52. ZeroMemory(lpszLoggingDirectory, sizeof(WCHAR) * MAX_PATH_LEN);
  53. }
  54. if (pDeviceInfo != NULL) {
  55. *pDeviceInfo = NULL;
  56. }
  57. if (pdwNumDevices != NULL) {
  58. *pdwNumDevices = 0;
  59. }
  60. // Open the fax service providers registry key
  61. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, FAX_PROVIDERS_REGKEY, 0, KEY_ALL_ACCESS, &hServiceProvidersKey) != ERROR_SUCCESS) {
  62. return FALSE;
  63. }
  64. // Open the newfsp service provider registry key
  65. if (RegOpenKeyEx(hServiceProvidersKey, NEWFSP_PROVIDER, 0, KEY_ALL_ACCESS, &hNewFspKey) != ERROR_SUCCESS) {
  66. RegCloseKey(hServiceProvidersKey);
  67. return FALSE;
  68. }
  69. if (bLoggingEnabled != NULL) {
  70. // Get the logging enabled
  71. dwLoggingEnabledSize = sizeof(BOOL);
  72. RegQueryValueEx(hNewFspKey, NEWFSP_LOGGING_ENABLED, NULL, &dwType, (LPBYTE) bLoggingEnabled, &dwLoggingEnabledSize);
  73. }
  74. if (lpszLoggingDirectory != NULL) {
  75. // Get the logging directory
  76. dwLoggingDirectorySize = sizeof(WCHAR) * MAX_PATH_LEN;
  77. RegQueryValueEx(hNewFspKey, NEWFSP_LOGGING_DIRECTORY, NULL, &dwType, (LPBYTE) lpszLoggingDirectory, &dwLoggingDirectorySize);
  78. }
  79. if ((pDeviceInfo != NULL) || (pdwNumDevices != NULL)) {
  80. // Open the virtual fax devices registry key
  81. if (RegOpenKeyEx(hNewFspKey, NEWFSP_DEVICES, 0, KEY_ALL_ACCESS, &hDevicesKey) != ERROR_SUCCESS) {
  82. RegCloseKey(hNewFspKey);
  83. RegCloseKey(hServiceProvidersKey);
  84. return FALSE;
  85. }
  86. // Determine the number of virtual fax device registry subkeys
  87. if (RegQueryInfoKey(hDevicesKey, NULL, NULL, NULL, &dwSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
  88. RegCloseKey(hDevicesKey);
  89. RegCloseKey(hNewFspKey);
  90. RegCloseKey(hServiceProvidersKey);
  91. return FALSE;
  92. }
  93. }
  94. if (pdwNumDevices != NULL) {
  95. if (dwSubkeys < NEWFSP_DEVICE_LIMIT) {
  96. *pdwNumDevices = dwSubkeys;
  97. }
  98. else {
  99. *pdwNumDevices = NEWFSP_DEVICE_LIMIT;
  100. }
  101. }
  102. if (pDeviceInfo != NULL) {
  103. if (dwSubkeys > 0) {
  104. // Allocate a block of memory for the first virtual fax device data
  105. *pDeviceInfo = MemAllocMacro(sizeof(DEVICE_INFO));
  106. }
  107. // Enumerate the virtual fax device registry subkeys
  108. for (pCurrentDeviceInfo = *pDeviceInfo, dwIndex = 0; (dwIndex < dwSubkeys) && (dwIndex < NEWFSP_DEVICE_LIMIT); pCurrentDeviceInfo = pCurrentDeviceInfo->pNextDeviceInfo, dwIndex++) {
  109. if (pCurrentDeviceInfo == NULL) {
  110. // A memory allocation for virtual fax device data failed, so go with what we have so far
  111. *pdwNumDevices = dwIndex;
  112. break;
  113. }
  114. // Set the name of the virtual fax device registry subkey
  115. wsprintf(szDeviceSubkey, L"%d", dwIndex);
  116. // Set the identifier of the virtual fax device
  117. pCurrentDeviceInfo->DeviceId = dwIndex;
  118. if (RegOpenKeyEx(hDevicesKey, szDeviceSubkey, 0, KEY_ALL_ACCESS, &hDeviceSubkey) == ERROR_SUCCESS) {
  119. // Get the incoming fax directory for the virtual fax device
  120. dwDirectorySize = sizeof(WCHAR) * MAX_PATH_LEN;
  121. RegQueryValueEx(hDeviceSubkey, NEWFSP_DEVICE_DIRECTORY, NULL, &dwType, (LPBYTE) pCurrentDeviceInfo->Directory, &dwDirectorySize);
  122. RegCloseKey(hDeviceSubkey);
  123. }
  124. // Allocate a block of memory for the next virtual fax device data
  125. if ((dwIndex < (dwSubkeys - 1)) && (dwIndex < (NEWFSP_DEVICE_LIMIT - 1))) {
  126. pCurrentDeviceInfo->pNextDeviceInfo = MemAllocMacro(sizeof(DEVICE_INFO));
  127. }
  128. else {
  129. pCurrentDeviceInfo->pNextDeviceInfo = NULL;
  130. }
  131. }
  132. }
  133. if ((pDeviceInfo != NULL) || (pdwNumDevices != NULL)) {
  134. RegCloseKey(hDevicesKey);
  135. }
  136. RegCloseKey(hNewFspKey);
  137. RegCloseKey(hServiceProvidersKey);
  138. return TRUE;
  139. }
  140. VOID
  141. SetNewFspRegistryData(
  142. BOOL bLoggingEnabled,
  143. LPWSTR lpszLoggingDirectory,
  144. PDEVICE_INFO pDeviceInfo
  145. )
  146. /*++
  147. Routine Description:
  148. Set the registry data for the newfsp service provider
  149. Arguments:
  150. bLoggingEnabled - indicates if logging is enabled
  151. lpszLoggingDirectory - indicates the logging directory
  152. pDeviceInfo - pointer to the virtual fax devices
  153. Return Value:
  154. None
  155. --*/
  156. {
  157. // hServiceProvidersKey is the handle to the fax service providers registry key
  158. HKEY hServiceProvidersKey;
  159. // hNewFspKey is the handle to the newfsp service provider registry key
  160. HKEY hNewFspKey;
  161. // hDevicesKey is the handle to the virtual fax devices registry key
  162. HKEY hDevicesKey;
  163. // dwSubkeys is the number of virtual fax device registry subkeys
  164. DWORD dwSubkeys;
  165. // dwIndex is a counter to enumerate each virtual fax device registry subkey
  166. DWORD dwIndex;
  167. // szDeviceSubkey is the name of a virtual fax device registry subkey
  168. WCHAR szDeviceSubkey[MAX_PATH];
  169. // hDeviceSubkey is the handle to a virtual fax device registry subkey
  170. HKEY hDeviceSubkey;
  171. DWORD dwDisposition;
  172. // pCurrentDeviceInfo is a pointer to the current virtual fax device
  173. PDEVICE_INFO pCurrentDeviceInfo;
  174. // Open the fax service providers registry key
  175. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, FAX_PROVIDERS_REGKEY, 0, KEY_ALL_ACCESS, &hServiceProvidersKey) != ERROR_SUCCESS) {
  176. return;
  177. }
  178. // Open the newfsp service provider registry key
  179. if (RegCreateKeyEx(hServiceProvidersKey, NEWFSP_PROVIDER, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewFspKey, &dwDisposition) != ERROR_SUCCESS) {
  180. RegCloseKey(hServiceProvidersKey);
  181. return;
  182. }
  183. // Set the logging enabled
  184. RegSetValueEx(hNewFspKey, NEWFSP_LOGGING_ENABLED, 0, REG_DWORD, (LPBYTE) &bLoggingEnabled, sizeof(bLoggingEnabled));
  185. // Set the logging directory
  186. if (lpszLoggingDirectory != NULL) {
  187. RegSetValueEx(hNewFspKey, NEWFSP_LOGGING_DIRECTORY, 0, REG_SZ, (LPBYTE) lpszLoggingDirectory, (lstrlen(lpszLoggingDirectory) + 1) * sizeof(WCHAR));
  188. }
  189. // Open the virtual fax devices registry key
  190. if (RegCreateKeyEx(hNewFspKey, NEWFSP_DEVICES, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hDevicesKey, &dwDisposition) != ERROR_SUCCESS) {
  191. RegCloseKey(hNewFspKey);
  192. RegCloseKey(hServiceProvidersKey);
  193. return;
  194. }
  195. // Determine the number of virtual fax device registry subkeys
  196. if (RegQueryInfoKey(hDevicesKey, NULL, NULL, NULL, &dwSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
  197. RegCloseKey(hDevicesKey);
  198. RegCloseKey(hNewFspKey);
  199. RegCloseKey(hServiceProvidersKey);
  200. return;
  201. }
  202. // Enumerate the virtual fax device registry subkeys
  203. for (pCurrentDeviceInfo = pDeviceInfo, dwIndex = 0; pCurrentDeviceInfo; pCurrentDeviceInfo = pCurrentDeviceInfo->pNextDeviceInfo, dwIndex++) {
  204. // Set the name of the virtual fax device registry subkey
  205. wsprintf(szDeviceSubkey, L"%d", pCurrentDeviceInfo->DeviceId);
  206. if (RegCreateKeyEx(hDevicesKey, szDeviceSubkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hDeviceSubkey, &dwDisposition) == ERROR_SUCCESS) {
  207. // Set the incoming fax directory for the virtual fax device
  208. RegSetValueEx(hDeviceSubkey, NEWFSP_DEVICE_DIRECTORY, 0, REG_SZ, (LPBYTE) pCurrentDeviceInfo->Directory, (lstrlen(pCurrentDeviceInfo->Directory) + 1) * sizeof(WCHAR));
  209. RegCloseKey(hDeviceSubkey);
  210. }
  211. }
  212. // Delete any removed virtual fax device registry subkeys
  213. for ( ; dwIndex < dwSubkeys; dwIndex++) {
  214. // Set the name of the virtual fax device registry subkey
  215. wsprintf(szDeviceSubkey, L"%d", dwIndex);
  216. RegDeleteKey(hDevicesKey, szDeviceSubkey);
  217. }
  218. RegCloseKey(hDevicesKey);
  219. RegCloseKey(hNewFspKey);
  220. RegCloseKey(hServiceProvidersKey);
  221. }