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.

393 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. faxrcv.c
  5. Abstract:
  6. Window NT Fax Routing Extension. This routing method signals a named event.
  7. Author:
  8. Steven Kehrli (steveke) 11/15/1997
  9. --*/
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include <winfax.h>
  13. #include <faxroute.h>
  14. #include "faxrcv.h"
  15. PFAXROUTEGETFILE g_pFaxRouteGetFile; // g_pFaxRouteGetFile is the pointer to callback to get file from fax file list
  16. DWORD
  17. DllEntry(
  18. HINSTANCE hInstance,
  19. DWORD dwReason,
  20. LPVOID pContext
  21. )
  22. /*++
  23. Routine Description:
  24. DLL entry point
  25. Arguments:
  26. hInstance - handle to the module
  27. dwReason - indicates the reason for being called
  28. pContext - context
  29. Return Value:
  30. TRUE on success
  31. --*/
  32. {
  33. switch (dwReason) {
  34. case DLL_PROCESS_ATTACH:
  35. if (!g_hFaxRcvEvent) {
  36. // Create FaxRcv named event
  37. g_hFaxRcvEvent = CreateEvent(NULL, FALSE, FALSE, FAXRCV_EVENT);
  38. }
  39. if (!g_hFaxRcvMutex) {
  40. // Create FaxRcv named mutex
  41. g_hFaxRcvMutex = CreateMutex(NULL, FALSE, FAXRCV_MUTEX);
  42. }
  43. break;
  44. case DLL_PROCESS_DETACH:
  45. if (g_hFaxRcvMutex) {
  46. // Wait for access to the FaxRcv named mutex
  47. WaitForSingleObject(g_hFaxRcvMutex, INFINITE);
  48. // Reset FaxRcv named event
  49. ResetEvent(g_hFaxRcvEvent);
  50. // Close FaxRcv named event
  51. CloseHandle(g_hFaxRcvEvent);
  52. g_hFaxRcvEvent = NULL;
  53. if (g_pFaxRcvView) {
  54. // Delete szCopyTiffFile
  55. DeleteFile((LPWSTR) g_pFaxRcvView);
  56. // Close FaxRcv memory map view
  57. UnmapViewOfFile(g_pFaxRcvView);
  58. g_pFaxRcvView = NULL;
  59. }
  60. if (g_hFaxRcvMap) {
  61. // Close FaxRcv memory map
  62. CloseHandle(g_hFaxRcvMap);
  63. g_hFaxRcvMap = NULL;
  64. }
  65. // Release access to the FaxRcv named mutex
  66. ReleaseMutex(g_hFaxRcvMutex);
  67. // Close FaxRcv named mutex
  68. CloseHandle(g_hFaxRcvMutex);
  69. g_hFaxRcvMutex = NULL;
  70. }
  71. break;
  72. }
  73. return TRUE;
  74. }
  75. BOOL WINAPI
  76. FaxRouteInitialize(
  77. HANDLE hHeap,
  78. PFAX_ROUTE_CALLBACKROUTINES pFaxRouteCallbackRoutines
  79. )
  80. /*++
  81. Routine Description:
  82. Initializes the routing extension
  83. Arguments:
  84. hHeap - handle to the heap
  85. pFaxRouteCallbackRoutins - pointer to fax routing callback routines
  86. Return Value:
  87. TRUE on success
  88. --*/
  89. {
  90. // Set g_pFaxRouteGetFile
  91. g_pFaxRouteGetFile = pFaxRouteCallbackRoutines->FaxRouteGetFile;
  92. return TRUE;
  93. }
  94. BOOL WINAPI
  95. FaxRouteGetRoutingInfo(
  96. LPCWSTR RoutingGuid,
  97. DWORD dwDeviceId,
  98. LPBYTE RoutingInfo,
  99. LPDWORD pdwRoutingInfoSize
  100. )
  101. /*++
  102. Routine Description:
  103. Gets the routing info for a routing method
  104. Arguments:
  105. RoutingGuid - pointer to the GUID of the routing method
  106. dwDeviceId - port id
  107. RoutingInfo - pointer to the routing info
  108. pdwRoutingInfoSize - pointer to the size of the routing info
  109. Return Value:
  110. TRUE on success
  111. --*/
  112. {
  113. return TRUE;
  114. }
  115. BOOL WINAPI
  116. FaxRouteSetRoutingInfo(
  117. LPCWSTR RoutingGuid,
  118. DWORD dwDeviceId,
  119. BYTE const *RoutingInfo,
  120. DWORD dwRoutingInfoSize
  121. )
  122. /*++
  123. Routine Description:
  124. Sets the routing info for a routing method
  125. Arguments:
  126. RoutingGuid - pointer to the GUID of the routing method
  127. dwDeviceId - port id
  128. RoutingInfo - pointer to the routing info
  129. dwRoutingInfoSize - size of the routing info
  130. Return Value:
  131. TRUE on success
  132. --*/
  133. {
  134. return TRUE;
  135. }
  136. BOOL WINAPI
  137. FaxRouteDeviceEnable(
  138. LPCWSTR RoutingGuid,
  139. DWORD dwDeviceId,
  140. LONG bEnable
  141. )
  142. /*++
  143. Routine Description:
  144. Enables a routing method
  145. Arguments:
  146. RoutingGuid - pointer to the GUID of the routing method
  147. dwDeviceId - port id
  148. bEnable - indicates whether the routing method is enabled or disabled
  149. Return Value:
  150. TRUE on success
  151. --*/
  152. {
  153. return TRUE;
  154. }
  155. BOOL WINAPI
  156. FaxRouteDeviceChangeNotification(
  157. DWORD dwDeviceId,
  158. BOOL bNewDevice
  159. )
  160. /*++
  161. Routine Description:
  162. Handles a device change
  163. Arguments:
  164. dwDeviceId - port id
  165. bNewDevice - indicates whether the device is new
  166. Return Value:
  167. TRUE on success
  168. --*/
  169. {
  170. return TRUE;
  171. }
  172. BOOL WINAPI
  173. FaxRcv(
  174. PFAX_ROUTE pFaxRoute,
  175. PVOID *FailureData,
  176. LPDWORD pdwFailureDataSize
  177. )
  178. /*++
  179. Routine Description:
  180. Routing method. This routing method signals a named event.
  181. Arguments:
  182. pFaxRoute - pointer to the fax routing structure
  183. FailureData - pointer to the failure data
  184. pdwFailureDataSize - size of the failure data
  185. Return Value:
  186. TRUE on success
  187. --*/
  188. {
  189. // hFaxRcvExtKey is the handle to the FaxRcv Extension Registry key
  190. HKEY hFaxRcvExtKey;
  191. // bEnable indicates whether the Routing method is enabled
  192. BOOL bEnable;
  193. // szTiffFile is the name of the received fax
  194. WCHAR szTiffFile[_MAX_PATH];
  195. // szCopyTiffFile is the name of the copy of the received fax
  196. WCHAR szCopyTiffFile[_MAX_PATH];
  197. // szDrive is the drive of the received fax
  198. WCHAR szDrive[_MAX_DRIVE];
  199. // szDir is the dir of the received fax
  200. WCHAR szDir[_MAX_DIR];
  201. // szFile is the name of the received fax
  202. WCHAR szFile[_MAX_FNAME];
  203. // szExt is the extension of the received fax
  204. WCHAR szExt[_MAX_EXT];
  205. UINT_PTR upOffset;
  206. DWORD cb;
  207. // Wait for access to the FaxRcv named mutex
  208. WaitForSingleObject(g_hFaxRcvMutex, INFINITE);
  209. // Open the FaxRcv Extension Registry key
  210. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, FAXRCV_EXT_REGKEY, 0, KEY_ALL_ACCESS, &hFaxRcvExtKey) != ERROR_SUCCESS) {
  211. // Release access to the FaxRcv named mutex
  212. ReleaseMutex(g_hFaxRcvMutex);
  213. return TRUE;
  214. }
  215. // Set cb
  216. cb = sizeof(BOOL);
  217. // Query the FaxRcv Extension bEnable Registry value
  218. if (RegQueryValueEx(hFaxRcvExtKey, BENABLE_EXT_REGVAL, NULL, NULL, (LPBYTE) &bEnable, &cb) != ERROR_SUCCESS) {
  219. // Close the FaxRcv Extension Registry key
  220. RegCloseKey(hFaxRcvExtKey);
  221. // Release access to the FaxRcv named mutex
  222. ReleaseMutex(g_hFaxRcvMutex);
  223. return TRUE;
  224. }
  225. // Close the FaxRcv Extension Registry key
  226. RegCloseKey(hFaxRcvExtKey);
  227. if (!bEnable) {
  228. // Release access to the FaxRcv named mutex
  229. ReleaseMutex(g_hFaxRcvMutex);
  230. return TRUE;
  231. }
  232. // Set cb
  233. cb = sizeof(szTiffFile);
  234. // Initialize szTiffFile
  235. ZeroMemory(szTiffFile, cb);
  236. // Get the file
  237. if (!g_pFaxRouteGetFile(pFaxRoute->JobId, 1, szTiffFile, &cb)) {
  238. // Release access to the FaxRcv named mutex
  239. ReleaseMutex(g_hFaxRcvMutex);
  240. return FALSE;
  241. }
  242. // Initialize szDrive
  243. ZeroMemory(szDrive, sizeof(szDrive));
  244. // Initialize szDir
  245. ZeroMemory(szDir, sizeof(szDir));
  246. // Initialize szFile
  247. ZeroMemory(szFile, sizeof(szFile));
  248. // Initialize szExt
  249. ZeroMemory(szExt, sizeof(szExt));
  250. _wsplitpath(szTiffFile, szDrive, szDir, szFile, szExt);
  251. // Initialize szCopyTiffFile
  252. ZeroMemory(szCopyTiffFile, sizeof(szCopyTiffFile));
  253. // Set szCopyTiffFile
  254. wsprintf(szCopyTiffFile, L"%s%s%s%s%s", szDrive, szDir, L"Copy of ", szFile, szExt);
  255. // Copy szTiffFile to szCopyTiffFile
  256. CopyFile(szTiffFile, szCopyTiffFile, FALSE);
  257. // Determine the memory required by FaxRcv memory map
  258. cb = (lstrlen(szCopyTiffFile) + 1) * sizeof(WCHAR);
  259. cb += (lstrlen(pFaxRoute->Tsid) + 1) * sizeof(WCHAR);
  260. cb += sizeof(DWORD);
  261. if (g_pFaxRcvView) {
  262. // Delete szCopyTiffFile
  263. DeleteFile((LPWSTR) g_pFaxRcvView);
  264. // Close FaxRcv memory map view
  265. UnmapViewOfFile(g_pFaxRcvView);
  266. }
  267. if (g_hFaxRcvMap) {
  268. // Close FaxRcv memory map
  269. CloseHandle(g_hFaxRcvMap);
  270. }
  271. // Create FaxRcv memory map
  272. g_hFaxRcvMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, cb, FAXRCV_MAP);
  273. // Create FaxRcv memory map view
  274. g_pFaxRcvView = (LPBYTE) MapViewOfFile(g_hFaxRcvMap, FILE_MAP_WRITE, 0, 0, 0);
  275. // Set upOffset
  276. upOffset = 0;
  277. // Set szCopyTiffFile
  278. lstrcpy((LPWSTR) ((UINT_PTR) g_pFaxRcvView + upOffset), szCopyTiffFile);
  279. upOffset += (lstrlen(szCopyTiffFile) + 1) * sizeof(WCHAR);
  280. // Set Tsid
  281. lstrcpy((LPWSTR) ((UINT_PTR) g_pFaxRcvView + upOffset), pFaxRoute->Tsid);
  282. upOffset += (lstrlen(pFaxRoute->Tsid) + 1) * sizeof(WCHAR);
  283. // Set DeviceId
  284. CopyMemory((LPDWORD) ((UINT_PTR) g_pFaxRcvView + upOffset), &pFaxRoute->DeviceId, sizeof(DWORD));
  285. // Signal FaxRcv named event
  286. SetEvent(g_hFaxRcvEvent);
  287. // Release access to the FaxRcv named mutex
  288. ReleaseMutex(g_hFaxRcvMutex);
  289. return TRUE;
  290. }