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.

355 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxxp.cpp
  5. Abstract:
  6. This module contains routines for the fax transport provider.
  7. Author:
  8. Wesley Witt (wesw) 13-Aug-1996
  9. --*/
  10. #include "faxxp.h"
  11. #pragma hdrstop
  12. //
  13. // globals
  14. //
  15. LPALLOCATEBUFFER gpfnAllocateBuffer; // MAPIAllocateBuffer function
  16. LPALLOCATEMORE gpfnAllocateMore; // MAPIAllocateMore function
  17. LPFREEBUFFER gpfnFreeBuffer; // MAPIFreeBuffer function
  18. HINSTANCE FaxXphInstance;
  19. HMODULE hModRichEdit;
  20. MAPIUID FaxGuid = FAX_XP_GUID;
  21. extern "C"
  22. DWORD
  23. FaxXpDllEntry(
  24. HINSTANCE hInstance,
  25. DWORD Reason,
  26. LPVOID Context
  27. )
  28. /*++
  29. Routine Description:
  30. DLL initialization function.
  31. Arguments:
  32. hInstance - Instance handle
  33. Reason - Reason for the entrypoint being called
  34. Context - Context record
  35. Return Value:
  36. TRUE - Initialization succeeded
  37. FALSE - Initialization failed
  38. --*/
  39. {
  40. if (Reason == DLL_PROCESS_ATTACH) {
  41. FaxXphInstance = hInstance;
  42. DisableThreadLibraryCalls( hInstance );
  43. HeapInitialize( NULL, MapiMemAlloc, MapiMemFree, HEAPINIT_NO_VALIDATION | HEAPINIT_NO_STRINGS );
  44. }
  45. if (Reason == DLL_PROCESS_DETACH) {
  46. }
  47. return TRUE;
  48. }
  49. STDINITMETHODIMP
  50. XPProviderInit(
  51. HINSTANCE hInstance,
  52. LPMALLOC lpMalloc,
  53. LPALLOCATEBUFFER lpAllocateBuffer,
  54. LPALLOCATEMORE lpAllocateMore,
  55. LPFREEBUFFER lpFreeBuffer,
  56. ULONG ulFlags,
  57. ULONG ulMAPIVer,
  58. ULONG * lpulProviderVer,
  59. LPXPPROVIDER * lppXPProvider
  60. )
  61. /*++
  62. Routine Description:
  63. Entry point called by the MAPI spooler when a profile uses this
  64. transport. The spooler calls this method and expects a pointer to an
  65. implementation of the IXPProvider interface. MAPI uses the returned
  66. IXPProvider interface pointer to logon on the transport provider.
  67. Arguments:
  68. Refer to MAPI Documentation for this method.
  69. Return Value:
  70. An HRESULT.
  71. --*/
  72. {
  73. gpfnAllocateBuffer = lpAllocateBuffer;
  74. gpfnAllocateMore = lpAllocateMore;
  75. gpfnFreeBuffer = lpFreeBuffer;
  76. if (!hModRichEdit) {
  77. hModRichEdit = LoadLibrary( "RICHED32.DLL" );
  78. }
  79. CXPProvider * pXPProvider = new CXPProvider( hInstance );
  80. if (!pXPProvider) {
  81. return E_OUTOFMEMORY;
  82. }
  83. *lppXPProvider = (LPXPPROVIDER)pXPProvider;
  84. *lpulProviderVer = CURRENT_SPI_VERSION;
  85. return 0;
  86. }
  87. HRESULT STDAPICALLTYPE
  88. CreateDefaultPropertyTags(
  89. LPPROFSECT pProfileObj
  90. )
  91. /*++
  92. Routine Description:
  93. Creates the default property tags & values.
  94. Arguments:
  95. pProfileObj - Profile object.
  96. Return Value:
  97. An HRESULT.
  98. --*/
  99. {
  100. HRESULT hResult;
  101. SPropValue spvProps[NUM_FAX_PROPERTIES] = { 0 };
  102. PPRINTER_INFO_2 PrinterInfo;
  103. DWORD CountPrinters;
  104. LPSTR FaxPrinterName = NULL;
  105. LOGFONT FontStruct;
  106. HFONT hFont;
  107. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &CountPrinters, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS );
  108. if (PrinterInfo) {
  109. DWORD i;
  110. for (i=0; i<CountPrinters; i++) {
  111. if (strcmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0) {
  112. FaxPrinterName = StringDup( PrinterInfo[i].pPrinterName );
  113. break;
  114. }
  115. }
  116. MemFree(PrinterInfo);
  117. }
  118. spvProps[PROP_FAX_PRINTER_NAME].ulPropTag = PR_FAX_PRINTER_NAME;
  119. spvProps[PROP_FAX_PRINTER_NAME].Value.LPSZ = FaxPrinterName ? FaxPrinterName : "";
  120. spvProps[PROP_COVERPAGE_NAME].ulPropTag = PR_COVERPAGE_NAME;
  121. spvProps[PROP_COVERPAGE_NAME].Value.LPSZ = "";
  122. spvProps[PROP_USE_COVERPAGE].ulPropTag = PR_USE_COVERPAGE;
  123. spvProps[PROP_USE_COVERPAGE].Value.ul = 0;
  124. spvProps[PROP_SERVER_COVERPAGE].ulPropTag = PR_SERVER_COVERPAGE;
  125. spvProps[PROP_SERVER_COVERPAGE].Value.ul = 0;
  126. hFont = (HFONT) GetStockObject( SYSTEM_FIXED_FONT );
  127. GetObject( hFont, sizeof(LOGFONT), &FontStruct );
  128. spvProps[PROP_FONT].ulPropTag = PR_FONT;
  129. spvProps[PROP_FONT].Value.bin.cb = sizeof(LOGFONT);
  130. spvProps[PROP_FONT].Value.bin.lpb = (LPBYTE) &FontStruct;
  131. hResult = pProfileObj->SetProps( sizeof(spvProps)/sizeof(SPropValue), spvProps, NULL);
  132. return hResult;
  133. }
  134. HRESULT STDAPICALLTYPE
  135. ServiceEntry(
  136. HINSTANCE hInstance,
  137. LPMALLOC pMallocObj,
  138. LPMAPISUP pSupObj,
  139. ULONG ulUIParam,
  140. ULONG ulFlags,
  141. ULONG ulContext,
  142. ULONG ulCfgPropCount,
  143. LPSPropValue pCfgProps,
  144. LPPROVIDERADMIN pAdminProvObj,
  145. LPMAPIERROR * ppMAPIError
  146. )
  147. /*++
  148. Routine Description:
  149. Called by the profile setup API to display the provider
  150. configuration properties for this transport provider
  151. Arguments:
  152. Refer to MAPI Documentation for this method.
  153. Return Value:
  154. An HRESULT.
  155. --*/
  156. {
  157. HRESULT hResult = S_OK;
  158. LPPROFSECT pProfileObj = NULL;
  159. ULONG PropCount = 0;
  160. LPSPropValue pProps = NULL;
  161. FAXXP_CONFIG FaxConfig;
  162. pSupObj->GetMemAllocRoutines( &gpfnAllocateBuffer, &gpfnAllocateMore, &gpfnFreeBuffer );
  163. hResult = pAdminProvObj->OpenProfileSection(
  164. &FaxGuid,
  165. NULL,
  166. MAPI_MODIFY,
  167. &pProfileObj
  168. );
  169. if (hResult) {
  170. goto exit;
  171. }
  172. if (ulContext == MSG_SERVICE_CREATE) {
  173. CreateDefaultPropertyTags( pProfileObj );
  174. goto exit;
  175. }
  176. if (ulContext == MSG_SERVICE_DELETE) {
  177. goto exit;
  178. }
  179. hResult = pProfileObj->GetProps(
  180. (LPSPropTagArray) &sptFaxProps,
  181. 0,
  182. &PropCount,
  183. &pProps
  184. );
  185. if (FAILED(hResult)) {
  186. goto exit;
  187. }
  188. FaxConfig.PrinterName = GetStringProperty( pProps, PROP_FAX_PRINTER_NAME );
  189. FaxConfig.CoverPageName = GetStringProperty( pProps, PROP_COVERPAGE_NAME );
  190. FaxConfig.UseCoverPage = GetDwordProperty( pProps, PROP_USE_COVERPAGE );
  191. FaxConfig.ServerCoverPage = GetDwordProperty( pProps, PROP_SERVER_COVERPAGE );
  192. #ifndef WIN95
  193. //
  194. // get the server name from the printer name
  195. //
  196. FaxConfig.ServerName = GetServerName(FaxConfig.PrinterName);
  197. //
  198. // nice idea but we should really defer this until it's needed, ie., if and when the
  199. // dialog comes up (otherwise we can fire up the fax service when it's not needed)
  200. //
  201. #if 0
  202. HANDLE hFax;
  203. PFAX_CONFIGURATION pFaxConfiguration;
  204. //
  205. // get the servercp flag
  206. //
  207. FaxConfig.ServerCpOnly = FALSE;
  208. if (FaxConnectFaxServer(FaxConfig.ServerName,&hFax) ) {
  209. if (FaxGetConfiguration(hFax,&pFaxConfiguration) ) {
  210. FaxConfig.ServerCpOnly = pFaxConfiguration->ServerCp;
  211. FaxFreeBuffer(pFaxConfiguration);
  212. }
  213. FaxClose(hFax);
  214. }
  215. #endif
  216. #endif
  217. if (!GetBinaryProperty( pProps, PROP_FONT, &FaxConfig.FontStruct, sizeof(FaxConfig.FontStruct) )) {
  218. HFONT hFont = (HFONT) GetStockObject( SYSTEM_FIXED_FONT );
  219. GetObject( hFont, sizeof(LOGFONT), &FaxConfig.FontStruct );
  220. }
  221. if (ulContext == MSG_SERVICE_CONFIGURE) {
  222. DialogBoxParam(
  223. hInstance,
  224. MAKEINTRESOURCE(FAX_CONFIG_DIALOG),
  225. (HWND) ulUIParam,
  226. ConfigDlgProc,
  227. (LPARAM) &FaxConfig
  228. );
  229. }
  230. pProps[PROP_FAX_PRINTER_NAME].ulPropTag = PR_FAX_PRINTER_NAME;
  231. pProps[PROP_FAX_PRINTER_NAME].Value.LPSZ = FaxConfig.PrinterName;
  232. pProps[PROP_COVERPAGE_NAME].ulPropTag = PR_COVERPAGE_NAME;
  233. pProps[PROP_COVERPAGE_NAME].Value.LPSZ = FaxConfig.CoverPageName;
  234. pProps[PROP_USE_COVERPAGE].ulPropTag = PR_USE_COVERPAGE;
  235. pProps[PROP_USE_COVERPAGE].Value.ul = FaxConfig.UseCoverPage;
  236. pProps[PROP_SERVER_COVERPAGE].ulPropTag = PR_SERVER_COVERPAGE;
  237. pProps[PROP_SERVER_COVERPAGE].Value.ul = FaxConfig.ServerCoverPage;
  238. pProps[PROP_FONT].ulPropTag = PR_FONT;
  239. pProps[PROP_FONT].Value.bin.lpb = (LPBYTE)&FaxConfig.FontStruct;
  240. pProps[PROP_FONT].Value.bin.cb = sizeof(FaxConfig.FontStruct);
  241. hResult = pProfileObj->SetProps( PropCount, pProps, NULL);
  242. if (FaxConfig.PrinterName) {
  243. MemFree( FaxConfig.PrinterName );
  244. }
  245. if (FaxConfig.CoverPageName) {
  246. MemFree( FaxConfig.CoverPageName );
  247. }
  248. if (FaxConfig.ServerName) {
  249. MemFree(FaxConfig.ServerName);
  250. }
  251. exit:
  252. if (pProfileObj) {
  253. pProfileObj->Release();
  254. }
  255. if (pProps) {
  256. MemFree( pProps );
  257. }
  258. return hResult;
  259. }