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.

182 lines
4.8 KiB

  1. #include "faxrtp.h"
  2. #pragma hdrstop
  3. LIST_ENTRY RoutingListHead;
  4. CRITICAL_SECTION CsRouting;
  5. LPCWSTR InboundProfileName;
  6. DWORD
  7. GetMaskBit(
  8. LPCWSTR RoutingGuid
  9. )
  10. {
  11. if (_tcsicmp( RoutingGuid, REGVAL_RM_EMAIL_GUID ) == 0) {
  12. return LR_EMAIL;
  13. } else if (_tcsicmp( RoutingGuid, REGVAL_RM_FOLDER_GUID ) == 0) {
  14. return LR_STORE;
  15. } else if (_tcsicmp( RoutingGuid, REGVAL_RM_INBOX_GUID ) == 0) {
  16. return LR_INBOX;
  17. } else if (_tcsicmp( RoutingGuid, REGVAL_RM_PRINTING_GUID ) == 0) {
  18. return LR_PRINT;
  19. }
  20. return 0;
  21. }
  22. BOOL
  23. AddNewDeviceToRoutingTable(
  24. DWORD DeviceId,
  25. LPCWSTR DeviceName,
  26. LPCWSTR Csid,
  27. LPCWSTR Tsid,
  28. LPCWSTR PrinterName,
  29. LPCWSTR StoreDir,
  30. LPCWSTR ProfileName,
  31. DWORD Mask
  32. )
  33. {
  34. PROUTING_TABLE RoutingEntry = (PROUTING_TABLE) MemAlloc( sizeof(ROUTING_TABLE) );
  35. if (!RoutingEntry) {
  36. return FALSE;
  37. }
  38. RoutingEntry->DeviceId = DeviceId;
  39. RoutingEntry->DeviceName = DeviceName;
  40. RoutingEntry->Csid = Csid;
  41. RoutingEntry->Tsid = Tsid;
  42. RoutingEntry->PrinterName = PrinterName;
  43. RoutingEntry->StoreDir = StoreDir;
  44. RoutingEntry->ProfileName = ProfileName;
  45. RoutingEntry->Mask = Mask;
  46. InsertTailList( &RoutingListHead, &RoutingEntry->ListEntry );
  47. return TRUE;
  48. }
  49. BOOL
  50. FaxDeviceEnumerator(
  51. HKEY hSubKey,
  52. LPWSTR SubKeyName,
  53. DWORD Index,
  54. PVOID Context
  55. )
  56. {
  57. if (!SubKeyName) {
  58. return TRUE;
  59. }
  60. //
  61. // try to enumerate the routing information under a device node.
  62. // NOTE: if we fail to enumerate the routing information, we return TRUE, instead of
  63. // FALSE, as would be expected. This means that we will still initialize our routing
  64. // extension correctly, but we just won't be able to route to certain (probably bogus)
  65. // devices
  66. HKEY hKeyRouting = OpenRegistryKey( hSubKey, REGKEY_ROUTING, FALSE, KEY_READ );
  67. if (!hKeyRouting) {
  68. DebugPrint(( TEXT("InitializeRoutingTable(): could not open routing registry key") ));
  69. return TRUE;
  70. }
  71. AddNewDeviceToRoutingTable(
  72. GetRegistryDword ( hSubKey, REGVAL_PERMANENT_LINEID ),
  73. GetRegistryString( hSubKey, REGVAL_DEVICE_NAME, EMPTY_STRING ),
  74. GetRegistryString( hSubKey, REGVAL_ROUTING_CSID, EMPTY_STRING ),
  75. GetRegistryString( hSubKey, REGVAL_ROUTING_TSID, EMPTY_STRING ),
  76. GetRegistryString( hKeyRouting, REGVAL_ROUTING_PRINTER, EMPTY_STRING ),
  77. GetRegistryString( hKeyRouting, REGVAL_ROUTING_DIR, EMPTY_STRING ),
  78. GetRegistryString( hKeyRouting, REGVAL_ROUTING_PROFILE, EMPTY_STRING ),
  79. GetRegistryDword ( hKeyRouting, REGVAL_ROUTING_MASK )
  80. );
  81. RegCloseKey( hKeyRouting );
  82. return TRUE;
  83. }
  84. BOOL
  85. InitializeRoutingTable(
  86. VOID
  87. )
  88. {
  89. InitializeListHead( &RoutingListHead );
  90. InitializeCriticalSection( &CsRouting );
  91. HKEY hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAXSERVER, FALSE, KEY_READ );
  92. if (!hKey) {
  93. DebugPrint(( TEXT("InitializeRoutingTable(): could not open registry key") ));
  94. return FALSE;
  95. }
  96. InboundProfileName = GetRegistryString( hKey, REGVAL_INBOUND_PROFILE, EMPTY_STRING );
  97. if (!InboundProfileName) {
  98. DebugPrint(( TEXT("InitializeRoutingTable(): could not read inbound profile name") ));
  99. }
  100. RegCloseKey( hKey );
  101. if (!EnumerateRegistryKeys( HKEY_LOCAL_MACHINE, REGKEY_FAX_DEVICES, FALSE, FaxDeviceEnumerator, NULL )) {
  102. DebugPrint(( TEXT("InitializeRoutingTable(): could not enumerate fax devices") ));
  103. return FALSE;
  104. }
  105. return TRUE;
  106. }
  107. BOOL
  108. UpdateRoutingInfoRegistry(
  109. PROUTING_TABLE RoutingEntry
  110. )
  111. {
  112. WCHAR KeyName[256];
  113. swprintf( KeyName, L"%s\\%08d\\%s", REGKEY_FAX_DEVICES, RoutingEntry->DeviceId, REGKEY_ROUTING );
  114. HKEY hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, KeyName, TRUE, KEY_ALL_ACCESS );
  115. if (!hKey) {
  116. Assert(( ! TEXT("InitializeRoutingTable(): could not open registry key") ));
  117. return FALSE;
  118. }
  119. SetRegistryString( hKey, REGVAL_ROUTING_PRINTER, RoutingEntry->PrinterName );
  120. SetRegistryString( hKey, REGVAL_ROUTING_DIR, RoutingEntry->StoreDir );
  121. SetRegistryString( hKey, REGVAL_ROUTING_PROFILE, RoutingEntry->ProfileName );
  122. SetRegistryDword( hKey, REGVAL_ROUTING_MASK, RoutingEntry->Mask );
  123. RegCloseKey( hKey );
  124. return TRUE;
  125. }
  126. PROUTING_TABLE
  127. GetRoutingEntry(
  128. DWORD DeviceId
  129. )
  130. {
  131. PLIST_ENTRY Next;
  132. PROUTING_TABLE RoutingEntry;
  133. Next = RoutingListHead.Flink;
  134. if (Next) {
  135. while (Next != &RoutingListHead) {
  136. RoutingEntry = CONTAINING_RECORD( Next, ROUTING_TABLE, ListEntry );
  137. Next = RoutingEntry->ListEntry.Flink;
  138. if (RoutingEntry->DeviceId == DeviceId) {
  139. return RoutingEntry;
  140. }
  141. }
  142. }
  143. return NULL;
  144. }