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.

1847 lines
44 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. registry.cpp
  5. Abstract:
  6. This module wraps all of the registry access
  7. for the fax server.
  8. Author:
  9. Wesley Witt (wesw) 9-June-1996
  10. Revision History:
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <tchar.h>
  16. #include "winfax.h"
  17. #include "faxutil.h"
  18. #include "faxreg.h"
  19. #include "faxsvcrg.h"
  20. #define FAX_EVENT_MSG_FILE TEXT("%systemroot%\\system32\\faxevent.dll")
  21. #define FAX_CATEGORY_COUNT 4
  22. BOOL
  23. EnumDeviceProviders(
  24. HKEY hSubKey,
  25. LPWSTR SubKeyName,
  26. DWORD Index,
  27. PREG_FAX_SERVICE FaxReg
  28. )
  29. {
  30. if (SubKeyName == NULL) {
  31. if (Index) {
  32. FaxReg->DeviceProviders = (PREG_DEVICE_PROVIDER) MemAlloc( Index * sizeof(REG_DEVICE_PROVIDER) );
  33. if (!FaxReg->DeviceProviders) {
  34. return FALSE;
  35. }
  36. }
  37. return TRUE;
  38. }
  39. if (FaxReg == NULL || FaxReg->DeviceProviders == NULL) {
  40. return FALSE;
  41. }
  42. FaxReg->DeviceProviders[Index].FriendlyName = GetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, EMPTY_STRING );
  43. FaxReg->DeviceProviders[Index].ImageName = GetRegistryStringExpand( hSubKey, REGVAL_IMAGE_NAME, EMPTY_STRING );
  44. FaxReg->DeviceProviders[Index].ProviderName = GetRegistryString( hSubKey, REGVAL_PROVIDER_NAME,EMPTY_STRING );
  45. return TRUE;
  46. }
  47. BOOL
  48. EnumDeviceProvidersChange(
  49. HKEY hSubKey,
  50. LPWSTR SubKeyName,
  51. DWORD Index,
  52. PREG_FAX_SERVICE FaxReg
  53. )
  54. {
  55. if (SubKeyName == NULL) {
  56. //
  57. // called once for the subkey
  58. //
  59. return TRUE;
  60. }
  61. if (FaxReg == NULL || FaxReg->DeviceProviders == NULL) {
  62. return FALSE;
  63. }
  64. SetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, FaxReg->DeviceProviders[Index].FriendlyName );
  65. SetRegistryStringExpand( hSubKey, REGVAL_IMAGE_NAME, FaxReg->DeviceProviders[Index].ImageName );
  66. SetRegistryString( hSubKey, REGVAL_PROVIDER_NAME, FaxReg->DeviceProviders[Index].ProviderName );
  67. return TRUE;
  68. }
  69. BOOL
  70. EnumRoutingMethods(
  71. HKEY hSubKey,
  72. LPWSTR SubKeyName,
  73. DWORD Index,
  74. PREG_ROUTING_EXTENSION RoutingExtension
  75. )
  76. {
  77. if (SubKeyName == NULL) {
  78. if (Index) {
  79. RoutingExtension->RoutingMethods = (PREG_ROUTING_METHOD) MemAlloc( Index * sizeof(REG_ROUTING_METHOD) );
  80. if (!RoutingExtension->RoutingMethods) {
  81. return FALSE;
  82. }
  83. }
  84. return TRUE;
  85. }
  86. if (RoutingExtension == NULL || RoutingExtension->RoutingMethods == NULL) {
  87. return FALSE;
  88. }
  89. RoutingExtension->RoutingMethods[Index].InternalName = StringDup( SubKeyName );
  90. RoutingExtension->RoutingMethods[Index].FriendlyName = GetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, EMPTY_STRING );
  91. RoutingExtension->RoutingMethods[Index].FunctionName = GetRegistryString( hSubKey, REGVAL_FUNCTION_NAME, EMPTY_STRING );
  92. RoutingExtension->RoutingMethods[Index].Guid = GetRegistryString( hSubKey, REGVAL_GUID, EMPTY_STRING );
  93. RoutingExtension->RoutingMethods[Index].Priority = GetRegistryDword( hSubKey, REGVAL_ROUTING_PRIORITY );
  94. return TRUE;
  95. }
  96. BOOL
  97. EnumRoutingMethodsChange(
  98. HKEY hSubKey,
  99. LPWSTR SubKeyName,
  100. DWORD Index,
  101. PREG_ROUTING_EXTENSION RoutingExtension
  102. )
  103. {
  104. if (SubKeyName == NULL) {
  105. //
  106. // called once for the subkey
  107. //
  108. return TRUE;
  109. }
  110. if (RoutingExtension == NULL || RoutingExtension->RoutingMethods) {
  111. return FALSE;
  112. }
  113. SetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, RoutingExtension->RoutingMethods[Index].FriendlyName );
  114. SetRegistryString( hSubKey, REGVAL_FUNCTION_NAME, RoutingExtension->RoutingMethods[Index].FunctionName );
  115. SetRegistryString( hSubKey, REGVAL_GUID, RoutingExtension->RoutingMethods[Index].Guid );
  116. SetRegistryDword ( hSubKey, REGVAL_ROUTING_PRIORITY, RoutingExtension->RoutingMethods[Index].Priority );
  117. return TRUE;
  118. }
  119. BOOL
  120. EnumRoutingExtensions(
  121. HKEY hSubKey,
  122. LPWSTR SubKeyName,
  123. DWORD Index,
  124. PREG_FAX_SERVICE FaxReg
  125. )
  126. {
  127. if (SubKeyName == NULL) {
  128. if (Index) {
  129. FaxReg->RoutingExtensions = (PREG_ROUTING_EXTENSION) MemAlloc( Index * sizeof(REG_ROUTING_EXTENSION) );
  130. if (!FaxReg->RoutingExtensions) {
  131. return FALSE;
  132. }
  133. }
  134. return TRUE;
  135. }
  136. if (FaxReg == NULL || FaxReg->RoutingExtensions == NULL) {
  137. return FALSE;
  138. }
  139. FaxReg->RoutingExtensions[Index].InternalName = StringDup( SubKeyName );
  140. FaxReg->RoutingExtensions[Index].FriendlyName = GetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, EMPTY_STRING );
  141. FaxReg->RoutingExtensions[Index].ImageName = GetRegistryStringExpand( hSubKey, REGVAL_IMAGE_NAME, EMPTY_STRING );
  142. //
  143. // load the routing methods for this extension
  144. //
  145. FaxReg->RoutingExtensions[Index].RoutingMethodsCount = EnumerateRegistryKeys(
  146. hSubKey,
  147. REGKEY_ROUTING_METHODS,
  148. FALSE,
  149. EnumRoutingMethods,
  150. &FaxReg->RoutingExtensions[Index]
  151. );
  152. return TRUE;
  153. }
  154. BOOL
  155. EnumRoutingExtensionsChange(
  156. HKEY hSubKey,
  157. LPWSTR SubKeyName,
  158. DWORD Index,
  159. PREG_FAX_SERVICE FaxReg
  160. )
  161. {
  162. if (SubKeyName == NULL) {
  163. //
  164. // called once for the subkey
  165. //
  166. return TRUE;
  167. }
  168. if (FaxReg == NULL || FaxReg->RoutingExtensions == NULL) {
  169. return FALSE;
  170. }
  171. SetRegistryString( hSubKey, REGVAL_FRIENDLY_NAME, FaxReg->RoutingExtensions[Index].FriendlyName );
  172. SetRegistryStringExpand( hSubKey, REGVAL_IMAGE_NAME, FaxReg->RoutingExtensions[Index].ImageName );
  173. //
  174. // load the routing methods for this extension
  175. //
  176. EnumerateRegistryKeys(
  177. hSubKey,
  178. REGKEY_ROUTING_METHODS,
  179. TRUE,
  180. EnumRoutingMethodsChange,
  181. &FaxReg->RoutingExtensions[Index]
  182. );
  183. return TRUE;
  184. }
  185. BOOL
  186. EnumDevices(
  187. HKEY hSubKey,
  188. LPWSTR SubKeyName,
  189. DWORD Index,
  190. PREG_FAX_SERVICE FaxReg
  191. )
  192. {
  193. if (SubKeyName == NULL) {
  194. if (Index) {
  195. FaxReg->Devices = (PREG_DEVICE) MemAlloc( Index * sizeof(REG_DEVICE) );
  196. if (!FaxReg->Devices) {
  197. return FALSE;
  198. }
  199. }
  200. return TRUE;
  201. }
  202. if (FaxReg == NULL || FaxReg->Devices == NULL) {
  203. return FALSE;
  204. }
  205. FaxReg->Devices[Index].PermanentLineID = GetRegistryDword( hSubKey, REGVAL_PERMANENT_LINEID );
  206. FaxReg->Devices[Index].Priority = GetRegistryDword( hSubKey, REGVAL_PRIORITY );
  207. FaxReg->Devices[Index].Flags = GetRegistryDword( hSubKey, REGVAL_FLAGS );
  208. FaxReg->Devices[Index].Rings = GetRegistryDword( hSubKey, REGVAL_RINGS );
  209. FaxReg->Devices[Index].Name = GetRegistryString( hSubKey, REGVAL_DEVICE_NAME, EMPTY_STRING );
  210. FaxReg->Devices[Index].Provider = GetRegistryString( hSubKey, REGVAL_PROVIDER, EMPTY_STRING );
  211. FaxReg->Devices[Index].Csid = GetRegistryString( hSubKey, REGVAL_ROUTING_CSID, EMPTY_STRING );
  212. FaxReg->Devices[Index].Tsid = GetRegistryString( hSubKey, REGVAL_ROUTING_TSID, EMPTY_STRING );
  213. return TRUE;
  214. }
  215. BOOL
  216. EnumDevicesCache(
  217. HKEY hSubKey,
  218. LPWSTR SubKeyName,
  219. DWORD Index,
  220. PREG_FAX_SERVICE FaxReg
  221. )
  222. {
  223. if (SubKeyName == NULL) {
  224. if (Index) {
  225. FaxReg->DevicesCache = (PREG_DEVICE_CACHE) MemAlloc( Index * sizeof(REG_DEVICE_CACHE) );
  226. if (!FaxReg->DevicesCache) {
  227. return FALSE;
  228. }
  229. }
  230. return TRUE;
  231. }
  232. if (FaxReg == NULL || FaxReg->DevicesCache == NULL) {
  233. return FALSE;
  234. }
  235. FaxReg->DevicesCache[Index].PermanentLineID = GetRegistryDword( hSubKey, REGVAL_PERMANENT_LINEID );
  236. //
  237. // cached devices should not have a priority
  238. //
  239. //FaxReg->DevicesCache[Index].Priority = 0; // GetRegistryDword( hSubKey, REGVAL_PRIORITY );
  240. FaxReg->DevicesCache[Index].Flags = GetRegistryDword( hSubKey, REGVAL_FLAGS );
  241. FaxReg->DevicesCache[Index].Rings = GetRegistryDword( hSubKey, REGVAL_RINGS );
  242. FaxReg->DevicesCache[Index].Name = GetRegistryString( hSubKey, REGVAL_DEVICE_NAME, EMPTY_STRING );
  243. FaxReg->DevicesCache[Index].Provider = GetRegistryString( hSubKey, REGVAL_PROVIDER, EMPTY_STRING );
  244. FaxReg->DevicesCache[Index].Csid = GetRegistryString( hSubKey, REGVAL_ROUTING_CSID, EMPTY_STRING );
  245. FaxReg->DevicesCache[Index].Tsid = GetRegistryString( hSubKey, REGVAL_ROUTING_TSID, EMPTY_STRING );
  246. FaxReg->DevicesCache[Index].RoutingMask = GetRegistryDword( hSubKey, REGVAL_ROUTING_MASK );
  247. FaxReg->DevicesCache[Index].Printer = GetRegistryString( hSubKey, REGVAL_ROUTING_PRINTER, EMPTY_STRING );
  248. FaxReg->DevicesCache[Index].Profile = GetRegistryString( hSubKey, REGVAL_ROUTING_PROFILE, EMPTY_STRING );
  249. FaxReg->DevicesCache[Index].StoreDir = GetRegistryString( hSubKey, REGVAL_ROUTING_DIR, EMPTY_STRING );
  250. return TRUE;
  251. }
  252. VOID
  253. SetDevicesCacheValues(
  254. HKEY hSubKey,
  255. DWORD PermanentLineID,
  256. DWORD Flags,
  257. DWORD Rings,
  258. LPTSTR DeviceName,
  259. LPTSTR ProviderName,
  260. LPTSTR Csid,
  261. LPTSTR Tsid,
  262. DWORD RouteMask,
  263. LPTSTR RoutePrinterName,
  264. LPTSTR RouteDir,
  265. LPTSTR RouteProfile
  266. )
  267. {
  268. SetRegistryDword( hSubKey, REGVAL_PERMANENT_LINEID, PermanentLineID );
  269. SetRegistryDword( hSubKey, REGVAL_FLAGS, Flags );
  270. SetRegistryDword( hSubKey, REGVAL_RINGS, Rings );
  271. SetRegistryString( hSubKey, REGVAL_DEVICE_NAME, DeviceName );
  272. SetRegistryString( hSubKey, REGVAL_PROVIDER, ProviderName );
  273. SetRegistryString( hSubKey, REGVAL_ROUTING_CSID, Csid );
  274. SetRegistryString( hSubKey, REGVAL_ROUTING_TSID, Tsid );
  275. SetRegistryDword( hSubKey, REGVAL_ROUTING_MASK, RouteMask );
  276. SetRegistryString( hSubKey, REGVAL_ROUTING_PRINTER, RoutePrinterName);
  277. SetRegistryString( hSubKey, REGVAL_ROUTING_PROFILE, RouteProfile );
  278. SetRegistryString( hSubKey, REGVAL_ROUTING_DIR, RouteDir );
  279. }
  280. VOID
  281. SetDevicesValues(
  282. HKEY hSubKey,
  283. DWORD PermanentLineID,
  284. DWORD Priority,
  285. DWORD Flags,
  286. DWORD Rings,
  287. LPTSTR DeviceName,
  288. LPTSTR ProviderName,
  289. LPTSTR Csid,
  290. LPTSTR Tsid
  291. )
  292. {
  293. SetRegistryDword( hSubKey, REGVAL_PERMANENT_LINEID, PermanentLineID );
  294. SetRegistryDword( hSubKey, REGVAL_PRIORITY, Priority );
  295. SetRegistryDword( hSubKey, REGVAL_FLAGS, Flags );
  296. SetRegistryDword( hSubKey, REGVAL_RINGS, Rings );
  297. if (DeviceName) SetRegistryString( hSubKey, REGVAL_DEVICE_NAME, DeviceName );
  298. if (ProviderName) SetRegistryString( hSubKey, REGVAL_PROVIDER, ProviderName );
  299. SetRegistryString( hSubKey, REGVAL_ROUTING_CSID, Csid );
  300. SetRegistryString( hSubKey, REGVAL_ROUTING_TSID, Tsid );
  301. }
  302. BOOL
  303. EnumDevicesChange(
  304. HKEY hSubKey,
  305. LPWSTR SubKeyName,
  306. DWORD Index,
  307. PREG_FAX_SERVICE FaxReg
  308. )
  309. {
  310. if (SubKeyName == NULL) {
  311. //
  312. // called once for the subkey
  313. //
  314. return TRUE;
  315. }
  316. if (FaxReg == NULL || FaxReg->Devices == NULL) {
  317. return FALSE;
  318. }
  319. SetDevicesValues(
  320. hSubKey,
  321. FaxReg->Devices[Index].PermanentLineID,
  322. FaxReg->Devices[Index].Priority,
  323. FaxReg->Devices[Index].Flags,
  324. FaxReg->Devices[Index].Rings,
  325. FaxReg->Devices[Index].Name,
  326. FaxReg->Devices[Index].Provider,
  327. FaxReg->Devices[Index].Csid,
  328. FaxReg->Devices[Index].Tsid
  329. );
  330. return TRUE;
  331. }
  332. BOOL
  333. EnumDevicesCacheChange(
  334. HKEY hSubKey,
  335. LPWSTR SubKeyName,
  336. DWORD Index,
  337. PREG_FAX_SERVICE FaxReg
  338. )
  339. {
  340. if (SubKeyName == NULL) {
  341. //
  342. // called once for the subkey
  343. //
  344. return TRUE;
  345. }
  346. if (FaxReg == NULL || FaxReg->DevicesCache == NULL) {
  347. return FALSE;
  348. }
  349. SetDevicesCacheValues(
  350. hSubKey,
  351. FaxReg->DevicesCache[Index].PermanentLineID,
  352. FaxReg->DevicesCache[Index].Flags,
  353. FaxReg->DevicesCache[Index].Rings,
  354. FaxReg->DevicesCache[Index].Name,
  355. FaxReg->DevicesCache[Index].Provider,
  356. FaxReg->DevicesCache[Index].Csid,
  357. FaxReg->DevicesCache[Index].Tsid,
  358. FaxReg->DevicesCache[Index].RoutingMask,
  359. FaxReg->DevicesCache[Index].Printer,
  360. FaxReg->DevicesCache[Index].StoreDir,
  361. FaxReg->DevicesCache[Index].Profile
  362. );
  363. return TRUE;
  364. }
  365. BOOL
  366. EnumLogging(
  367. HKEY hSubKey,
  368. LPWSTR SubKeyName,
  369. DWORD Index,
  370. PREG_FAX_SERVICE FaxReg
  371. )
  372. {
  373. if (SubKeyName == NULL) {
  374. if (Index) {
  375. FaxReg->Logging = (PREG_CATEGORY) MemAlloc( Index * sizeof(REG_CATEGORY) );
  376. if (!FaxReg->Logging) {
  377. return FALSE;
  378. }
  379. }
  380. return TRUE;
  381. }
  382. if (FaxReg->Logging == NULL) {
  383. return FALSE;
  384. }
  385. FaxReg->Logging[Index].CategoryName = GetRegistryString( hSubKey, REGVAL_CATEGORY_NAME, EMPTY_STRING );
  386. FaxReg->Logging[Index].Level = GetRegistryDword( hSubKey, REGVAL_CATEGORY_LEVEL );
  387. FaxReg->Logging[Index].Number = GetRegistryDword( hSubKey, REGVAL_CATEGORY_NUMBER );
  388. return TRUE;
  389. }
  390. BOOL
  391. EnumLoggingChange(
  392. HKEY hSubKey,
  393. LPWSTR SubKeyName,
  394. DWORD Index,
  395. PREG_FAX_SERVICE FaxReg
  396. )
  397. {
  398. if (SubKeyName == NULL) {
  399. return TRUE;
  400. }
  401. SetRegistryString( hSubKey, REGVAL_CATEGORY_NAME, FaxReg->Logging[Index].CategoryName );
  402. SetRegistryDword( hSubKey, REGVAL_CATEGORY_LEVEL, FaxReg->Logging[Index].Level );
  403. SetRegistryDword( hSubKey, REGVAL_CATEGORY_NUMBER, FaxReg->Logging[Index].Number );
  404. return TRUE;
  405. }
  406. PREG_FAX_SERVICE
  407. GetFaxRegistry(
  408. VOID
  409. )
  410. {
  411. PREG_FAX_SERVICE FaxReg;
  412. HKEY hKey;
  413. DWORD Tmp;
  414. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_READ );
  415. if (!hKey) {
  416. return NULL;
  417. }
  418. FaxReg = (PREG_FAX_SERVICE) MemAlloc( sizeof(REG_FAX_SERVICE) );
  419. if (!FaxReg) {
  420. RegCloseKey( hKey );
  421. return NULL;
  422. }
  423. //
  424. // load the fax service values
  425. //
  426. FaxReg->Retries = GetRegistryDword( hKey, REGVAL_RETRIES );
  427. FaxReg->RetryDelay = GetRegistryDword( hKey, REGVAL_RETRYDELAY );
  428. FaxReg->DirtyDays = GetRegistryDword( hKey, REGVAL_DIRTYDAYS );
  429. FaxReg->QueuePaused = GetRegistryDword( hKey, REGVAL_QUEUE_PAUSED );
  430. FaxReg->NextJobNumber = GetRegistryDword( hKey, REGVAL_JOB_NUMBER );
  431. FaxReg->ForceReceive = GetRegistryDword( hKey, REGVAL_FORCE_RECEIVE );
  432. FaxReg->TerminationDelay = GetRegistryDword( hKey, REGVAL_TERMINATION_DELAY );
  433. FaxReg->Branding = GetRegistryDword( hKey, REGVAL_BRANDING );
  434. FaxReg->UseDeviceTsid = GetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID );
  435. FaxReg->ServerCp = GetRegistryDword( hKey, REGVAL_SERVERCP );
  436. Tmp = GetRegistryDword( hKey, REGVAL_STARTCHEAP );
  437. FaxReg->StartCheapTime.Hour = LOWORD(Tmp);
  438. FaxReg->StartCheapTime.Minute = HIWORD(Tmp);
  439. Tmp = GetRegistryDword( hKey, REGVAL_STOPCHEAP );
  440. FaxReg->StopCheapTime.Hour = LOWORD(Tmp);
  441. FaxReg->StopCheapTime.Minute = HIWORD(Tmp);
  442. FaxReg->ArchiveOutgoingFaxes = GetRegistryDword( hKey, REGVAL_ARCHIVEFLAG );
  443. FaxReg->InboundProfile = GetRegistryString( hKey, REGVAL_INBOUND_PROFILE, EMPTY_STRING );
  444. FaxReg->ArchiveDirectory = GetRegistryString( hKey, REGVAL_ARCHIVEDIR, EMPTY_STRING );
  445. //
  446. // load the device providers
  447. //
  448. FaxReg->DeviceProviderCount = EnumerateRegistryKeys(
  449. hKey,
  450. REGKEY_DEVICE_PROVIDERS,
  451. FALSE,
  452. EnumDeviceProviders,
  453. FaxReg
  454. );
  455. //
  456. // load the routing extensions
  457. //
  458. FaxReg->RoutingExtensionsCount = EnumerateRegistryKeys(
  459. hKey,
  460. REGKEY_ROUTING_EXTENSIONS,
  461. FALSE,
  462. EnumRoutingExtensions,
  463. FaxReg
  464. );
  465. //
  466. // load the devices
  467. //
  468. FaxReg->DeviceCount = EnumerateRegistryKeys(
  469. hKey,
  470. REGKEY_DEVICES,
  471. FALSE,
  472. EnumDevices,
  473. FaxReg
  474. );
  475. //
  476. // load the cached devices
  477. //
  478. FaxReg->DeviceCacheCount = EnumerateRegistryKeys(
  479. hKey,
  480. REGKEY_DEVICES_CACHE,
  481. FALSE,
  482. EnumDevicesCache,
  483. FaxReg
  484. );
  485. //
  486. // load the logging categories
  487. //
  488. FaxReg->LoggingCount = EnumerateRegistryKeys(
  489. hKey,
  490. REGKEY_LOGGING,
  491. FALSE,
  492. EnumLogging,
  493. FaxReg
  494. );
  495. RegCloseKey( hKey );
  496. return FaxReg;
  497. }
  498. BOOL
  499. SetFaxRegistry(
  500. PREG_FAX_SERVICE FaxReg
  501. )
  502. {
  503. HKEY hKey;
  504. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_ALL_ACCESS );
  505. if (!hKey) {
  506. return FALSE;
  507. }
  508. //
  509. // set the fax service values
  510. //
  511. SetRegistryDword( hKey, REGVAL_RETRIES, FaxReg->Retries );
  512. SetRegistryDword( hKey, REGVAL_RETRYDELAY, FaxReg->RetryDelay );
  513. SetRegistryDword( hKey, REGVAL_DIRTYDAYS, FaxReg->DirtyDays );
  514. SetRegistryDword( hKey, REGVAL_QUEUE_PAUSED, FaxReg->QueuePaused );
  515. SetRegistryDword( hKey, REGVAL_BRANDING, FaxReg->Branding );
  516. SetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID, FaxReg->UseDeviceTsid );
  517. SetRegistryString( hKey, REGVAL_INBOUND_PROFILE, FaxReg->InboundProfile );
  518. //
  519. // set the device providers
  520. //
  521. EnumerateRegistryKeys(
  522. hKey,
  523. REGKEY_DEVICE_PROVIDERS,
  524. TRUE,
  525. EnumDeviceProvidersChange,
  526. FaxReg
  527. );
  528. //
  529. // set the routing extensions
  530. //
  531. EnumerateRegistryKeys(
  532. hKey,
  533. REGKEY_ROUTING_EXTENSIONS,
  534. TRUE,
  535. EnumRoutingExtensionsChange,
  536. FaxReg
  537. );
  538. //
  539. // set the devices
  540. //
  541. EnumerateRegistryKeys(
  542. hKey,
  543. REGKEY_DEVICES,
  544. TRUE,
  545. EnumDevicesChange,
  546. FaxReg
  547. );
  548. //
  549. // set the devices cache
  550. //
  551. EnumerateRegistryKeys(
  552. hKey,
  553. REGKEY_DEVICES_CACHE,
  554. TRUE,
  555. EnumDevicesCacheChange,
  556. FaxReg
  557. );
  558. //
  559. // set the logging categories
  560. //
  561. EnumerateRegistryKeys(
  562. hKey,
  563. REGKEY_LOGGING,
  564. TRUE,
  565. EnumLoggingChange,
  566. FaxReg
  567. );
  568. return TRUE;
  569. }
  570. VOID
  571. FreeFaxRegistry(
  572. PREG_FAX_SERVICE FaxReg
  573. )
  574. {
  575. DWORD i,j;
  576. if (!FaxReg) {
  577. return;
  578. }
  579. for (i=0; i<FaxReg->DeviceProviderCount; i++) {
  580. MemFree( FaxReg->DeviceProviders[i].FriendlyName );
  581. MemFree( FaxReg->DeviceProviders[i].ImageName );
  582. MemFree( FaxReg->DeviceProviders[i].ProviderName );
  583. }
  584. for (i=0; i<FaxReg->RoutingExtensionsCount; i++) {
  585. MemFree( FaxReg->RoutingExtensions[i].FriendlyName );
  586. MemFree( FaxReg->RoutingExtensions[i].ImageName );
  587. for (j=0; j<FaxReg->RoutingExtensions[i].RoutingMethodsCount; j++) {
  588. MemFree( FaxReg->RoutingExtensions[i].RoutingMethods[j].FriendlyName );
  589. MemFree( FaxReg->RoutingExtensions[i].RoutingMethods[j].FunctionName );
  590. MemFree( FaxReg->RoutingExtensions[i].RoutingMethods[j].Guid );
  591. }
  592. MemFree( FaxReg->RoutingExtensions[i].RoutingMethods );
  593. }
  594. MemFree( FaxReg->DeviceProviders );
  595. MemFree( FaxReg->RoutingExtensions );
  596. for (i=0; i<FaxReg->DeviceCount; i++) {
  597. MemFree( FaxReg->Devices[i].Name );
  598. MemFree( FaxReg->Devices[i].Provider );
  599. MemFree( FaxReg->Devices[i].Csid );
  600. MemFree( FaxReg->Devices[i].Tsid );
  601. }
  602. MemFree( FaxReg->Devices );
  603. for (i=0; i<FaxReg->DeviceCacheCount; i++) {
  604. MemFree( FaxReg->DevicesCache[i].Name );
  605. MemFree( FaxReg->DevicesCache[i].Provider );
  606. MemFree( FaxReg->DevicesCache[i].Printer );
  607. MemFree( FaxReg->DevicesCache[i].Profile );
  608. MemFree( FaxReg->DevicesCache[i].StoreDir );
  609. MemFree( FaxReg->DevicesCache[i].Csid );
  610. MemFree( FaxReg->DevicesCache[i].Tsid );
  611. }
  612. MemFree( FaxReg->DevicesCache );
  613. for (i=0; i<FaxReg->LoggingCount; i++) {
  614. MemFree( FaxReg->Logging[i].CategoryName );
  615. }
  616. MemFree( FaxReg->Logging );
  617. MemFree( FaxReg );
  618. }
  619. BOOL
  620. SetFaxGlobalsRegistry(
  621. PFAX_CONFIGURATION FaxConfig
  622. )
  623. {
  624. HKEY hKey;
  625. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS );
  626. if (!hKey) {
  627. return FALSE;
  628. }
  629. SetRegistryDword( hKey, REGVAL_RETRIES, FaxConfig->Retries );
  630. SetRegistryDword( hKey, REGVAL_RETRYDELAY, FaxConfig->RetryDelay );
  631. SetRegistryDword( hKey, REGVAL_DIRTYDAYS, FaxConfig->DirtyDays );
  632. SetRegistryDword( hKey, REGVAL_QUEUE_PAUSED, FaxConfig->PauseServerQueue );
  633. SetRegistryDword( hKey, REGVAL_BRANDING, FaxConfig->Branding );
  634. SetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID, FaxConfig->UseDeviceTsid );
  635. SetRegistryDword( hKey, REGVAL_SERVERCP, FaxConfig->ServerCp );
  636. SetRegistryDword( hKey, REGVAL_STARTCHEAP, MAKELONG( FaxConfig->StartCheapTime.Hour, FaxConfig->StartCheapTime.Minute ) );
  637. SetRegistryDword( hKey, REGVAL_STOPCHEAP, MAKELONG( FaxConfig->StopCheapTime.Hour, FaxConfig->StopCheapTime.Minute ) );
  638. SetRegistryDword( hKey, REGVAL_ARCHIVEFLAG, FaxConfig->ArchiveOutgoingFaxes );
  639. SetRegistryString( hKey, REGVAL_INBOUND_PROFILE, FaxConfig->InboundProfile );
  640. SetRegistryString( hKey, REGVAL_ARCHIVEDIR, FaxConfig->ArchiveDirectory );
  641. RegCloseKey( hKey );
  642. return TRUE;
  643. }
  644. BOOL
  645. SetFaxJobNumberRegistry(
  646. DWORD NextJobNumber
  647. )
  648. {
  649. HKEY hKey;
  650. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS );
  651. if (!hKey) {
  652. return FALSE;
  653. }
  654. SetRegistryDword( hKey, REGVAL_JOB_NUMBER, NextJobNumber );
  655. RegCloseKey( hKey );
  656. return TRUE;
  657. }
  658. BOOL
  659. GetLoggingCategoriesRegistry(
  660. PREG_FAX_LOGGING FaxRegLogging
  661. )
  662. {
  663. REG_FAX_SERVICE FaxReg = {0};
  664. HKEY hKey;
  665. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_READ );
  666. if (!hKey) {
  667. return FALSE;
  668. }
  669. FaxRegLogging->LoggingCount = EnumerateRegistryKeys(
  670. hKey,
  671. REGKEY_LOGGING,
  672. FALSE,
  673. EnumLogging,
  674. &FaxReg
  675. );
  676. RegCloseKey( hKey );
  677. FaxRegLogging->Logging = FaxReg.Logging;
  678. return TRUE;
  679. }
  680. BOOL
  681. SetLoggingCategoriesRegistry(
  682. PREG_FAX_LOGGING FaxRegLogging
  683. )
  684. {
  685. REG_FAX_SERVICE FaxReg = {0};
  686. HKEY hKey;
  687. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS );
  688. if (!hKey) {
  689. return FALSE;
  690. }
  691. FaxReg.Logging = FaxRegLogging->Logging;
  692. FaxReg.LoggingCount = FaxRegLogging->LoggingCount;
  693. EnumerateRegistryKeys(
  694. hKey,
  695. REGKEY_LOGGING,
  696. TRUE,
  697. EnumLoggingChange,
  698. &FaxReg
  699. );
  700. RegCloseKey( hKey );
  701. return TRUE;
  702. }
  703. PREG_FAX_DEVICES
  704. GetFaxDevicesRegistry(
  705. VOID
  706. )
  707. {
  708. PREG_FAX_SERVICE FaxReg;
  709. PREG_FAX_DEVICES FaxRegDevices;
  710. HKEY hKey;
  711. DWORD i, currentpriority;
  712. BOOL foundpriority;
  713. WCHAR KeyName[256];
  714. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_READ );
  715. if (!hKey) {
  716. return NULL;
  717. }
  718. FaxReg = (PREG_FAX_SERVICE) MemAlloc( sizeof(REG_FAX_SERVICE) );
  719. if (!FaxReg) {
  720. RegCloseKey( hKey );
  721. return NULL;
  722. }
  723. FaxRegDevices = (PREG_FAX_DEVICES) MemAlloc( sizeof(REG_FAX_DEVICES) );
  724. if (!FaxRegDevices) {
  725. RegCloseKey( hKey );
  726. return NULL;
  727. }
  728. //
  729. // load the devices
  730. //
  731. FaxReg->DeviceCount = EnumerateRegistryKeys(
  732. hKey,
  733. REGKEY_DEVICES,
  734. FALSE,
  735. EnumDevices,
  736. FaxReg
  737. );
  738. RegCloseKey( hKey );
  739. FaxRegDevices->Devices = FaxReg->Devices;
  740. FaxRegDevices->DeviceCount = FaxReg->DeviceCount;
  741. MemFree( FaxReg );
  742. //
  743. // make sure the device priorities all make sense
  744. //
  745. for (currentpriority = 1; currentpriority < FaxRegDevices->DeviceCount; currentpriority++) {
  746. foundpriority = FALSE;
  747. for (i = 0; i < FaxRegDevices->DeviceCount; i++) {
  748. if ( FaxRegDevices->Devices[i].Priority == currentpriority) {
  749. if (foundpriority) {
  750. //
  751. // devices may not have the same priority
  752. //
  753. FaxRegDevices->Devices[i].Priority += 1;
  754. }
  755. foundpriority = TRUE;
  756. }
  757. }
  758. while (!foundpriority) {
  759. //
  760. // out of order priorities
  761. //
  762. for (i = 0; i < FaxRegDevices->DeviceCount; i++) {
  763. if ( FaxRegDevices->Devices[i].Priority > currentpriority) {
  764. FaxRegDevices->Devices[i].Priority -=1;
  765. }
  766. if (FaxRegDevices->Devices[i].Priority == currentpriority) {
  767. if (foundpriority) {
  768. FaxRegDevices->Devices[i].Priority += 1;
  769. }
  770. foundpriority = TRUE;
  771. }
  772. }
  773. }
  774. }
  775. //
  776. // write the adjusted device priorities into the registry.
  777. //
  778. for (i = 0; i < FaxRegDevices->DeviceCount; i++) {
  779. wsprintf( KeyName, L"%s\\%08d", REGKEY_FAX_DEVICES, FaxRegDevices->Devices[i].PermanentLineID );
  780. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, KeyName , FALSE, KEY_ALL_ACCESS );
  781. if (hKey) {
  782. SetDevicesValues(
  783. hKey,
  784. FaxRegDevices->Devices[i].PermanentLineID,
  785. FaxRegDevices->Devices[i].Priority,
  786. FaxRegDevices->Devices[i].Flags,
  787. FaxRegDevices->Devices[i].Rings,
  788. NULL,//FaxRegDevices->Devices[i].DeviceName,
  789. NULL,//FaxRegDevices->Devices[i].ProviderName,
  790. FaxRegDevices->Devices[i].Csid,
  791. FaxRegDevices->Devices[i].Tsid
  792. );
  793. RegCloseKey( hKey );
  794. }
  795. }
  796. return FaxRegDevices;
  797. }
  798. PREG_FAX_DEVICES_CACHE
  799. GetFaxDevicesCacheRegistry(
  800. VOID
  801. )
  802. {
  803. PREG_FAX_SERVICE FaxReg;
  804. PREG_FAX_DEVICES_CACHE FaxRegDevices;
  805. HKEY hKey;
  806. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_READ );
  807. if (!hKey) {
  808. return NULL;
  809. }
  810. FaxReg = (PREG_FAX_SERVICE) MemAlloc( sizeof(REG_FAX_SERVICE) );
  811. if (!FaxReg) {
  812. RegCloseKey( hKey );
  813. return NULL;
  814. }
  815. FaxRegDevices = (PREG_FAX_DEVICES_CACHE) MemAlloc( sizeof(REG_FAX_DEVICES_CACHE) );
  816. if (!FaxRegDevices) {
  817. RegCloseKey( hKey );
  818. return NULL;
  819. }
  820. //
  821. // load the devices
  822. //
  823. FaxReg->DeviceCacheCount = EnumerateRegistryKeys(
  824. hKey,
  825. REGKEY_DEVICES_CACHE,
  826. FALSE,
  827. EnumDevicesCache,
  828. FaxReg
  829. );
  830. RegCloseKey( hKey );
  831. FaxRegDevices->Devices = FaxReg->DevicesCache;
  832. FaxRegDevices->DeviceCount = FaxReg->DeviceCacheCount;
  833. MemFree( FaxReg );
  834. return FaxRegDevices;
  835. }
  836. DWORD
  837. GetNextDevicePriority(
  838. VOID
  839. )
  840. {
  841. #define MAX(i,j) i>j?i:j
  842. PREG_FAX_SERVICE FaxReg;
  843. HKEY hKey;
  844. DWORD nextpriority = 0,i;
  845. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, FALSE, KEY_READ );
  846. if (!hKey) {
  847. return 1;
  848. }
  849. FaxReg = (PREG_FAX_SERVICE) MemAlloc( sizeof(REG_FAX_SERVICE) );
  850. if (!FaxReg) {
  851. RegCloseKey( hKey );
  852. return 1;
  853. }
  854. //
  855. // load the devices
  856. //
  857. FaxReg->DeviceCount = EnumerateRegistryKeys(
  858. hKey,
  859. REGKEY_DEVICES,
  860. FALSE,
  861. EnumDevices,
  862. FaxReg
  863. );
  864. RegCloseKey( hKey );
  865. for (i = 0; i<FaxReg->DeviceCount; i++) {
  866. nextpriority = MAX(nextpriority,FaxReg->Devices[i].Priority);
  867. MemFree( FaxReg->Devices[i].Name );
  868. MemFree( FaxReg->Devices[i].Provider );
  869. MemFree( FaxReg->Devices[i].Csid );
  870. MemFree( FaxReg->Devices[i].Tsid );
  871. }
  872. if ( FaxReg->Devices )
  873. MemFree( FaxReg->Devices );
  874. MemFree( FaxReg );
  875. return nextpriority+1;
  876. }
  877. DWORD
  878. RegAddNewFaxDevice(
  879. LPTSTR DeviceName,
  880. LPTSTR ProviderName,
  881. LPTSTR Csid,
  882. LPTSTR Tsid,
  883. DWORD Priority, // -1 means get the next available priority slot
  884. DWORD PermanentLineID,
  885. DWORD Flags,
  886. DWORD Rings,
  887. LONG RoutingMask, // -1 means don't set routing
  888. LPTSTR RoutePrinterName,
  889. LPTSTR RouteDir,
  890. LPTSTR RouteProfile
  891. )
  892. {
  893. HKEY hKey;
  894. HKEY hKeyRouting;
  895. TCHAR SubKeyName[128];
  896. DWORD localPriority = Priority;
  897. //
  898. // create the device's registry key
  899. //
  900. _stprintf( SubKeyName, TEXT("%s\\%08d"), REGKEY_FAX_DEVICES, PermanentLineID );
  901. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, SubKeyName, TRUE, KEY_ALL_ACCESS );
  902. if (!hKey) {
  903. return -1;
  904. }
  905. if (Priority == -1) {
  906. localPriority = GetNextDevicePriority();
  907. }
  908. //
  909. // populate the key with it's values
  910. //
  911. SetDevicesValues(
  912. hKey,
  913. PermanentLineID,
  914. localPriority,
  915. Flags,
  916. Rings,
  917. DeviceName,
  918. ProviderName,
  919. Csid,
  920. Tsid
  921. );
  922. //
  923. // now add the routing info
  924. //
  925. if (RoutingMask != -1) {
  926. hKeyRouting = OpenRegistryKey( hKey, REGKEY_ROUTING, TRUE, KEY_ALL_ACCESS );
  927. if (!hKeyRouting) {
  928. Assert(( ! TEXT("Could not open routing registry key") ));
  929. return FALSE;
  930. }
  931. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PRINTER, RoutePrinterName )) {
  932. Assert(( ! TEXT("Could not set printer name registry value") ));
  933. }
  934. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_DIR, RouteDir )) {
  935. Assert(( ! TEXT("Could not set routing dir registry value") ));
  936. }
  937. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PROFILE, RouteProfile )) {
  938. Assert(( ! TEXT("Could not set routing profile name registry value") ));
  939. }
  940. if (!SetRegistryDword( hKeyRouting, REGVAL_ROUTING_MASK, RoutingMask )) {
  941. Assert(( ! TEXT("Could not set routing mask registry value") ));
  942. }
  943. RegCloseKey( hKeyRouting );
  944. }
  945. RegCloseKey( hKey );
  946. //
  947. // close the handles and leave
  948. //
  949. return localPriority;
  950. }
  951. BOOL
  952. RegAddNewFaxDeviceCache(
  953. LPTSTR DeviceName,
  954. LPTSTR ProviderName,
  955. LPTSTR Csid,
  956. LPTSTR Tsid,
  957. DWORD PermanentLineID,
  958. DWORD Flags,
  959. DWORD Rings,
  960. DWORD RoutingMask, // -1 means don't set routing
  961. LPTSTR RoutePrinterName,
  962. LPTSTR RouteDir,
  963. LPTSTR RouteProfile
  964. )
  965. {
  966. HKEY hKey;
  967. //HKEY hKeyRouting;
  968. TCHAR SubKeyName[128];
  969. //
  970. // create the device's registry key
  971. //
  972. _stprintf( SubKeyName, TEXT("%s\\%s\\%s"), REGKEY_SOFTWARE, REGKEY_DEVICES_CACHE,DeviceName );
  973. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, SubKeyName, TRUE, KEY_ALL_ACCESS );
  974. if (!hKey) {
  975. return FALSE;
  976. }
  977. //
  978. // populate the key with it's values
  979. //
  980. SetDevicesCacheValues(
  981. hKey,
  982. PermanentLineID,
  983. Flags,
  984. Rings,
  985. DeviceName,
  986. ProviderName,
  987. Csid,
  988. Tsid,
  989. RoutingMask,
  990. RoutePrinterName,
  991. RouteDir,
  992. RouteProfile
  993. );
  994. //
  995. // close the handle and leave
  996. //
  997. RegCloseKey( hKey );
  998. return TRUE;
  999. }
  1000. BOOL
  1001. SetFaxDeviceFlags(
  1002. DWORD PermanentLineID,
  1003. DWORD Flags
  1004. )
  1005. {
  1006. DWORD rVal;
  1007. HKEY hKey;
  1008. TCHAR KeyName[256];
  1009. _stprintf( KeyName, TEXT("%s\\%08d"), REGKEY_FAX_DEVICES, PermanentLineID );
  1010. rVal = RegOpenKey(
  1011. HKEY_LOCAL_MACHINE,
  1012. KeyName,
  1013. &hKey
  1014. );
  1015. if (rVal != ERROR_SUCCESS) {
  1016. DebugPrint(( TEXT("Could not open devices registry key, ec=0x%08x"), rVal ));
  1017. return FALSE;
  1018. }
  1019. RegSetValueEx(
  1020. hKey,
  1021. REGVAL_FLAGS,
  1022. 0,
  1023. REG_DWORD,
  1024. (LPBYTE) &Flags,
  1025. sizeof(DWORD)
  1026. );
  1027. RegCloseKey( hKey );
  1028. return TRUE;
  1029. }
  1030. BOOL
  1031. SetFaxRoutingInfo(
  1032. LPTSTR ExtensionName,
  1033. LPTSTR MethodName,
  1034. LPTSTR Guid,
  1035. DWORD Priority,
  1036. LPTSTR FunctionName,
  1037. LPTSTR FriendlyName
  1038. )
  1039. {
  1040. HKEY hKey;
  1041. TCHAR KeyName[256];
  1042. wsprintf( KeyName, L"%s\\%s\\%s\\%s", REGKEY_ROUTING_EXTENSION_KEY, ExtensionName,REGKEY_ROUTING_METHODS, MethodName );
  1043. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, KeyName, FALSE, KEY_ALL_ACCESS );
  1044. if (!hKey) {
  1045. return FALSE;
  1046. }
  1047. SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName );
  1048. SetRegistryString( hKey, REGVAL_FUNCTION_NAME, FunctionName );
  1049. SetRegistryString( hKey, REGVAL_GUID, Guid );
  1050. SetRegistryDword ( hKey, REGVAL_ROUTING_PRIORITY, Priority );
  1051. RegCloseKey( hKey );
  1052. return TRUE;
  1053. }
  1054. BOOL
  1055. DeleteFaxDevice(
  1056. DWORD PermanentLineID
  1057. )
  1058. {
  1059. TCHAR SubKey[256];
  1060. _stprintf( SubKey, TEXT("%s\\%s\\%08d"), REGKEY_SOFTWARE, REGKEY_DEVICES, PermanentLineID );
  1061. DebugPrint(( TEXT("Deleting %s\n"), SubKey ));
  1062. //
  1063. // recursive delete
  1064. //
  1065. return DeleteRegistryKey( HKEY_LOCAL_MACHINE, SubKey ) ;
  1066. }
  1067. BOOL
  1068. DeleteCachedFaxDevice(
  1069. LPTSTR DeviceName
  1070. )
  1071. {
  1072. TCHAR SubKey[256];
  1073. _stprintf( SubKey, TEXT("%s\\%s\\%s"), REGKEY_SOFTWARE, REGKEY_DEVICES_CACHE, DeviceName );
  1074. DebugPrint(( TEXT("Deleting %s\n"), SubKey ));
  1075. //
  1076. // recursive delete
  1077. //
  1078. return DeleteRegistryKey( HKEY_LOCAL_MACHINE, SubKey ) ;
  1079. }
  1080. VOID
  1081. FreeFaxDevicesRegistry(
  1082. PREG_FAX_DEVICES FaxReg
  1083. )
  1084. {
  1085. DWORD i;
  1086. if (!FaxReg) {
  1087. return;
  1088. }
  1089. for (i=0; i<FaxReg->DeviceCount; i++) {
  1090. MemFree( FaxReg->Devices[i].Name );
  1091. MemFree( FaxReg->Devices[i].Provider );
  1092. MemFree( FaxReg->Devices[i].Csid );
  1093. MemFree( FaxReg->Devices[i].Tsid );
  1094. }
  1095. MemFree( FaxReg->Devices );
  1096. MemFree( FaxReg );
  1097. }
  1098. VOID
  1099. FreeFaxDevicesCacheRegistry(
  1100. PREG_FAX_DEVICES_CACHE FaxReg
  1101. )
  1102. {
  1103. DWORD i;
  1104. if (!FaxReg) {
  1105. return;
  1106. }
  1107. for (i=0; i<FaxReg->DeviceCount; i++) {
  1108. MemFree( FaxReg->Devices[i].Name );
  1109. MemFree( FaxReg->Devices[i].Provider );
  1110. MemFree( FaxReg->Devices[i].Printer );
  1111. MemFree( FaxReg->Devices[i].Profile );
  1112. MemFree( FaxReg->Devices[i].StoreDir );
  1113. MemFree( FaxReg->Devices[i].Csid );
  1114. MemFree( FaxReg->Devices[i].Tsid );
  1115. }
  1116. MemFree( FaxReg->Devices );
  1117. MemFree( FaxReg );
  1118. }
  1119. VOID
  1120. FreeRegRoutingInfo(
  1121. PREG_ROUTING_INFO FaxReg
  1122. )
  1123. {
  1124. if (!FaxReg) {
  1125. return;
  1126. }
  1127. MemFree( FaxReg->Printer );
  1128. MemFree( FaxReg->Profile );
  1129. MemFree( FaxReg->StoreDir );
  1130. MemFree( FaxReg );
  1131. }
  1132. PREG_ROUTING_INFO
  1133. RegGetRoutingInfo(
  1134. DWORD PermanentLineID
  1135. )
  1136. {
  1137. HKEY hKey;
  1138. TCHAR KeyName[256];
  1139. PREG_ROUTING_INFO FaxReg = MemAlloc( sizeof(REG_ROUTING_INFO) );
  1140. if (!FaxReg) {
  1141. return NULL;
  1142. }
  1143. _stprintf( KeyName, TEXT("%s\\%08d\\%s"), REGKEY_FAX_DEVICES, PermanentLineID, REGKEY_ROUTING );
  1144. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, KeyName, FALSE, KEY_READ );
  1145. if (!hKey) {
  1146. MemFree( FaxReg );
  1147. return NULL;
  1148. }
  1149. FaxReg->RoutingMask = GetRegistryDword( hKey, REGVAL_ROUTING_MASK );
  1150. FaxReg->Printer = GetRegistryString( hKey, REGVAL_ROUTING_PRINTER, EMPTY_STRING );
  1151. FaxReg->Profile = GetRegistryString( hKey, REGVAL_ROUTING_PROFILE, EMPTY_STRING );
  1152. FaxReg->StoreDir = GetRegistryString( hKey, REGVAL_ROUTING_DIR, EMPTY_STRING );
  1153. RegCloseKey( hKey );
  1154. return FaxReg;
  1155. }
  1156. BOOL
  1157. CreateFaxEventSource(
  1158. PREG_FAX_SERVICE FaxReg,
  1159. PFAX_LOG_CATEGORY DefaultCategories,
  1160. int DefaultCategoryCount
  1161. )
  1162. {
  1163. HKEY hKey;
  1164. HKEY hKeyLogging;
  1165. DWORD Disposition;
  1166. LONG rVal;
  1167. DWORD Types;
  1168. DWORD i;
  1169. WCHAR KeyName[256];
  1170. if (FaxReg->LoggingCount == 0) {
  1171. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_LOGGING, TRUE, KEY_ALL_ACCESS );
  1172. if (!hKey) {
  1173. return FALSE;
  1174. }
  1175. FaxReg->Logging = (PREG_CATEGORY) MemAlloc(DefaultCategoryCount * sizeof(REG_CATEGORY) );
  1176. if (!FaxReg->Logging) {
  1177. RegCloseKey( hKey );
  1178. return FALSE;
  1179. }
  1180. for (i=0; i< (DWORD) DefaultCategoryCount; i++) {
  1181. wsprintf( KeyName, L"%d", DefaultCategories[i].Category );
  1182. hKeyLogging = OpenRegistryKey( hKey, KeyName, TRUE, KEY_ALL_ACCESS );
  1183. if (hKeyLogging) {
  1184. SetRegistryString( hKeyLogging, REGVAL_CATEGORY_NAME, DefaultCategories[i].Name );
  1185. FaxReg->Logging[i].CategoryName = StringDup( DefaultCategories[i].Name);
  1186. SetRegistryDword( hKeyLogging, REGVAL_CATEGORY_LEVEL, DefaultCategories[i].Level );
  1187. FaxReg->Logging[i].Level = DefaultCategories[i].Level;
  1188. SetRegistryDword( hKeyLogging, REGVAL_CATEGORY_NUMBER, DefaultCategories[i].Category );
  1189. FaxReg->Logging[i].Number = DefaultCategories[i].Category;
  1190. RegCloseKey( hKeyLogging );
  1191. }
  1192. }
  1193. FaxReg->LoggingCount = DefaultCategoryCount;
  1194. RegCloseKey( hKey );
  1195. }
  1196. //
  1197. // check to see if the required registry
  1198. // entries are present so the event viewer
  1199. // can display the event records
  1200. //
  1201. rVal = RegCreateKeyEx(
  1202. HKEY_LOCAL_MACHINE,
  1203. REGKEY_EVENTLOG,
  1204. 0,
  1205. TEXT(""),
  1206. 0,
  1207. KEY_ALL_ACCESS,
  1208. NULL,
  1209. &hKey,
  1210. &Disposition
  1211. );
  1212. if (rVal != ERROR_SUCCESS) {
  1213. goto error_exit;
  1214. }
  1215. // if (Disposition != REG_CREATED_NEW_KEY) {
  1216. // RegCloseKey( hKey );
  1217. // return TRUE;
  1218. // }
  1219. //
  1220. // the key was just created so we must now
  1221. // create the value entries
  1222. //
  1223. //
  1224. // set the message file name
  1225. // this is the name of the fax service
  1226. // binary because it contains the
  1227. // resource strings
  1228. //
  1229. rVal = RegSetValueEx(
  1230. hKey,
  1231. REGVAL_EVENTMSGFILE,
  1232. 0,
  1233. REG_EXPAND_SZ,
  1234. (LPBYTE) FAX_EVENT_MSG_FILE,
  1235. _tcslen(FAX_EVENT_MSG_FILE) * sizeof(TCHAR)
  1236. );
  1237. if (rVal != ERROR_SUCCESS) {
  1238. goto error_exit;
  1239. }
  1240. rVal = RegSetValueEx(
  1241. hKey,
  1242. REGVAL_CATEGORYMSGFILE,
  1243. 0,
  1244. REG_EXPAND_SZ,
  1245. (LPBYTE) FAX_EVENT_MSG_FILE,
  1246. _tcslen(FAX_EVENT_MSG_FILE) * sizeof(TCHAR)
  1247. );
  1248. if (rVal != ERROR_SUCCESS) {
  1249. goto error_exit;
  1250. }
  1251. Types = FAX_CATEGORY_COUNT;
  1252. rVal = RegSetValueEx(
  1253. hKey,
  1254. REGVAL_CATEGORYCOUNT,
  1255. 0,
  1256. REG_DWORD,
  1257. (LPBYTE) &Types,
  1258. sizeof(DWORD)
  1259. );
  1260. if (rVal != ERROR_SUCCESS) {
  1261. goto error_exit;
  1262. }
  1263. Types = 7;
  1264. rVal = RegSetValueEx(
  1265. hKey,
  1266. REGVAL_TYPESSUPPORTED,
  1267. 0,
  1268. REG_DWORD,
  1269. (LPBYTE) &Types,
  1270. sizeof(DWORD)
  1271. );
  1272. if (rVal != ERROR_SUCCESS) {
  1273. goto error_exit;
  1274. }
  1275. RegCloseKey( hKey );
  1276. return TRUE;
  1277. error_exit:
  1278. if (hKey) RegCloseKey( hKey );
  1279. //
  1280. // go ahead and leave FaxReg->Logging allocated on this failure...it will get cleaned up eventually
  1281. //
  1282. return FALSE;
  1283. }
  1284. BOOL
  1285. GetInstallationInfo(
  1286. LPDWORD Installed,
  1287. LPDWORD InstallType,
  1288. LPDWORD InstalledPlatforms,
  1289. LPDWORD ProductType
  1290. )
  1291. {
  1292. HKEY hKey;
  1293. LONG rVal;
  1294. DWORD RegType;
  1295. DWORD RegSize;
  1296. TCHAR ProductTypeStr[32];
  1297. DWORD Bytes;
  1298. DWORD Type;
  1299. if (Installed == NULL || InstallType == NULL || InstalledPlatforms == NULL || ProductType == NULL) {
  1300. return FALSE;
  1301. }
  1302. rVal = RegOpenKey(
  1303. HKEY_LOCAL_MACHINE,
  1304. REGKEY_FAX_SETUP,
  1305. &hKey
  1306. );
  1307. if (rVal != ERROR_SUCCESS) {
  1308. DebugPrint(( TEXT("Could not open setup registry key, ec=0x%08x"), rVal ));
  1309. return FALSE;
  1310. }
  1311. RegSize = sizeof(DWORD);
  1312. rVal = RegQueryValueEx(
  1313. hKey,
  1314. REGVAL_FAXINSTALLED,
  1315. 0,
  1316. &RegType,
  1317. (LPBYTE) Installed,
  1318. &RegSize
  1319. );
  1320. if (rVal != ERROR_SUCCESS) {
  1321. DebugPrint(( TEXT("Could not query installed registry value, ec=0x%08x"), rVal ));
  1322. *Installed = 0;
  1323. }
  1324. rVal = RegQueryValueEx(
  1325. hKey,
  1326. REGVAL_FAXINSTALL_TYPE,
  1327. 0,
  1328. &RegType,
  1329. (LPBYTE) InstallType,
  1330. &RegSize
  1331. );
  1332. if (rVal != ERROR_SUCCESS) {
  1333. DebugPrint(( TEXT("Could not query install type registry value, ec=0x%08x"), rVal ));
  1334. *InstallType = 0;
  1335. }
  1336. rVal = RegQueryValueEx(
  1337. hKey,
  1338. REGVAL_FAXINSTALLED_PLATFORMS,
  1339. 0,
  1340. &RegType,
  1341. (LPBYTE) InstalledPlatforms,
  1342. &RegSize
  1343. );
  1344. if (rVal != ERROR_SUCCESS) {
  1345. DebugPrint(( TEXT("Could not query install platforms mask registry value, ec=0x%08x"), rVal ));
  1346. *InstalledPlatforms = 0;
  1347. }
  1348. RegCloseKey( hKey );
  1349. //
  1350. // get the product type
  1351. //
  1352. *ProductType = PRODUCT_TYPE_WINNT;
  1353. rVal = RegOpenKey(
  1354. HKEY_LOCAL_MACHINE,
  1355. TEXT("System\\CurrentControlSet\\Control\\ProductOptions"),
  1356. &hKey
  1357. );
  1358. if (rVal == ERROR_SUCCESS) {
  1359. Bytes = sizeof(ProductTypeStr);
  1360. rVal = RegQueryValueEx(
  1361. hKey,
  1362. TEXT("ProductType"),
  1363. NULL,
  1364. &Type,
  1365. (LPBYTE) ProductTypeStr,
  1366. &Bytes
  1367. );
  1368. if (rVal == ERROR_SUCCESS) {
  1369. if ((_tcsicmp( ProductTypeStr, TEXT("SERVERNT") ) == 0) ||
  1370. (_tcsicmp( ProductTypeStr, TEXT("LANMANNT") ) == 0)) {
  1371. *ProductType = PRODUCT_TYPE_SERVER;
  1372. }
  1373. }
  1374. RegCloseKey( hKey );
  1375. }
  1376. return TRUE;
  1377. }
  1378. BOOL
  1379. IsModemClass1(
  1380. LPSTR SubKey,
  1381. LPBOOL Class1Fax
  1382. )
  1383. {
  1384. BOOL rVal = TRUE;
  1385. LONG Rslt;
  1386. HKEY hKey;
  1387. DWORD Type;
  1388. DWORD Size;
  1389. *Class1Fax = 0;
  1390. Rslt = RegOpenKeyExA(
  1391. HKEY_LOCAL_MACHINE,
  1392. SubKey,
  1393. 0,
  1394. KEY_READ,
  1395. &hKey
  1396. );
  1397. if (Rslt == ERROR_SUCCESS) {
  1398. Size = sizeof(DWORD);
  1399. Rslt = RegQueryValueEx(
  1400. hKey,
  1401. TEXT("FaxClass1"),
  1402. 0,
  1403. &Type,
  1404. (LPBYTE) Class1Fax,
  1405. &Size
  1406. );
  1407. if (Rslt != ERROR_SUCCESS) {
  1408. rVal = FALSE;
  1409. }
  1410. RegCloseKey( hKey );
  1411. }
  1412. return rVal;
  1413. }
  1414. BOOL
  1415. SaveModemClass(
  1416. LPSTR SubKey,
  1417. BOOL Class1Fax
  1418. )
  1419. {
  1420. BOOL rVal = FALSE;
  1421. LONG Rslt;
  1422. HKEY hKey;
  1423. Rslt = RegOpenKeyExA(
  1424. HKEY_LOCAL_MACHINE,
  1425. SubKey,
  1426. 0,
  1427. KEY_WRITE,
  1428. &hKey
  1429. );
  1430. if (Rslt == ERROR_SUCCESS) {
  1431. Rslt = RegSetValueEx(
  1432. hKey,
  1433. TEXT("FaxClass1"),
  1434. 0,
  1435. REG_DWORD,
  1436. (LPBYTE) &Class1Fax,
  1437. sizeof(DWORD)
  1438. );
  1439. if (Rslt == ERROR_SUCCESS) {
  1440. rVal = TRUE;
  1441. }
  1442. RegCloseKey( hKey );
  1443. }
  1444. return rVal;
  1445. }
  1446. BOOL
  1447. GetOrigSetupData(
  1448. PREG_SETUP RegSetup
  1449. )
  1450. {
  1451. HKEY hKey;
  1452. HKEY hKeySetup;
  1453. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, FALSE, KEY_READ );
  1454. if (!hKey) {
  1455. return FALSE;
  1456. }
  1457. hKeySetup = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SETUP_ORIG, FALSE, KEY_READ );
  1458. if (!hKeySetup) {
  1459. return FALSE;
  1460. }
  1461. RegSetup->Installed = GetRegistryDword( hKey, REGVAL_FAXINSTALLED );
  1462. RegSetup->InstallType = GetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE );
  1463. RegSetup->InstalledPlatforms = GetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS );
  1464. RegSetup->Csid = GetRegistryString( hKeySetup, REGVAL_ROUTING_CSID, EMPTY_STRING );
  1465. RegSetup->Tsid = GetRegistryString( hKeySetup, REGVAL_ROUTING_TSID, EMPTY_STRING );
  1466. RegSetup->Printer = GetRegistryString( hKeySetup, REGVAL_ROUTING_PRINTER, EMPTY_STRING );
  1467. RegSetup->StoreDir = GetRegistryString( hKeySetup, REGVAL_ROUTING_DIR, EMPTY_STRING );
  1468. RegSetup->Profile = GetRegistryString( hKeySetup, REGVAL_ROUTING_PROFILE, EMPTY_STRING );
  1469. RegSetup->Mask = GetRegistryDword( hKeySetup, REGVAL_ROUTING_MASK );
  1470. RegSetup->Rings = GetRegistryDword( hKeySetup, REGVAL_RINGS );
  1471. RegCloseKey( hKey );
  1472. RegCloseKey( hKeySetup );
  1473. return TRUE;
  1474. }
  1475. VOID
  1476. FreeOrigSetupData(
  1477. PREG_SETUP RegSetup
  1478. )
  1479. {
  1480. MemFree( RegSetup->Csid );
  1481. MemFree( RegSetup->Tsid );
  1482. MemFree( RegSetup->Printer );
  1483. MemFree( RegSetup->StoreDir );
  1484. MemFree( RegSetup->Profile );
  1485. }