Leaked source code of windows server 2003
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.

510 lines
14 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. Revision History:
  10. 20/10/99 -danl-
  11. Handle errors and get proper server name in ServiceEntry.
  12. dd/mm/yy -author-
  13. description
  14. --*/
  15. #include "faxxp.h"
  16. #include "debugex.h"
  17. #include <faxres.h>
  18. #pragma hdrstop
  19. //
  20. // globals
  21. //
  22. LPALLOCATEBUFFER gpfnAllocateBuffer; // MAPIAllocateBuffer function
  23. LPALLOCATEMORE gpfnAllocateMore; // MAPIAllocateMore function
  24. LPFREEBUFFER gpfnFreeBuffer; // MAPIFreeBuffer function
  25. HINSTANCE g_hModule = NULL; // DLL handle
  26. HINSTANCE g_hResource = NULL; // Resource DLL handle
  27. HMODULE g_hModRichEdit;
  28. MAPIUID g_FaxGuid = FAX_XP_GUID;
  29. extern "C"
  30. DWORD
  31. DllMain(
  32. HINSTANCE hInstance,
  33. DWORD Reason,
  34. LPVOID Context
  35. )
  36. /*++
  37. Routine Description:
  38. DLL initialization function.
  39. Arguments:
  40. hInstance - Instance handle
  41. Reason - Reason for the entrypoint being called
  42. Context - Context record
  43. Return Value:
  44. TRUE - Initialization succeeded
  45. FALSE - Initialization failed
  46. --*/
  47. {
  48. DWORD dwRet = TRUE;
  49. DBG_ENTER(TEXT("DllMain"),dwRet,TEXT("Reason=%d,Context=%d"),Reason,Context);
  50. if (Reason == DLL_PROCESS_ATTACH)
  51. {
  52. DisableThreadLibraryCalls( hInstance );
  53. HeapInitialize( NULL, MapiMemAlloc, MapiMemFree, MapiMemReAlloc );
  54. g_hModule = hInstance;
  55. g_hResource = GetResInstance(hInstance);
  56. if(!g_hResource)
  57. {
  58. return FALSE;
  59. }
  60. }
  61. else if (Reason == DLL_PROCESS_DETACH)
  62. {
  63. FreeResInstance();
  64. }
  65. return dwRet;
  66. }
  67. STDINITMETHODIMP
  68. XPProviderInit(
  69. HINSTANCE hInstance,
  70. LPMALLOC lpMalloc,
  71. LPALLOCATEBUFFER lpAllocateBuffer,
  72. LPALLOCATEMORE lpAllocateMore,
  73. LPFREEBUFFER lpFreeBuffer,
  74. ULONG ulFlags,
  75. ULONG ulMAPIVer,
  76. ULONG * lpulProviderVer,
  77. LPXPPROVIDER * lppXPProvider
  78. )
  79. /*++
  80. Routine Description:
  81. Entry point called by the MAPI spooler when a profile uses this
  82. transport. The spooler calls this method and expects a pointer to an
  83. implementation of the IXPProvider interface. MAPI uses the returned
  84. IXPProvider interface pointer to logon on the transport provider.
  85. Arguments:
  86. Refer to MAPI Documentation for this method.
  87. Return Value:
  88. An HRESULT.
  89. --*/
  90. {
  91. HRESULT hr = S_OK;
  92. CXPProvider * pXPProvider = NULL;
  93. DBG_ENTER(TEXT("XPProviderInit"),hr,TEXT("ulFlags=%d,ulMAPIVer=%d"),ulFlags,ulMAPIVer);
  94. gpfnAllocateBuffer = lpAllocateBuffer;
  95. gpfnAllocateMore = lpAllocateMore;
  96. gpfnFreeBuffer = lpFreeBuffer;
  97. if (!g_hModRichEdit)
  98. {
  99. g_hModRichEdit = LoadLibrary( _T("RICHED32.DLL") );
  100. }
  101. __try
  102. {
  103. pXPProvider = new CXPProvider( hInstance );
  104. }
  105. __except (EXCEPTION_EXECUTE_HANDLER)
  106. {
  107. //
  108. // Do nothing (InitializeCriticalSection threw exception)
  109. //
  110. hr = E_OUTOFMEMORY;
  111. goto exit;
  112. }
  113. if (!pXPProvider)
  114. {
  115. hr = E_OUTOFMEMORY;
  116. goto exit;
  117. }
  118. *lppXPProvider = (LPXPPROVIDER)pXPProvider;
  119. *lpulProviderVer = CURRENT_SPI_VERSION;
  120. exit:
  121. return hr;
  122. }
  123. HRESULT STDAPICALLTYPE
  124. CreateDefaultPropertyTags(
  125. LPPROFSECT pProfileObj
  126. )
  127. /*++
  128. Routine Description:
  129. Creates the default property tags & values.
  130. Arguments:
  131. pProfileObj - Profile object.
  132. Return Value:
  133. An HRESULT.
  134. --*/
  135. {
  136. HRESULT hResult;
  137. DBG_ENTER(TEXT("CreateDefaultPropertyTags"),hResult);
  138. SPropValue spvProps[NUM_FAX_PROPERTIES] = { 0 };
  139. PPRINTER_INFO_2 PrinterInfo = NULL;
  140. DWORD CountPrinters;
  141. LPTSTR FaxPrinterName = NULL;
  142. TCHAR szEmpty[2] = {0};
  143. LOGFONT FontStruct;
  144. HFONT hFont;
  145. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &CountPrinters );
  146. if (PrinterInfo)
  147. {
  148. DWORD i;
  149. for (i=0; i<CountPrinters; i++)
  150. {
  151. if (_tcscmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0)
  152. {
  153. FaxPrinterName = StringDup( PrinterInfo[i].pPrinterName );
  154. if(NULL == FaxPrinterName)
  155. {
  156. VERBOSE(MEM_ERR, TEXT("StringDup Failed in xport\\faxxp.cpp\\CreateDefaultPropertyTags"));
  157. hResult = E_OUTOFMEMORY;
  158. goto exit;
  159. }
  160. break;
  161. }
  162. }
  163. }
  164. spvProps[PROP_FAX_PRINTER_NAME].ulPropTag = PR_FAX_PRINTER_NAME;
  165. spvProps[PROP_FAX_PRINTER_NAME].Value.bin.cb = FaxPrinterName ? (_tcslen(FaxPrinterName) + 1) * sizeof(TCHAR)
  166. : (_tcslen(szEmpty) + 1) * sizeof(TCHAR);
  167. spvProps[PROP_FAX_PRINTER_NAME].Value.bin.lpb = (LPBYTE) ((FaxPrinterName) ? FaxPrinterName : szEmpty);
  168. spvProps[PROP_COVERPAGE_NAME].ulPropTag = PR_COVERPAGE_NAME;
  169. spvProps[PROP_COVERPAGE_NAME].Value.bin.cb = (_tcslen(szEmpty) + 1) * sizeof(TCHAR);
  170. spvProps[PROP_COVERPAGE_NAME].Value.bin.lpb= (LPBYTE)szEmpty;
  171. spvProps[PROP_USE_COVERPAGE].ulPropTag = PR_USE_COVERPAGE;
  172. spvProps[PROP_USE_COVERPAGE].Value.ul = 0;
  173. spvProps[PROP_SERVER_COVERPAGE].ulPropTag = PR_SERVER_COVERPAGE;
  174. spvProps[PROP_SERVER_COVERPAGE].Value.ul = 0;
  175. hFont = (HFONT) GetStockObject( SYSTEM_FIXED_FONT );
  176. GetObject( hFont, sizeof(LOGFONT), &FontStruct );
  177. if(FontStruct.lfHeight > 0)
  178. {
  179. FontStruct.lfHeight *= -1;
  180. }
  181. FontStruct.lfWidth = 0;
  182. spvProps[PROP_FONT].ulPropTag = PR_FONT;
  183. spvProps[PROP_FONT].Value.bin.cb = sizeof(LOGFONT);
  184. spvProps[PROP_FONT].Value.bin.lpb = (LPBYTE) &FontStruct;
  185. spvProps[PROP_SEND_SINGLE_RECEIPT].ulPropTag = PR_SEND_SINGLE_RECEIPT;
  186. spvProps[PROP_SEND_SINGLE_RECEIPT].Value.ul = TRUE;
  187. spvProps[PROP_ATTACH_FAX].ulPropTag = PR_ATTACH_FAX;
  188. spvProps[PROP_ATTACH_FAX].Value.ul = FALSE;
  189. LPSPropProblemArray lpProblems = NULL;
  190. hResult = pProfileObj->SetProps( sizeof(spvProps)/sizeof(SPropValue), spvProps, &lpProblems);
  191. if(FAILED(hResult))
  192. {
  193. hResult = ::GetLastError();
  194. CALL_FAIL(GENERAL_ERR, TEXT("SetProps"), hResult);
  195. goto exit;
  196. }
  197. if (lpProblems)
  198. {
  199. hResult = MAPI_E_NOT_FOUND;
  200. MAPIFreeBuffer(lpProblems);
  201. }
  202. exit:
  203. MemFree(PrinterInfo);
  204. MemFree(FaxPrinterName);
  205. return hResult;
  206. }
  207. HRESULT STDAPICALLTYPE
  208. ServiceEntry(
  209. HINSTANCE hInstance,
  210. LPMALLOC pMallocObj,
  211. LPMAPISUP pSupObj,
  212. ULONG ulUIParam,
  213. ULONG ulFlags,
  214. ULONG ulContext,
  215. ULONG ulCfgPropCount,
  216. LPSPropValue pCfgProps,
  217. LPPROVIDERADMIN pAdminProvObj,
  218. LPMAPIERROR * ppMAPIError
  219. )
  220. /*++
  221. Routine Description:
  222. Called by the profile setup API to display the provider
  223. configuration properties for this transport provider
  224. Arguments:
  225. Refer to MAPI Documentation for this method.
  226. Return Value:
  227. An HRESULT.
  228. --*/
  229. {
  230. HRESULT hResult = S_OK;
  231. DBG_ENTER(TEXT("ServiceEntry"),hResult,TEXT("ulFlags=%d,ulContext=%d"),ulFlags,ulContext);
  232. LPPROFSECT pProfileObj = NULL;
  233. ULONG PropCount = 0;
  234. LPSPropValue pProps = NULL;
  235. FAXXP_CONFIG FaxConfig = {0};
  236. INT_PTR nDlgRes;
  237. //
  238. // First check if the context of the call is UNINSTALL
  239. // If it is then pSupObj == NULL
  240. //
  241. if (ulContext == MSG_SERVICE_UNINSTALL)
  242. {
  243. goto exit;
  244. }
  245. if (ulContext == MSG_SERVICE_DELETE)
  246. {
  247. goto exit;
  248. }
  249. if (ulContext == MSG_SERVICE_INSTALL)
  250. {
  251. goto exit;
  252. }
  253. if (ulContext == MSG_SERVICE_PROVIDER_CREATE ||
  254. ulContext == MSG_SERVICE_PROVIDER_DELETE)
  255. {
  256. hResult = MAPI_E_NO_SUPPORT;
  257. goto exit;
  258. }
  259. Assert(NULL != pSupObj);
  260. hResult = pSupObj->GetMemAllocRoutines( &gpfnAllocateBuffer, &gpfnAllocateMore, &gpfnFreeBuffer );
  261. if(FAILED(hResult))
  262. {
  263. CALL_FAIL(GENERAL_ERR, TEXT("IMAPISupport::GetMemAllocRoutines"), hResult);
  264. goto exit;
  265. }
  266. hResult = pAdminProvObj->OpenProfileSection(&g_FaxGuid,
  267. NULL,
  268. MAPI_MODIFY,
  269. &pProfileObj);
  270. if (FAILED(hResult))
  271. {
  272. CALL_FAIL(GENERAL_ERR, TEXT("IProviderAdmin::OpenProfileSection"), hResult);
  273. goto exit;
  274. }
  275. if (ulContext == MSG_SERVICE_CREATE)
  276. {
  277. hResult = CreateDefaultPropertyTags( pProfileObj );
  278. goto exit;
  279. }
  280. if (ulContext != MSG_SERVICE_CONFIGURE)
  281. {
  282. goto exit;
  283. }
  284. //
  285. //get fax related props from profileObj, to give them as initial values for the DlgBox
  286. //
  287. hResult = pProfileObj->GetProps((LPSPropTagArray) &sptFaxProps,
  288. 0,
  289. &PropCount,
  290. &pProps);
  291. if (!HR_SUCCEEDED(hResult))
  292. {
  293. CALL_FAIL(GENERAL_ERR, TEXT("GetProps"), hResult);
  294. goto exit;
  295. }
  296. FaxConfig.PrinterName = StringDup( (LPTSTR)pProps[PROP_FAX_PRINTER_NAME].Value.bin.lpb);
  297. if (NULL == FaxConfig.PrinterName)
  298. {
  299. hResult = E_OUTOFMEMORY;
  300. goto exit;
  301. }
  302. FaxConfig.CoverPageName = StringDup((LPTSTR)pProps[PROP_COVERPAGE_NAME].Value.bin.lpb);
  303. if (NULL == FaxConfig.CoverPageName)
  304. {
  305. hResult = E_OUTOFMEMORY;
  306. goto exit;
  307. }
  308. FaxConfig.UseCoverPage = GetDwordProperty( pProps, PROP_USE_COVERPAGE );
  309. FaxConfig.ServerCoverPage = GetDwordProperty( pProps, PROP_SERVER_COVERPAGE );
  310. FaxConfig.SendSingleReceipt = GetDwordProperty( pProps, PROP_SEND_SINGLE_RECEIPT );
  311. FaxConfig.bAttachFax = GetDwordProperty( pProps, PROP_ATTACH_FAX );
  312. FaxConfig.ServerName = NULL;
  313. if(!GetServerNameFromPrinterName(FaxConfig.PrinterName,&FaxConfig.ServerName))
  314. {
  315. //
  316. // If we fail getting server name we will default to local
  317. //
  318. CALL_FAIL(GENERAL_ERR, TEXT("GetServerNameFromPrinterName"), 0);
  319. }
  320. if (!GetBinaryProperty( pProps, PROP_FONT, &FaxConfig.FontStruct, sizeof(FaxConfig.FontStruct)))
  321. {
  322. HFONT hFont = (HFONT) GetStockObject( SYSTEM_FIXED_FONT );
  323. GetObject( hFont, sizeof(LOGFONT), &FaxConfig.FontStruct );
  324. if(FaxConfig.FontStruct.lfHeight > 0)
  325. {
  326. FaxConfig.FontStruct.lfHeight *= -1;
  327. }
  328. FaxConfig.FontStruct.lfWidth = 0;
  329. }
  330. //
  331. //open a dialogBox to let user config those props
  332. //
  333. nDlgRes = DialogBoxParam(g_hResource,
  334. MAKEINTRESOURCE(IDD_FAX_PROP_CONFIG),
  335. (HWND)ULongToHandle(ulUIParam),
  336. ConfigDlgProc,
  337. (LPARAM) &FaxConfig);
  338. if(IDOK != nDlgRes)
  339. {
  340. if(-1 == nDlgRes)
  341. {
  342. hResult = E_FAIL;
  343. CALL_FAIL(GENERAL_ERR, TEXT("DialogBoxParam"), GetLastError());
  344. }
  345. goto exit;
  346. }
  347. //
  348. //update props' value in the profileObj
  349. //
  350. pProps[PROP_FAX_PRINTER_NAME].ulPropTag = PR_FAX_PRINTER_NAME;
  351. pProps[PROP_FAX_PRINTER_NAME].Value.bin.lpb = (LPBYTE) FaxConfig.PrinterName;
  352. pProps[PROP_FAX_PRINTER_NAME].Value.bin.cb = (_tcslen(FaxConfig.PrinterName) + 1)*sizeof(TCHAR) ;
  353. pProps[PROP_COVERPAGE_NAME].ulPropTag = PR_COVERPAGE_NAME;
  354. pProps[PROP_COVERPAGE_NAME].Value.bin.lpb = (LPBYTE)FaxConfig.CoverPageName;
  355. pProps[PROP_COVERPAGE_NAME].Value.bin.cb = (_tcslen(FaxConfig.CoverPageName) + 1)*sizeof(TCHAR) ;
  356. pProps[PROP_USE_COVERPAGE].ulPropTag = PR_USE_COVERPAGE;
  357. pProps[PROP_USE_COVERPAGE].Value.ul = FaxConfig.UseCoverPage;
  358. pProps[PROP_SERVER_COVERPAGE].ulPropTag = PR_SERVER_COVERPAGE;
  359. pProps[PROP_SERVER_COVERPAGE].Value.ul = FaxConfig.ServerCoverPage;
  360. pProps[PROP_FONT].ulPropTag = PR_FONT;
  361. pProps[PROP_FONT].Value.bin.lpb = (LPBYTE)&FaxConfig.FontStruct;
  362. pProps[PROP_FONT].Value.bin.cb = sizeof(FaxConfig.FontStruct);
  363. pProps[PROP_SEND_SINGLE_RECEIPT].ulPropTag = PR_SEND_SINGLE_RECEIPT;
  364. pProps[PROP_SEND_SINGLE_RECEIPT].Value.ul = FaxConfig.SendSingleReceipt;
  365. pProps[PROP_ATTACH_FAX].ulPropTag = PR_ATTACH_FAX;
  366. pProps[PROP_ATTACH_FAX].Value.ul = FaxConfig.bAttachFax;
  367. hResult = pProfileObj->SetProps( PropCount, pProps, NULL);
  368. exit:
  369. if (FaxConfig.PrinterName)
  370. {
  371. MemFree( FaxConfig.PrinterName );
  372. FaxConfig.PrinterName = NULL;
  373. }
  374. if (FaxConfig.CoverPageName)
  375. {
  376. MemFree( FaxConfig.CoverPageName );
  377. FaxConfig.CoverPageName = NULL;
  378. }
  379. if (FaxConfig.ServerName)
  380. {
  381. MemFree(FaxConfig.ServerName);
  382. FaxConfig.ServerName = NULL;
  383. }
  384. if (pProfileObj)
  385. {
  386. pProfileObj->Release();
  387. }
  388. if (pProps)
  389. {
  390. MAPIFreeBuffer( pProps );
  391. }
  392. return hResult;
  393. }