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.

305 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxdev.c
  5. Abstract:
  6. This module contains all access to the
  7. FAX device providers.
  8. Author:
  9. Wesley Witt (wesw) 22-Jan-1996
  10. Revision History:
  11. --*/
  12. #include "faxsvc.h"
  13. #pragma hdrstop
  14. LIST_ENTRY DeviceProviders;
  15. BOOL
  16. LoadDeviceProviders(
  17. PREG_FAX_SERVICE FaxReg
  18. )
  19. /*++
  20. Routine Description:
  21. Initializes all registered device providers.
  22. This function read the system registry to
  23. determine what device providers are available.
  24. All registered device providers are given the
  25. opportunity to initialize. Any failure causes
  26. the device provider to be unloaded.
  27. Arguments:
  28. None.
  29. Return Value:
  30. TRUE - The device providers are initialized.
  31. FALSE - The device providers could not be initialized.
  32. --*/
  33. {
  34. DWORD i;
  35. HMODULE hModule;
  36. PDEVICE_PROVIDER DeviceProvider;
  37. InitializeListHead( &DeviceProviders );
  38. for (i=0; i<FaxReg->DeviceProviderCount; i++) {
  39. hModule = LoadLibrary( FaxReg->DeviceProviders[i].ImageName );
  40. if (!hModule) {
  41. DebugPrint(( TEXT("LoadLibrary() failed: [%s], ec=%d"), FaxReg->DeviceProviders[i].ImageName, GetLastError() ));
  42. goto InitializationFailure;
  43. }
  44. DeviceProvider = (PDEVICE_PROVIDER) MemAlloc( sizeof(DEVICE_PROVIDER) );
  45. if (!DeviceProvider) {
  46. FreeLibrary( hModule );
  47. DebugPrint(( TEXT("Could not allocate memory for device provider %s"), FaxReg->DeviceProviders[i].ImageName ));
  48. goto InitializationFailure;
  49. }
  50. DeviceProvider->hModule = hModule;
  51. _tcscpy( DeviceProvider->FriendlyName, FaxReg->DeviceProviders[i].FriendlyName );
  52. _tcscpy( DeviceProvider->ImageName, FaxReg->DeviceProviders[i].ImageName );
  53. _tcscpy( DeviceProvider->ProviderName, FaxReg->DeviceProviders[i].ProviderName );
  54. DeviceProvider->FaxDevInitialize = (PFAXDEVINITIALIZE) GetProcAddress(
  55. hModule,
  56. "FaxDevInitialize"
  57. );
  58. DeviceProvider->FaxDevStartJob = (PFAXDEVSTARTJOB) GetProcAddress(
  59. hModule,
  60. "FaxDevStartJob"
  61. );
  62. DeviceProvider->FaxDevEndJob = (PFAXDEVENDJOB) GetProcAddress(
  63. hModule,
  64. "FaxDevEndJob"
  65. );
  66. DeviceProvider->FaxDevSend = (PFAXDEVSEND) GetProcAddress(
  67. hModule,
  68. "FaxDevSend"
  69. );
  70. DeviceProvider->FaxDevReceive = (PFAXDEVRECEIVE) GetProcAddress(
  71. hModule,
  72. "FaxDevReceive"
  73. );
  74. DeviceProvider->FaxDevReportStatus = (PFAXDEVREPORTSTATUS) GetProcAddress(
  75. hModule,
  76. "FaxDevReportStatus"
  77. );
  78. DeviceProvider->FaxDevAbortOperation = (PFAXDEVABORTOPERATION) GetProcAddress(
  79. hModule,
  80. "FaxDevAbortOperation"
  81. );
  82. DeviceProvider->FaxDevVirtualDeviceCreation = (PFAXDEVVIRTUALDEVICECREATION) GetProcAddress(
  83. hModule,
  84. "FaxDevVirtualDeviceCreation"
  85. );
  86. if (DeviceProvider->FaxDevInitialize &&
  87. DeviceProvider->FaxDevStartJob &&
  88. DeviceProvider->FaxDevEndJob &&
  89. DeviceProvider->FaxDevSend &&
  90. DeviceProvider->FaxDevReceive &&
  91. DeviceProvider->FaxDevReportStatus &&
  92. DeviceProvider->FaxDevAbortOperation ) {
  93. //
  94. // create the device provider's heap
  95. //
  96. DeviceProvider->HeapHandle = HeapCreate( 0, 1024*100, 1024*1024*2 );
  97. if (!DeviceProvider->HeapHandle) {
  98. FreeLibrary( hModule );
  99. MemFree( DeviceProvider );
  100. goto InitializationFailure;
  101. } else {
  102. InsertTailList( &DeviceProviders, &DeviceProvider->ListEntry );
  103. }
  104. } else {
  105. //
  106. // the device provider dll does not have a complete export list
  107. //
  108. MemFree( DeviceProvider );
  109. FreeLibrary( hModule );
  110. DebugPrint(( TEXT("Device provider FAILED to initialized [%s]"), FaxReg->DeviceProviders[i].FriendlyName ));
  111. goto InitializationFailure;
  112. }
  113. goto next;
  114. InitializationFailure:
  115. FaxLog(
  116. FAXLOG_CATEGORY_INIT,
  117. FAXLOG_LEVEL_NONE,
  118. 2,
  119. MSG_FSP_INIT_FAILED,
  120. FaxReg->DeviceProviders[i].FriendlyName,
  121. FaxReg->DeviceProviders[i].ImageName
  122. );
  123. next:
  124. ;
  125. }
  126. return TRUE;
  127. }
  128. BOOL
  129. InitializeDeviceProviders(
  130. VOID
  131. )
  132. {
  133. PLIST_ENTRY Next;
  134. PDEVICE_PROVIDER DeviceProvider;
  135. Next = DeviceProviders.Flink;
  136. if (!Next) {
  137. return FALSE;
  138. }
  139. while ((ULONG_PTR)Next != (ULONG_PTR)&DeviceProviders) {
  140. DeviceProvider = CONTAINING_RECORD( Next, DEVICE_PROVIDER, ListEntry );
  141. Next = DeviceProvider->ListEntry.Flink;
  142. //
  143. // the device provider exporta ALL the requisite functions
  144. // now try to initialize it
  145. //
  146. __try {
  147. if (DeviceProvider->FaxDevInitialize(
  148. hLineApp,
  149. DeviceProvider->HeapHandle,
  150. &DeviceProvider->FaxDevCallback,
  151. FaxDeviceProviderCallback)) {
  152. //
  153. // all is ok
  154. //
  155. DebugPrint(( TEXT("Device provider initialized [%s]"), DeviceProvider->FriendlyName ));
  156. } else {
  157. //
  158. // initialization failed, so unload the provider dll
  159. //
  160. FreeLibrary( DeviceProvider->hModule );
  161. DebugPrint(( TEXT("Device provider FAILED to initialized [%s]"), DeviceProvider->FriendlyName ));
  162. MemFree( DeviceProvider );
  163. }
  164. } __except (EXCEPTION_EXECUTE_HANDLER) {
  165. FreeLibrary( DeviceProvider->hModule );
  166. DebugPrint(( TEXT("Device provider FAILED to initialized [%s]"), DeviceProvider->FriendlyName ));
  167. MemFree( DeviceProvider );
  168. }
  169. }
  170. return TRUE;
  171. }
  172. PDEVICE_PROVIDER
  173. FindDeviceProvider(
  174. LPTSTR ProviderName
  175. )
  176. /*++
  177. Routine Description:
  178. Locates a device provider in the linked list
  179. of device providers based on the provider name.
  180. The device provider name is case sensitive.
  181. Arguments:
  182. ProviderName - Specifies the device provider name to locate.
  183. None.
  184. Return Value:
  185. Pointer to a DEVICE_PROVIDER structure, or NULL for failure.
  186. --*/
  187. {
  188. PLIST_ENTRY Next;
  189. PDEVICE_PROVIDER Provider;
  190. Next = DeviceProviders.Flink;
  191. if (!Next) {
  192. return NULL;
  193. }
  194. while ((ULONG_PTR)Next != (ULONG_PTR)&DeviceProviders) {
  195. Provider = CONTAINING_RECORD( Next, DEVICE_PROVIDER, ListEntry );
  196. Next = Provider->ListEntry.Flink;
  197. if (_tcscmp( Provider->ProviderName, ProviderName ) == 0) {
  198. return Provider;
  199. }
  200. }
  201. return NULL;
  202. }
  203. BOOL CALLBACK
  204. FaxDeviceProviderCallback(
  205. IN HANDLE FaxHandle,
  206. IN DWORD DeviceId,
  207. IN DWORD_PTR Param1,
  208. IN DWORD_PTR Param2,
  209. IN DWORD_PTR Param3
  210. )
  211. {
  212. return TRUE;
  213. }