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.

5399 lines
136 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. config.c
  5. Abstract:
  6. This module contains the configuration
  7. specific WINFAX API functions.
  8. Author:
  9. Wesley Witt (wesw) 29-Nov-1996
  10. Revision History:
  11. --*/
  12. #include "faxapi.h"
  13. #pragma hdrstop
  14. #include <mbstring.h>
  15. BOOL
  16. WINAPI
  17. FaxGetConfigurationW(
  18. IN HANDLE FaxHandle,
  19. OUT PFAX_CONFIGURATIONW *FaxConfig
  20. )
  21. /*++
  22. Routine Description:
  23. Retrieves the FAX configuration from the FAX server.
  24. The SizeOfStruct in the FaxConfig argument MUST be
  25. set to a value=>= sizeof(FAX_CONFIGURATION).
  26. Arguments:
  27. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  28. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  29. Return Value:
  30. TRUE - Success
  31. FALSE - Failure, call GetLastError() for more error information.
  32. --*/
  33. {
  34. error_status_t ec;
  35. DWORD FaxConfigSize = 0;
  36. DEBUG_FUNCTION_NAME(TEXT("FaxGetConfigurationW"));
  37. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  38. SetLastError(ERROR_INVALID_HANDLE);
  39. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  40. return FALSE;
  41. }
  42. if (!FaxConfig) {
  43. SetLastError( ERROR_INVALID_PARAMETER );
  44. DebugPrintEx(DEBUG_ERR, _T("FaxConfig is NULL."));
  45. return FALSE;
  46. }
  47. *FaxConfig = NULL;
  48. //
  49. __try
  50. {
  51. ec = FAX_GetConfiguration(
  52. FH_FAX_HANDLE(FaxHandle),
  53. (LPBYTE*)FaxConfig,
  54. &FaxConfigSize
  55. );
  56. }
  57. __except (EXCEPTION_EXECUTE_HANDLER)
  58. {
  59. //
  60. // For some reason we got an exception.
  61. //
  62. ec = GetExceptionCode();
  63. DebugPrintEx(
  64. DEBUG_ERR,
  65. TEXT("Exception on RPC call to FAX_GetConfiguration. (ec: %ld)"),
  66. ec);
  67. }
  68. if (ec)
  69. {
  70. DumpRPCExtendedStatus();
  71. SetLastError( ec );
  72. return FALSE;
  73. }
  74. FixupStringPtrW( FaxConfig, (*FaxConfig)->ArchiveDirectory );
  75. (*FaxConfig)->Reserved = NULL;
  76. return TRUE;
  77. }
  78. BOOL
  79. WINAPI
  80. FaxGetConfigurationA(
  81. IN HANDLE FaxHandle,
  82. OUT PFAX_CONFIGURATIONA *FaxConfigA
  83. )
  84. /*++
  85. Routine Description:
  86. Retrieves the FAX configuration from the FAX server.
  87. The SizeOfStruct in the FaxConfig argument MUST be
  88. set to a value=>= sizeof(FAX_CONFIGURATION).
  89. Arguments:
  90. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  91. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  92. Return Value:
  93. TRUE - Success
  94. FALSE - Failure, call GetLastError() for more error information.
  95. --*/
  96. {
  97. DEBUG_FUNCTION_NAME(TEXT("FaxGetConfigurationA"));
  98. //
  99. // No need to Validate Parameters, FaxGetConfigurationW() will do that
  100. //
  101. if (!FaxGetConfigurationW(
  102. FaxHandle,
  103. (PFAX_CONFIGURATIONW*) FaxConfigA
  104. ))
  105. {
  106. DebugPrintEx(DEBUG_ERR, _T("FaxGetConfigurationW() is failed, ec = %ld."), GetLastError());
  107. return FALSE;
  108. }
  109. if (!ConvertUnicodeStringInPlace((LPWSTR) (*FaxConfigA)->ArchiveDirectory))
  110. {
  111. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  112. MemFree (*FaxConfigA);
  113. return FALSE;
  114. }
  115. (*FaxConfigA)->SizeOfStruct = sizeof(FAX_CONFIGURATIONA);
  116. return TRUE;
  117. } // FaxGetConfigurationA
  118. BOOL
  119. WINAPI
  120. FaxSetConfigurationW(
  121. IN HANDLE FaxHandle,
  122. IN const FAX_CONFIGURATIONW *FaxConfig
  123. )
  124. /*++
  125. Routine Description:
  126. Changes the FAX configuration on the FAX server.
  127. The SizeOfStruct in the FaxConfig argument MUST be
  128. set to a value == sizeof(FAX_CONFIGURATION).
  129. Arguments:
  130. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  131. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  132. Return Value:
  133. TRUE - Success
  134. FALSE - Failure, call GetLastError() for more error information.
  135. --*/
  136. {
  137. error_status_t ec;
  138. DEBUG_FUNCTION_NAME(TEXT("FaxSetConfigurationW"));
  139. //
  140. // Validate Parameters
  141. //
  142. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  143. SetLastError(ERROR_INVALID_HANDLE);
  144. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  145. return FALSE;
  146. }
  147. if (!FaxConfig) {
  148. SetLastError(ERROR_INVALID_PARAMETER);
  149. DebugPrintEx(DEBUG_ERR, _T("FaxConfig() is NULL."));
  150. return FALSE;
  151. }
  152. if (FaxConfig->SizeOfStruct != sizeof(FAX_CONFIGURATIONW)) {
  153. SetLastError(ERROR_INVALID_PARAMETER);
  154. DebugPrintEx(DEBUG_ERR, _T("FaxConfig->SizeOfStruct != sizeof(FAX_CONFIGURATIONW)"));
  155. return FALSE;
  156. }
  157. __try
  158. {
  159. ec = FAX_SetConfiguration( FH_FAX_HANDLE(FaxHandle), FaxConfig );
  160. }
  161. __except (EXCEPTION_EXECUTE_HANDLER)
  162. {
  163. //
  164. // For some reason we got an exception.
  165. //
  166. ec = GetExceptionCode();
  167. DebugPrintEx(DEBUG_ERR,
  168. _T("Exception on RPC call to FAX_SetConfiguration. (ec: %ld)"),
  169. ec);
  170. }
  171. if (ec)
  172. {
  173. DumpRPCExtendedStatus();
  174. SetLastError( ec );
  175. return FALSE;
  176. }
  177. return TRUE;
  178. }
  179. BOOL
  180. WINAPI
  181. FaxSetConfigurationA(
  182. IN HANDLE FaxHandle,
  183. IN const FAX_CONFIGURATIONA *FaxConfig
  184. )
  185. {
  186. error_status_t ec = ERROR_SUCCESS;
  187. FAX_CONFIGURATIONW FaxConfigW;
  188. DEBUG_FUNCTION_NAME(TEXT("FaxSetConfigurationA"));
  189. //
  190. // Validate Parameters
  191. //
  192. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  193. SetLastError(ERROR_INVALID_HANDLE);
  194. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  195. return FALSE;
  196. }
  197. if (!FaxConfig) {
  198. SetLastError(ERROR_INVALID_PARAMETER);
  199. DebugPrintEx(DEBUG_ERR, _T("FaxConfig is NULL."));
  200. return FALSE;
  201. }
  202. if (FaxConfig->SizeOfStruct != sizeof(FAX_CONFIGURATIONA)) {
  203. SetLastError(ERROR_INVALID_PARAMETER);
  204. DebugPrintEx(DEBUG_ERR, _T("FaxConfig->SizeOfStruct != sizeof(FAX_CONFIGURATIONA)."));
  205. return FALSE;
  206. }
  207. //
  208. // ansi structure is same size as unicode structure, so we can just copy it, then
  209. // cast the string pointers correctly
  210. //
  211. CopyMemory(&FaxConfigW,FaxConfig,sizeof(FAX_CONFIGURATIONA));
  212. if (FaxConfig->ArchiveDirectory)
  213. {
  214. if (NULL == (FaxConfigW.ArchiveDirectory = AnsiStringToUnicodeString(FaxConfig->ArchiveDirectory)))
  215. {
  216. ec = ERROR_OUTOFMEMORY;
  217. DebugPrintEx(DEBUG_ERR,
  218. _T("AnsiStringToUnicodeString(FaxConfig->ArchiveDirectory) returns NULL."));
  219. goto exit;
  220. }
  221. }
  222. //
  223. // Set InboundProfile to NULL
  224. //
  225. FaxConfigW.Reserved = NULL;
  226. __try
  227. {
  228. ec = FAX_SetConfiguration( FH_FAX_HANDLE(FaxHandle),
  229. (PFAX_CONFIGURATIONW)&FaxConfigW );
  230. }
  231. __except (EXCEPTION_EXECUTE_HANDLER)
  232. {
  233. //
  234. // For some reason we got an exception.
  235. //
  236. ec = GetExceptionCode();
  237. DebugPrintEx(
  238. DEBUG_ERR,
  239. TEXT("Exception on RPC call to FAX_SetConfiguration. (ec: %ld)"),
  240. ec);
  241. }
  242. exit:
  243. if (FaxConfigW.ArchiveDirectory)
  244. {
  245. MemFree((PVOID)FaxConfigW.ArchiveDirectory);
  246. }
  247. if (ec != ERROR_SUCCESS)
  248. {
  249. DumpRPCExtendedStatus();
  250. SetLastError(ec);
  251. return FALSE;
  252. }
  253. return TRUE;
  254. }
  255. BOOL
  256. WINAPI
  257. FaxGetLoggingCategoriesA(
  258. IN HANDLE FaxHandle,
  259. OUT PFAX_LOG_CATEGORYA *Categories,
  260. OUT LPDWORD NumberCategories
  261. )
  262. {
  263. BOOL retval;
  264. DWORD i;
  265. DEBUG_FUNCTION_NAME(TEXT("FaxGetLoggingCategoriesA"));
  266. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE))
  267. {
  268. SetLastError(ERROR_INVALID_HANDLE);
  269. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  270. return FALSE;
  271. }
  272. if (!Categories)
  273. {
  274. SetLastError(ERROR_INVALID_PARAMETER);
  275. DebugPrintEx(DEBUG_ERR, _T("Categories is NULL."));
  276. return FALSE;
  277. }
  278. if (!NumberCategories)
  279. {
  280. SetLastError(ERROR_INVALID_PARAMETER);
  281. DebugPrintEx(DEBUG_ERR, _T("NumberCategories is NULL."));
  282. return FALSE;
  283. }
  284. retval = FaxGetLoggingCategoriesW(FaxHandle,(PFAX_LOG_CATEGORYW *)Categories , NumberCategories);
  285. if (!retval)
  286. {
  287. DebugPrintEx(DEBUG_ERR, _T("FaxGetLoggingCategoriesW() is failed."));
  288. return FALSE;
  289. }
  290. for (i=0; i<*NumberCategories; i++)
  291. {
  292. if (!ConvertUnicodeStringInPlace((LPWSTR)(*Categories)[i].Name))
  293. {
  294. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  295. MemFree (*Categories);
  296. return FALSE;
  297. }
  298. }
  299. return TRUE;
  300. } // FaxGetLoggingCategoriesA
  301. BOOL
  302. WINAPI
  303. FaxGetLoggingCategoriesW(
  304. IN HANDLE FaxHandle,
  305. OUT PFAX_LOG_CATEGORYW *Categories,
  306. OUT LPDWORD NumberCategories
  307. )
  308. {
  309. error_status_t ec;
  310. DWORD BufferSize = 0;
  311. DWORD i;
  312. DEBUG_FUNCTION_NAME(TEXT("FaxGetLoggingCategoriesW"));
  313. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  314. SetLastError(ERROR_INVALID_HANDLE);
  315. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  316. return FALSE;
  317. }
  318. if (!Categories) {
  319. SetLastError(ERROR_INVALID_PARAMETER);
  320. DebugPrintEx(DEBUG_ERR, _T("Categories is NULL."));
  321. return FALSE;
  322. }
  323. if (!NumberCategories) {
  324. SetLastError(ERROR_INVALID_PARAMETER);
  325. DebugPrintEx(DEBUG_ERR, _T("NumberCategories is NULL."));
  326. return FALSE;
  327. }
  328. *Categories = NULL;
  329. *NumberCategories = 0;
  330. //
  331. __try
  332. {
  333. ec = FAX_GetLoggingCategories(
  334. FH_FAX_HANDLE(FaxHandle),
  335. (LPBYTE*)Categories,
  336. &BufferSize,
  337. NumberCategories
  338. );
  339. }
  340. __except (EXCEPTION_EXECUTE_HANDLER)
  341. {
  342. //
  343. // For some reason we got an exception.
  344. //
  345. ec = GetExceptionCode();
  346. DebugPrintEx(
  347. DEBUG_ERR,
  348. TEXT("Exception on RPC call to FAX_GetLoggingCategories. (ec: %ld)"),
  349. ec);
  350. }
  351. if (ec != ERROR_SUCCESS)
  352. {
  353. DumpRPCExtendedStatus();
  354. SetLastError(ec);
  355. return FALSE;
  356. }
  357. for (i=0; i<*NumberCategories; i++) {
  358. FixupStringPtrW( Categories, (*Categories)[i].Name );
  359. }
  360. return TRUE;
  361. }
  362. BOOL
  363. WINAPI
  364. FaxSetLoggingCategoriesA(
  365. IN HANDLE FaxHandle,
  366. IN const FAX_LOG_CATEGORYA *Categories,
  367. IN DWORD NumberCategories
  368. )
  369. {
  370. DWORD i;
  371. PFAX_LOG_CATEGORYW CategoryW;
  372. BOOL retval;
  373. DEBUG_FUNCTION_NAME(TEXT("FaxSetLoggingCategoriesA"));
  374. //
  375. // Validate Parameters
  376. //
  377. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  378. SetLastError(ERROR_INVALID_HANDLE);
  379. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  380. return FALSE;
  381. }
  382. if (!Categories) {
  383. SetLastError(ERROR_INVALID_PARAMETER);
  384. DebugPrintEx(DEBUG_ERR, _T("Categories is NULL."));
  385. return FALSE;
  386. }
  387. if (!NumberCategories) {
  388. SetLastError(ERROR_INVALID_PARAMETER);
  389. DebugPrintEx(DEBUG_ERR, _T("NumberCategories is NULL."));
  390. return FALSE;
  391. }
  392. CategoryW = (PFAX_LOG_CATEGORYW) MemAlloc( sizeof(FAX_LOG_CATEGORYW) * NumberCategories );
  393. if (!CategoryW) {
  394. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  395. DebugPrintEx(DEBUG_ERR, _T("MemAlloc() returned NULL."));
  396. return FALSE;
  397. }
  398. for (i = 0; i< NumberCategories; i++) {
  399. CategoryW[i].Category = Categories[i].Category;
  400. CategoryW[i].Level = Categories[i].Level;
  401. CategoryW[i].Name = (LPCWSTR) AnsiStringToUnicodeString(Categories[i].Name);
  402. if (!CategoryW[i].Name && Categories[i].Name) {
  403. DebugPrintEx(DEBUG_ERR,
  404. _T("AnsiStringToUnicodeString(Categories[%ld].Name) returns NULL."), i);
  405. goto error_exit;
  406. }
  407. }
  408. retval = FaxSetLoggingCategoriesW(FaxHandle, CategoryW, NumberCategories);
  409. for (i = 0; i< NumberCategories; i++) {
  410. if (CategoryW[i].Name) MemFree((LPBYTE)CategoryW[i].Name);
  411. }
  412. MemFree(CategoryW);
  413. return retval;
  414. error_exit:
  415. for (i = 0; i< NumberCategories; i++) {
  416. if (CategoryW[i].Name) MemFree((LPBYTE)CategoryW[i].Name);
  417. }
  418. MemFree(CategoryW);
  419. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  420. return FALSE;
  421. }
  422. BOOL
  423. WINAPI
  424. FaxSetLoggingCategoriesW(
  425. IN HANDLE FaxHandle,
  426. IN const FAX_LOG_CATEGORYW *Categories,
  427. IN DWORD NumberCategories
  428. )
  429. {
  430. error_status_t ec;
  431. DWORD BufferSize;
  432. DWORD i;
  433. LPBYTE Buffer;
  434. ULONG_PTR Offset;
  435. PFAX_LOG_CATEGORY LogCat;
  436. DEBUG_FUNCTION_NAME(TEXT("FaxSetLoggingCategoriesW"));
  437. //
  438. // Validate Parameters
  439. //
  440. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  441. SetLastError(ERROR_INVALID_HANDLE);
  442. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  443. return FALSE;
  444. }
  445. if (!Categories) {
  446. SetLastError(ERROR_INVALID_PARAMETER);
  447. DebugPrintEx(DEBUG_ERR, _T("Categories is NULL."));
  448. return FALSE;
  449. }
  450. if (!NumberCategories) {
  451. SetLastError(ERROR_INVALID_PARAMETER);
  452. DebugPrintEx(DEBUG_ERR, _T("NumberCategories is NULL."));
  453. return FALSE;
  454. }
  455. Offset = sizeof(FAX_LOG_CATEGORY) * NumberCategories;
  456. BufferSize = DWORD(Offset);
  457. for (i=0; i<NumberCategories; i++) {
  458. BufferSize += StringSizeW( Categories[i].Name );
  459. }
  460. Buffer = (LPBYTE) MemAlloc( BufferSize );
  461. if (Buffer == NULL) {
  462. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  463. DebugPrintEx(DEBUG_ERR, _T("MemAlloc() failed."));
  464. return FALSE;
  465. }
  466. LogCat = (PFAX_LOG_CATEGORY) Buffer;
  467. for (i=0; i<NumberCategories; i++) {
  468. LogCat[i].Category = Categories[i].Category;
  469. LogCat[i].Level = Categories[i].Level;
  470. StoreStringW(
  471. Categories[i].Name,
  472. (PULONG_PTR) &LogCat[i].Name,
  473. Buffer,
  474. &Offset,
  475. BufferSize
  476. );
  477. }
  478. __try
  479. {
  480. ec = FAX_SetLoggingCategories(
  481. FH_FAX_HANDLE(FaxHandle),
  482. Buffer,
  483. BufferSize,
  484. NumberCategories
  485. );
  486. }
  487. __except (EXCEPTION_EXECUTE_HANDLER)
  488. {
  489. //
  490. // For some reason we got an exception.
  491. //
  492. ec = GetExceptionCode();
  493. DebugPrintEx(
  494. DEBUG_ERR,
  495. TEXT("Exception on RPC call to FAX_SetLoggingCategories. (ec: %ld)"),
  496. ec);
  497. }
  498. MemFree( Buffer );
  499. if (ec != ERROR_SUCCESS)
  500. {
  501. DumpRPCExtendedStatus();
  502. SetLastError(ec);
  503. return FALSE;
  504. }
  505. return TRUE;
  506. }
  507. BOOL
  508. WINAPI
  509. FaxGetCountryListW(
  510. IN HANDLE FaxHandle,
  511. OUT PFAX_TAPI_LINECOUNTRY_LISTW *CountryListBuffer
  512. )
  513. {
  514. error_status_t ec;
  515. DWORD dwNumCountries;
  516. DWORD dwIndex;
  517. DEBUG_FUNCTION_NAME(TEXT("FaxGetCountryListW"));
  518. //
  519. // Validate Parameters
  520. //
  521. if (!ValidateFaxHandle(FaxHandle, FHT_SERVICE)) {
  522. SetLastError(ERROR_INVALID_HANDLE);
  523. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  524. return FALSE;
  525. }
  526. if (!CountryListBuffer) {
  527. SetLastError(ERROR_INVALID_PARAMETER);
  528. DebugPrintEx(DEBUG_ERR, _T("CountryListBuffer is NULL."));
  529. return FALSE;
  530. }
  531. *CountryListBuffer = NULL;
  532. dwNumCountries = 0;
  533. //
  534. __try
  535. {
  536. ec = FAX_GetCountryList(
  537. FH_FAX_HANDLE(FaxHandle),
  538. (LPBYTE*)CountryListBuffer,
  539. &dwNumCountries);
  540. }
  541. __except (EXCEPTION_EXECUTE_HANDLER)
  542. {
  543. //
  544. // For some reason we got an exception.
  545. //
  546. ec = GetExceptionCode();
  547. DebugPrintEx(
  548. DEBUG_ERR,
  549. TEXT("Exception on RPC call to FAX_GetCountryList. (ec: %ld)"),
  550. ec);
  551. }
  552. if (ec)
  553. {
  554. DumpRPCExtendedStatus();
  555. SetLastError( ec );
  556. return FALSE;
  557. }
  558. (*CountryListBuffer)->LineCountryEntries =
  559. (PFAX_TAPI_LINECOUNTRY_ENTRYW) ((LPBYTE)*CountryListBuffer +
  560. (ULONG_PTR)(*CountryListBuffer)->LineCountryEntries);
  561. for (dwIndex=0; dwIndex<(*CountryListBuffer)->dwNumCountries; dwIndex++) {
  562. if ((*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrCountryName) {
  563. (*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrCountryName =
  564. (LPWSTR) ((LPBYTE)*CountryListBuffer +
  565. (ULONG_PTR)(*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrCountryName);
  566. }
  567. if ((*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrLongDistanceRule) {
  568. (*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrLongDistanceRule =
  569. (LPWSTR) ((LPBYTE)*CountryListBuffer +
  570. (ULONG_PTR)(*CountryListBuffer)->LineCountryEntries[dwIndex].lpctstrLongDistanceRule);
  571. }
  572. }
  573. return TRUE;
  574. }
  575. BOOL
  576. WINAPI
  577. FaxGetCountryListA(
  578. IN HANDLE FaxHandle,
  579. OUT PFAX_TAPI_LINECOUNTRY_LISTA *CountryListBuffer
  580. )
  581. {
  582. DWORD i;
  583. DEBUG_FUNCTION_NAME(TEXT("FaxGetCountryListA"));
  584. //
  585. // no need to validate parameters, FaxGetCountryListW() will do that
  586. //
  587. if (!FaxGetCountryListW( FaxHandle, (PFAX_TAPI_LINECOUNTRY_LISTW*) CountryListBuffer ))
  588. {
  589. DebugPrintEx(DEBUG_ERR, _T("FaxGetCountryListW() is failed. ec = %ld."), GetLastError());
  590. return FALSE;
  591. }
  592. for (i=0; i<(*CountryListBuffer)->dwNumCountries; i++)
  593. {
  594. if (!ConvertUnicodeStringInPlace((LPWSTR)(*CountryListBuffer)->LineCountryEntries[i].lpctstrCountryName) ||
  595. !ConvertUnicodeStringInPlace((LPWSTR)(*CountryListBuffer)->LineCountryEntries[i].lpctstrLongDistanceRule))
  596. {
  597. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  598. MemFree (*CountryListBuffer);
  599. return FALSE;
  600. }
  601. }
  602. return TRUE;
  603. } // FaxGetCountryListA
  604. #ifndef UNICODE
  605. BOOL
  606. WINAPI
  607. FaxGetCountryListX(
  608. IN HANDLE FaxHandle,
  609. OUT PFAX_TAPI_LINECOUNTRY_LISTA *CountryListBuffer
  610. )
  611. {
  612. UNREFERENCED_PARAMETER (FaxHandle);
  613. UNREFERENCED_PARAMETER (CountryListBuffer);
  614. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  615. return FALSE;
  616. }
  617. #endif // #ifndef UNICODE
  618. FaxEnumGlobalRoutingInfoW(
  619. IN HANDLE FaxHandle,
  620. OUT PFAX_GLOBAL_ROUTING_INFOW *RoutingInfoBuffer,
  621. OUT LPDWORD MethodsReturned
  622. )
  623. {
  624. PFAX_GLOBAL_ROUTING_INFOW FaxRoutingInfo = NULL;
  625. error_status_t ec;
  626. DWORD i;
  627. DWORD RoutingInfoBufferSize = 0;
  628. DEBUG_FUNCTION_NAME(TEXT("FaxEnumGlobalRoutingInfoW"));
  629. //
  630. // Validate Parameters
  631. //
  632. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  633. SetLastError(ERROR_INVALID_HANDLE);
  634. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  635. return FALSE;
  636. }
  637. if (!RoutingInfoBuffer) {
  638. SetLastError(ERROR_INVALID_PARAMETER);
  639. DebugPrintEx(DEBUG_ERR, _T("RoutingInfoBuffer is NULL."));
  640. return FALSE;
  641. }
  642. if (!MethodsReturned) {
  643. SetLastError(ERROR_INVALID_PARAMETER);
  644. DebugPrintEx(DEBUG_ERR, _T("MethodsReturned is NULL."));
  645. return FALSE;
  646. }
  647. *RoutingInfoBuffer = NULL;
  648. __try
  649. {
  650. ec = FAX_EnumGlobalRoutingInfo(
  651. FH_FAX_HANDLE(FaxHandle),
  652. (LPBYTE*)RoutingInfoBuffer,
  653. &RoutingInfoBufferSize,
  654. MethodsReturned
  655. );
  656. }
  657. __except (EXCEPTION_EXECUTE_HANDLER)
  658. {
  659. //
  660. // For some reason we got an exception.
  661. //
  662. ec = GetExceptionCode();
  663. DebugPrintEx(
  664. DEBUG_ERR,
  665. TEXT("Exception on RPC call to FAX_EnumGlobalRoutingInfo. (ec: %ld)"),
  666. ec);
  667. }
  668. if (ec)
  669. {
  670. DumpRPCExtendedStatus();
  671. SetLastError( ec );
  672. return FALSE;
  673. }
  674. FaxRoutingInfo = (PFAX_GLOBAL_ROUTING_INFOW) *RoutingInfoBuffer;
  675. for (i=0; i<*MethodsReturned; i++) {
  676. FixupStringPtrW( RoutingInfoBuffer, FaxRoutingInfo[i].Guid );
  677. FixupStringPtrW( RoutingInfoBuffer, FaxRoutingInfo[i].FunctionName );
  678. FixupStringPtrW( RoutingInfoBuffer, FaxRoutingInfo[i].FriendlyName );
  679. FixupStringPtrW( RoutingInfoBuffer, FaxRoutingInfo[i].ExtensionImageName );
  680. FixupStringPtrW( RoutingInfoBuffer, FaxRoutingInfo[i].ExtensionFriendlyName );
  681. }
  682. return TRUE;
  683. }
  684. BOOL
  685. WINAPI
  686. FaxEnumGlobalRoutingInfoA(
  687. IN HANDLE FaxHandle,
  688. OUT PFAX_GLOBAL_ROUTING_INFOA *RoutingInfoBuffer,
  689. OUT LPDWORD MethodsReturned
  690. )
  691. {
  692. PFAX_GLOBAL_ROUTING_INFOW FaxRoutingMethod = NULL;
  693. DWORD i;
  694. DEBUG_FUNCTION_NAME(TEXT("FaxEnumGlobalRoutingInfoA"));
  695. //
  696. // No need to validate parameters, FaxEnumGlobalRoutingInfoW() will do that
  697. //
  698. if (!FaxEnumGlobalRoutingInfoW(
  699. FaxHandle,
  700. (PFAX_GLOBAL_ROUTING_INFOW *)RoutingInfoBuffer,
  701. MethodsReturned
  702. ))
  703. {
  704. DebugPrintEx(DEBUG_ERR, _T("FAX_EnumGlobalRoutingInfoW() failed. ec = %ld."), GetLastError());
  705. return FALSE;
  706. }
  707. FaxRoutingMethod = (PFAX_GLOBAL_ROUTING_INFOW) *RoutingInfoBuffer;
  708. for (i=0; i<*MethodsReturned; i++)
  709. {
  710. if (!ConvertUnicodeStringInPlace((LPWSTR)FaxRoutingMethod[i].Guid) ||
  711. !ConvertUnicodeStringInPlace((LPWSTR)FaxRoutingMethod[i].FunctionName) ||
  712. !ConvertUnicodeStringInPlace((LPWSTR)FaxRoutingMethod[i].FriendlyName) ||
  713. !ConvertUnicodeStringInPlace((LPWSTR)FaxRoutingMethod[i].ExtensionImageName) ||
  714. !ConvertUnicodeStringInPlace((LPWSTR)FaxRoutingMethod[i].ExtensionFriendlyName))
  715. {
  716. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  717. MemFree (*RoutingInfoBuffer);
  718. return FALSE;
  719. }
  720. }
  721. return TRUE;
  722. } // FaxEnumGlobalRoutingInfoA
  723. BOOL
  724. WINAPI
  725. FaxSetGlobalRoutingInfoW(
  726. IN HANDLE FaxHandle,
  727. IN const FAX_GLOBAL_ROUTING_INFOW *RoutingInfo
  728. )
  729. {
  730. error_status_t ec;
  731. DEBUG_FUNCTION_NAME(TEXT("FaxSetGlobalRoutingInfoW"));
  732. //
  733. // Validate Parameters
  734. //
  735. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  736. SetLastError(ERROR_INVALID_HANDLE);
  737. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() failed."));
  738. return FALSE;
  739. }
  740. if (!RoutingInfo) {
  741. SetLastError(ERROR_INVALID_PARAMETER);
  742. DebugPrintEx(DEBUG_ERR, _T("RoutingInfo is NULL."));
  743. return FALSE;
  744. }
  745. if (RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOW)) {
  746. SetLastError(ERROR_INVALID_PARAMETER);
  747. DebugPrintEx(DEBUG_ERR, _T("RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOW)."));
  748. return FALSE;
  749. }
  750. __try
  751. {
  752. ec = FAX_SetGlobalRoutingInfo( FH_FAX_HANDLE(FaxHandle), RoutingInfo );
  753. }
  754. __except (EXCEPTION_EXECUTE_HANDLER)
  755. {
  756. //
  757. // For some reason we got an exception.
  758. //
  759. ec = GetExceptionCode();
  760. DebugPrintEx(
  761. DEBUG_ERR,
  762. TEXT("Exception on RPC call to FAX_SetGlobalRoutingInfo. (ec: %ld)"),
  763. ec);
  764. }
  765. if (ec)
  766. {
  767. DumpRPCExtendedStatus();
  768. SetLastError( ec );
  769. return FALSE;
  770. }
  771. return TRUE;
  772. }
  773. BOOL
  774. WINAPI
  775. FaxSetGlobalRoutingInfoA(
  776. IN HANDLE FaxHandle,
  777. IN const FAX_GLOBAL_ROUTING_INFOA *RoutingInfo
  778. )
  779. {
  780. BOOL Rval;
  781. FAX_GLOBAL_ROUTING_INFOW RoutingInfoW = {0};
  782. DEBUG_FUNCTION_NAME(TEXT("FaxSetGlobalRoutingInfoA"));
  783. //
  784. // Validate Parameters
  785. //
  786. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  787. SetLastError(ERROR_INVALID_HANDLE);
  788. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() failed."));
  789. return FALSE;
  790. }
  791. if (!RoutingInfo) {
  792. SetLastError(ERROR_INVALID_PARAMETER);
  793. DebugPrintEx(DEBUG_ERR, _T("RoutingInfo is NULL."));
  794. return FALSE;
  795. }
  796. if (RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOA)) {
  797. SetLastError(ERROR_INVALID_PARAMETER);
  798. DebugPrintEx(DEBUG_ERR, _T("RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOA)."));
  799. return FALSE;
  800. }
  801. RoutingInfoW.SizeOfStruct = sizeof(FAX_GLOBAL_ROUTING_INFOW);
  802. RoutingInfoW.Priority = RoutingInfo->Priority;
  803. RoutingInfoW.Guid = AnsiStringToUnicodeString(RoutingInfo->Guid);
  804. if (!RoutingInfoW.Guid && RoutingInfo->Guid)
  805. {
  806. Rval = ERROR_OUTOFMEMORY;
  807. DebugPrintEx(DEBUG_ERR,
  808. _T("AnsiStringToUnicodeString(RoutingInfo->Guid) returns NULL."));
  809. goto exit;
  810. }
  811. RoutingInfoW.FriendlyName = AnsiStringToUnicodeString(RoutingInfo->FriendlyName);
  812. if (!RoutingInfoW.FriendlyName && RoutingInfo->FriendlyName)
  813. {
  814. Rval = ERROR_OUTOFMEMORY;
  815. DebugPrintEx(DEBUG_ERR,
  816. _T("AnsiStringToUnicodeString(RoutingInfo->FriendlyName) returns NULL."));
  817. goto exit;
  818. }
  819. RoutingInfoW.FunctionName = AnsiStringToUnicodeString(RoutingInfo->FunctionName);
  820. if (!RoutingInfoW.FunctionName && RoutingInfo->FunctionName)
  821. {
  822. Rval = ERROR_OUTOFMEMORY;
  823. DebugPrintEx(DEBUG_ERR,
  824. _T("AnsiStringToUnicodeString(RoutingInfo->FunctionName) returns NULL."));
  825. goto exit;
  826. }
  827. RoutingInfoW.ExtensionImageName = AnsiStringToUnicodeString(RoutingInfo->ExtensionImageName);
  828. if (!RoutingInfoW.ExtensionImageName && RoutingInfo->ExtensionImageName)
  829. {
  830. Rval = ERROR_OUTOFMEMORY;
  831. DebugPrintEx(DEBUG_ERR,
  832. _T("AnsiStringToUnicodeString(RoutingInfo->ExtensionImageName) returns NULL."));
  833. goto exit;
  834. }
  835. RoutingInfoW.ExtensionFriendlyName = AnsiStringToUnicodeString(RoutingInfo->ExtensionFriendlyName);
  836. if (!RoutingInfoW.ExtensionFriendlyName && RoutingInfo->ExtensionFriendlyName)
  837. {
  838. Rval = ERROR_OUTOFMEMORY;
  839. DebugPrintEx(DEBUG_ERR,
  840. _T("AnsiStringToUnicodeString(RoutingInfo->ExtensionFriendlyName) returns NULL."));
  841. goto exit;
  842. }
  843. Rval = FaxSetGlobalRoutingInfoW( FaxHandle, &RoutingInfoW);
  844. exit:
  845. if (RoutingInfoW.Guid) MemFree( (LPBYTE) RoutingInfoW.Guid ) ;
  846. if (RoutingInfoW.FriendlyName) MemFree( (LPBYTE) RoutingInfoW.FriendlyName ) ;
  847. if (RoutingInfoW.FunctionName) MemFree( (LPBYTE) RoutingInfoW.FunctionName ) ;
  848. if (RoutingInfoW.ExtensionImageName) MemFree( (LPBYTE) RoutingInfoW.ExtensionImageName ) ;
  849. if (RoutingInfoW.ExtensionFriendlyName) MemFree( (LPBYTE) RoutingInfoW.ExtensionFriendlyName ) ;
  850. return Rval;
  851. }
  852. BOOL
  853. WINAPI
  854. FaxAccessCheck(
  855. IN HANDLE FaxHandle,
  856. IN DWORD AccessMask
  857. )
  858. {
  859. BOOL fPermission = FALSE;
  860. error_status_t ec = ERROR_SUCCESS;
  861. DWORD dwAccessMaskEx = 0;
  862. DWORD dwValidMask = (FAX_JOB_SUBMIT |
  863. FAX_JOB_QUERY |
  864. FAX_CONFIG_QUERY |
  865. FAX_CONFIG_SET |
  866. FAX_PORT_QUERY |
  867. FAX_PORT_SET |
  868. FAX_JOB_MANAGE |
  869. WRITE_DAC |
  870. WRITE_OWNER |
  871. ACCESS_SYSTEM_SECURITY |
  872. READ_CONTROL |
  873. GENERIC_ALL |
  874. GENERIC_READ |
  875. GENERIC_WRITE |
  876. GENERIC_EXECUTE);
  877. DEBUG_FUNCTION_NAME(TEXT("FaxAccessCheck"));
  878. //
  879. // Validate Parameters
  880. //
  881. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE))
  882. {
  883. SetLastError (ERROR_INVALID_HANDLE);
  884. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  885. return FALSE;
  886. }
  887. //
  888. // For legacy support - Turn off SYNCHRONIZE and DELETE (They are part of legacy FAX_ALL_ACCESS)
  889. //
  890. AccessMask &= ~(SYNCHRONIZE | DELETE);
  891. //
  892. // Validate specific access rights
  893. //
  894. if (0 == (AccessMask & dwValidMask))
  895. {
  896. SetLastError( ERROR_SUCCESS ); // // means access is denied
  897. DebugPrintEx(DEBUG_ERR,
  898. _T("AccessMask is invalid - No valid access bit type indicated"));
  899. return FALSE;
  900. }
  901. if ( 0 != (AccessMask & ~dwValidMask))
  902. {
  903. SetLastError( ERROR_SUCCESS ); // means access is denied
  904. DebugPrintEx(DEBUG_ERR,
  905. _T("AccessMask is invalid - contains invalid access type bits"));
  906. return FALSE;
  907. }
  908. //
  909. // Convert the Win2K legacy specific access rights to our new exteneded specific access rights
  910. // before calling FaxAccessCheckEx().
  911. //
  912. if (FAX_JOB_SUBMIT & AccessMask)
  913. {
  914. dwAccessMaskEx |= FAX_ACCESS_SUBMIT;
  915. }
  916. if (FAX_JOB_QUERY & AccessMask)
  917. {
  918. dwAccessMaskEx |= FAX_ACCESS_QUERY_JOBS;
  919. }
  920. if (FAX_CONFIG_QUERY & AccessMask)
  921. {
  922. dwAccessMaskEx |= FAX_ACCESS_QUERY_CONFIG;
  923. }
  924. if (FAX_CONFIG_SET & AccessMask)
  925. {
  926. dwAccessMaskEx |= FAX_ACCESS_MANAGE_CONFIG;
  927. }
  928. if (FAX_PORT_QUERY & AccessMask)
  929. {
  930. dwAccessMaskEx |= FAX_ACCESS_QUERY_CONFIG;
  931. }
  932. if (FAX_PORT_SET & AccessMask)
  933. {
  934. dwAccessMaskEx |= FAX_ACCESS_MANAGE_CONFIG;
  935. }
  936. if (FAX_JOB_MANAGE & AccessMask)
  937. {
  938. dwAccessMaskEx |= FAX_ACCESS_MANAGE_JOBS;
  939. }
  940. //
  941. // Add standard and generic access rights
  942. //
  943. dwAccessMaskEx |= (AccessMask & ~SPECIFIC_RIGHTS_ALL);
  944. return FaxAccessCheckEx (FaxHandle, dwAccessMaskEx, NULL);
  945. }
  946. BOOL
  947. WINAPI
  948. FaxAccessCheckEx(
  949. IN HANDLE hFaxHandle,
  950. IN DWORD dwAccessMask,
  951. IN LPDWORD lpdwAccessRights
  952. )
  953. {
  954. BOOL fPermission = FALSE;
  955. error_status_t ec = ERROR_SUCCESS;
  956. DEBUG_FUNCTION_NAME(TEXT("FaxAccessCheckEx"));
  957. DWORD dwValidMask = ( FAX_ACCESS_SUBMIT |
  958. FAX_ACCESS_SUBMIT_NORMAL |
  959. FAX_ACCESS_SUBMIT_HIGH |
  960. FAX_ACCESS_QUERY_JOBS |
  961. FAX_ACCESS_MANAGE_JOBS |
  962. FAX_ACCESS_QUERY_CONFIG |
  963. FAX_ACCESS_MANAGE_CONFIG |
  964. FAX_ACCESS_QUERY_IN_ARCHIVE |
  965. FAX_ACCESS_MANAGE_IN_ARCHIVE |
  966. FAX_ACCESS_QUERY_OUT_ARCHIVE |
  967. FAX_ACCESS_MANAGE_OUT_ARCHIVE |
  968. WRITE_DAC |
  969. WRITE_OWNER |
  970. ACCESS_SYSTEM_SECURITY |
  971. READ_CONTROL |
  972. MAXIMUM_ALLOWED |
  973. GENERIC_ALL |
  974. GENERIC_READ |
  975. GENERIC_WRITE |
  976. GENERIC_EXECUTE);
  977. //
  978. // Validate Parameters
  979. //
  980. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  981. {
  982. SetLastError (ERROR_INVALID_HANDLE);
  983. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  984. return FALSE;
  985. }
  986. if (0 == (dwAccessMask & dwValidMask))
  987. {
  988. SetLastError( ERROR_SUCCESS ); // means access is denied
  989. DebugPrintEx(DEBUG_ERR,
  990. _T("dwAccessMask is invalid - No valid access bit type indicated"));
  991. return FALSE;
  992. }
  993. if ( 0 != (dwAccessMask & ~dwValidMask))
  994. {
  995. SetLastError( ERROR_SUCCESS ); // means access is denied
  996. DebugPrintEx(DEBUG_ERR,
  997. _T("dwAccessMask is invalid - contains invalid access type bits"));
  998. return FALSE;
  999. }
  1000. __try
  1001. {
  1002. ec = FAX_AccessCheck( FH_FAX_HANDLE(hFaxHandle), dwAccessMask, &fPermission, lpdwAccessRights);
  1003. }
  1004. __except (EXCEPTION_EXECUTE_HANDLER)
  1005. {
  1006. //
  1007. // For some reason we crashed.
  1008. //
  1009. ec = GetExceptionCode();
  1010. DebugPrintEx(
  1011. DEBUG_ERR,
  1012. TEXT("Exception on RPC call to FAX_AccessCheck. (ec: %ld)"),
  1013. ec);
  1014. }
  1015. if (ec != ERROR_SUCCESS)
  1016. {
  1017. DumpRPCExtendedStatus();
  1018. SetLastError(ec);
  1019. return FALSE;
  1020. }
  1021. SetLastError (ERROR_SUCCESS);
  1022. return fPermission;
  1023. }
  1024. //************************************
  1025. //* Getting / Setting the queue state
  1026. //************************************
  1027. BOOL
  1028. WINAPI
  1029. FaxGetQueueStates (
  1030. IN HANDLE hFaxHandle,
  1031. OUT PDWORD pdwQueueStates
  1032. )
  1033. /*++
  1034. Routine name : FaxGetQueueStates
  1035. Routine description:
  1036. Retruns the state of the queue
  1037. Author:
  1038. Eran Yariv (EranY), Nov, 1999
  1039. Arguments:
  1040. hFaxHandle [in] - Handle to fax server
  1041. pdwQueueStates [out] - Returned queue state
  1042. Return Value:
  1043. TRUE on success, FALSE otherwise
  1044. --*/
  1045. {
  1046. error_status_t ec;
  1047. DEBUG_FUNCTION_NAME(TEXT("FaxGetQueueStates"));
  1048. //
  1049. // Validate Parameters
  1050. //
  1051. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1052. {
  1053. SetLastError(ERROR_INVALID_HANDLE);
  1054. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1055. return FALSE;
  1056. }
  1057. if (NULL == pdwQueueStates)
  1058. {
  1059. SetLastError(ERROR_INVALID_PARAMETER);
  1060. DebugPrintEx(DEBUG_ERR, _T("pdwQueueStates is NULL."));
  1061. return FALSE;
  1062. }
  1063. __try
  1064. {
  1065. ec = FAX_GetQueueStates(
  1066. FH_FAX_HANDLE(hFaxHandle),
  1067. pdwQueueStates
  1068. );
  1069. }
  1070. __except (EXCEPTION_EXECUTE_HANDLER)
  1071. {
  1072. //
  1073. // For some reason we crashed.
  1074. //
  1075. ec = GetExceptionCode();
  1076. DebugPrintEx(
  1077. DEBUG_ERR,
  1078. TEXT("Exception on RPC call to FAX_GetQueueStates. (ec: %ld)"),
  1079. ec);
  1080. }
  1081. if (ec != ERROR_SUCCESS)
  1082. {
  1083. DumpRPCExtendedStatus();
  1084. SetLastError(ec);
  1085. return FALSE;
  1086. }
  1087. return TRUE;
  1088. } // FaxGetQueueStates
  1089. BOOL
  1090. WINAPI
  1091. FaxSetQueue (
  1092. IN HANDLE hFaxHandle,
  1093. IN CONST DWORD dwQueueStates
  1094. )
  1095. /*++
  1096. Routine name : FaxSetQueue
  1097. Routine description:
  1098. Sets the server's queue state
  1099. Author:
  1100. Eran Yariv (EranY), Nov, 1999
  1101. Arguments:
  1102. hFaxHandle [in] - Handle to fax server
  1103. dwQueueStates [in] - New queue state
  1104. Return Value:
  1105. TRUE on success, FALSE otherwise
  1106. --*/
  1107. {
  1108. error_status_t ec;
  1109. DEBUG_FUNCTION_NAME(TEXT("FaxSetQueue"));
  1110. //
  1111. // Validate Parameters
  1112. //
  1113. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1114. {
  1115. SetLastError(ERROR_INVALID_HANDLE);
  1116. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1117. return FALSE;
  1118. }
  1119. if (dwQueueStates & ~(FAX_INCOMING_BLOCKED | FAX_OUTBOX_BLOCKED | FAX_OUTBOX_PAUSED))
  1120. {
  1121. //
  1122. // Some invalid queue state specified
  1123. //
  1124. SetLastError(ERROR_INVALID_PARAMETER);
  1125. DebugPrintEx(DEBUG_ERR, _T("Invalid dwQueueStates."));
  1126. return FALSE;
  1127. }
  1128. __try
  1129. {
  1130. ec = FAX_SetQueue(
  1131. FH_FAX_HANDLE(hFaxHandle),
  1132. dwQueueStates
  1133. );
  1134. }
  1135. __except (EXCEPTION_EXECUTE_HANDLER)
  1136. {
  1137. //
  1138. // For some reason we crashed.
  1139. //
  1140. ec = GetExceptionCode();
  1141. DebugPrintEx(
  1142. DEBUG_ERR,
  1143. TEXT("Exception on RPC call to FAX_SetQueue. (ec: %ld)"),
  1144. ec);
  1145. }
  1146. if (ec != ERROR_SUCCESS)
  1147. {
  1148. DumpRPCExtendedStatus();
  1149. SetLastError(ec);
  1150. return FALSE;
  1151. }
  1152. return TRUE;
  1153. } // FaxSetQueue
  1154. //************************************************
  1155. //* Getting / Setting the receipts configuration
  1156. //************************************************
  1157. BOOL
  1158. WINAPI
  1159. FaxGetReceiptsConfigurationA (
  1160. IN HANDLE hFaxHandle,
  1161. OUT PFAX_RECEIPTS_CONFIGA *ppReceipts
  1162. )
  1163. /*++
  1164. Routine name : FaxGetReceiptsConfigurationA
  1165. Routine description:
  1166. Retrieve receipts configuration - ANSI version
  1167. Author:
  1168. Eran Yariv (EranY), Nov, 1999
  1169. Arguments:
  1170. hFaxHandle [in ] - Fax server handle
  1171. ppReceipts [out] - New receipts configuration buffer
  1172. Return Value:
  1173. TRUE - Success
  1174. FALSE - Failure, call GetLastError() for more error information.
  1175. --*/
  1176. {
  1177. DEBUG_FUNCTION_NAME(TEXT("FaxGetReceiptsConfigurationA"));
  1178. //
  1179. // no need to validate parameters ,FaxGetReceipsConfigurationW() will do that
  1180. //
  1181. if (!FaxGetReceiptsConfigurationW(
  1182. hFaxHandle,
  1183. (PFAX_RECEIPTS_CONFIGW*) ppReceipts
  1184. ))
  1185. {
  1186. DebugPrintEx(DEBUG_ERR, _T("FaxGetReceiptsConfigurationW() is failed. ec = %ld."), GetLastError());
  1187. return FALSE;
  1188. }
  1189. if (!ConvertUnicodeStringInPlace((LPWSTR) (*ppReceipts)->lptstrSMTPServer) ||
  1190. !ConvertUnicodeStringInPlace((LPWSTR) (*ppReceipts)->lptstrSMTPFrom) ||
  1191. !ConvertUnicodeStringInPlace((LPWSTR) (*ppReceipts)->lptstrSMTPUserName) ||
  1192. !ConvertUnicodeStringInPlace((LPWSTR) (*ppReceipts)->lptstrSMTPPassword))
  1193. {
  1194. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  1195. MemFree (*ppReceipts);
  1196. return FALSE;
  1197. }
  1198. return TRUE;
  1199. } // FaxGetReceiptsConfigurationA
  1200. BOOL
  1201. WINAPI
  1202. FaxGetReceiptsConfigurationW (
  1203. IN HANDLE hFaxHandle,
  1204. OUT PFAX_RECEIPTS_CONFIGW *ppReceipts
  1205. )
  1206. /*++
  1207. Routine name : FaxGetReceiptsConfigurationW
  1208. Routine description:
  1209. Retrieve receipts configuration - Unicode version
  1210. Author:
  1211. Eran Yariv (EranY), Nov, 1999
  1212. Arguments:
  1213. hFaxHandle [in ] - Fax server handle
  1214. ppReceipts [out] - New receipts configuration buffer
  1215. Return Value:
  1216. TRUE - Success
  1217. FALSE - Failure, call GetLastError() for more error information.
  1218. --*/
  1219. {
  1220. error_status_t ec;
  1221. DWORD dwConfigSize = 0;
  1222. DEBUG_FUNCTION_NAME(TEXT("FaxGetReceiptsConfigurationW"));
  1223. //
  1224. // Validate Parameters
  1225. //
  1226. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1227. {
  1228. SetLastError(ERROR_INVALID_HANDLE);
  1229. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1230. return FALSE;
  1231. }
  1232. if (!ppReceipts)
  1233. {
  1234. SetLastError( ERROR_INVALID_PARAMETER );
  1235. DebugPrintEx(DEBUG_ERR, _T("ppReceipts is NULL."));
  1236. return FALSE;
  1237. }
  1238. *ppReceipts = NULL;
  1239. __try
  1240. {
  1241. ec = FAX_GetReceiptsConfiguration (
  1242. FH_FAX_HANDLE(hFaxHandle),
  1243. (LPBYTE*)ppReceipts,
  1244. &dwConfigSize
  1245. );
  1246. }
  1247. __except (EXCEPTION_EXECUTE_HANDLER)
  1248. {
  1249. //
  1250. // For some reason we got an exception.
  1251. //
  1252. ec = GetExceptionCode();
  1253. DebugPrintEx(
  1254. DEBUG_ERR,
  1255. TEXT("Exception on RPC call to FAX_GetReceiptsConfiguration. (ec: %ld)"),
  1256. ec);
  1257. }
  1258. if (ERROR_SUCCESS != ec)
  1259. {
  1260. DumpRPCExtendedStatus();
  1261. SetLastError( ec );
  1262. return FALSE;
  1263. }
  1264. FixupStringPtrW( ppReceipts, (*ppReceipts)->lptstrSMTPServer );
  1265. FixupStringPtrW( ppReceipts, (*ppReceipts)->lptstrSMTPFrom );
  1266. FixupStringPtrW( ppReceipts, (*ppReceipts)->lptstrSMTPUserName );
  1267. FixupStringPtrW( ppReceipts, (*ppReceipts)->lptstrSMTPPassword );
  1268. return TRUE;
  1269. } // FaxGetReceiptsConfigurationW
  1270. #ifndef UNICODE
  1271. BOOL
  1272. WINAPI
  1273. FaxGetReceiptsConfigurationX (
  1274. IN HANDLE hFaxHandle,
  1275. OUT PFAX_RECEIPTS_CONFIGW *ppReceipts
  1276. )
  1277. {
  1278. UNREFERENCED_PARAMETER (hFaxHandle);
  1279. UNREFERENCED_PARAMETER (ppReceipts);
  1280. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  1281. return FALSE;
  1282. }
  1283. #endif // #ifndef UNICODE
  1284. BOOL
  1285. WINAPI
  1286. FaxSetReceiptsConfigurationA (
  1287. IN HANDLE hFaxHandle,
  1288. IN CONST PFAX_RECEIPTS_CONFIGA pReceipts
  1289. )
  1290. /*++
  1291. Routine name : FaxSetReceiptsConfigurationA
  1292. Routine description:
  1293. Set receipts configuration - ANSI version
  1294. Author:
  1295. Eran Yariv (EranY), Nov, 1999
  1296. Arguments:
  1297. hFaxHandle [in] - Handle to fax server
  1298. pReceipts [in] - New configuration
  1299. Return Value:
  1300. TRUE - Success
  1301. FALSE - Failure, call GetLastError() for more error information.
  1302. --*/
  1303. {
  1304. FAX_RECEIPTS_CONFIGW ReceiptsConfigW;
  1305. BOOL bRes = FALSE;
  1306. DEBUG_FUNCTION_NAME(TEXT("FaxSetReceiptsConfigurationA"));
  1307. //
  1308. // Validate Parameters
  1309. //
  1310. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1311. {
  1312. SetLastError(ERROR_INVALID_HANDLE);
  1313. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1314. return FALSE;
  1315. }
  1316. if (!pReceipts)
  1317. {
  1318. SetLastError(ERROR_INVALID_PARAMETER);
  1319. DebugPrintEx(DEBUG_ERR, _T("pReceipts is NULL."));
  1320. return FALSE;
  1321. }
  1322. if (sizeof (FAX_RECEIPTS_CONFIGA) != pReceipts->dwSizeOfStruct)
  1323. {
  1324. SetLastError(ERROR_INVALID_PARAMETER);
  1325. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_RECEIPTS_CONFIGA) != pReceipts->dwSizeOfStruct"));
  1326. return FALSE;
  1327. }
  1328. //
  1329. // ansi structure is same size as unicode structure, so we can just copy it, then
  1330. // cast the string pointers correctly
  1331. //
  1332. CopyMemory(&ReceiptsConfigW, pReceipts, sizeof(FAX_RECEIPTS_CONFIGA));
  1333. ReceiptsConfigW.dwSizeOfStruct = sizeof (FAX_RECEIPTS_CONFIGW);
  1334. ReceiptsConfigW.bIsToUseForMSRouteThroughEmailMethod = pReceipts->bIsToUseForMSRouteThroughEmailMethod;
  1335. ReceiptsConfigW.lptstrSMTPFrom = NULL;
  1336. ReceiptsConfigW.lptstrSMTPUserName = NULL;
  1337. ReceiptsConfigW.lptstrSMTPPassword = NULL;
  1338. ReceiptsConfigW.lptstrSMTPServer = NULL;
  1339. ReceiptsConfigW.lptstrReserved = NULL;
  1340. if (pReceipts->lptstrSMTPServer)
  1341. {
  1342. if (NULL ==
  1343. (ReceiptsConfigW.lptstrSMTPServer = AnsiStringToUnicodeString(pReceipts->lptstrSMTPServer))
  1344. )
  1345. {
  1346. DebugPrintEx(DEBUG_ERR,
  1347. _T("AnsiStringToUnicodeString(pReceipts->lptstrSMTPServer) returns NULL."));
  1348. goto exit;
  1349. }
  1350. }
  1351. if (pReceipts->lptstrSMTPFrom)
  1352. {
  1353. if (NULL ==
  1354. (ReceiptsConfigW.lptstrSMTPFrom = AnsiStringToUnicodeString(pReceipts->lptstrSMTPFrom))
  1355. )
  1356. {
  1357. DebugPrintEx(DEBUG_ERR,
  1358. _T("AnsiStringToUnicodeString(pReceipts->lptstrSMTPFrom) returns NULL."));
  1359. goto exit;
  1360. }
  1361. }
  1362. if (pReceipts->lptstrSMTPUserName)
  1363. {
  1364. if (NULL ==
  1365. (ReceiptsConfigW.lptstrSMTPUserName = AnsiStringToUnicodeString(pReceipts->lptstrSMTPUserName))
  1366. )
  1367. {
  1368. DebugPrintEx(DEBUG_ERR,
  1369. _T("AnsiStringToUnicodeString(pReceipts->lptstrSMTPUserName) returns NULL."));
  1370. goto exit;
  1371. }
  1372. }
  1373. if (pReceipts->lptstrSMTPPassword)
  1374. {
  1375. if (NULL ==
  1376. (ReceiptsConfigW.lptstrSMTPPassword = AnsiStringToUnicodeString(pReceipts->lptstrSMTPPassword))
  1377. )
  1378. {
  1379. DebugPrintEx(DEBUG_ERR,
  1380. _T("AnsiStringToUnicodeString(pReceipts->lptstrSMTPPassword) returns NULL."));
  1381. goto exit;
  1382. }
  1383. }
  1384. bRes = FaxSetReceiptsConfigurationW (hFaxHandle, &ReceiptsConfigW);
  1385. exit:
  1386. MemFree((PVOID)ReceiptsConfigW.lptstrSMTPServer);
  1387. MemFree((PVOID)ReceiptsConfigW.lptstrSMTPFrom);
  1388. MemFree((PVOID)ReceiptsConfigW.lptstrSMTPUserName);
  1389. SecureZeroMemory((PVOID)ReceiptsConfigW.lptstrSMTPPassword,wcslen(ReceiptsConfigW.lptstrSMTPPassword)*sizeof(WCHAR));
  1390. MemFree((PVOID)ReceiptsConfigW.lptstrSMTPPassword);
  1391. return bRes;
  1392. } // FaxSetReceiptsConfigurationA
  1393. BOOL
  1394. WINAPI
  1395. FaxSetReceiptsConfigurationW (
  1396. IN HANDLE hFaxHandle,
  1397. IN CONST PFAX_RECEIPTS_CONFIGW pReceipts
  1398. )
  1399. /*++
  1400. Routine name : FaxSetReceiptsConfigurationW
  1401. Routine description:
  1402. Set receipts configuration - UNICODE version
  1403. Author:
  1404. Eran Yariv (EranY), Nov, 1999
  1405. Arguments:
  1406. hFaxHandle [in] - Handle to fax server
  1407. pReceipts [in] - New configuration
  1408. Return Value:
  1409. TRUE - Success
  1410. FALSE - Failure, call GetLastError() for more error information.
  1411. --*/
  1412. {
  1413. error_status_t ec;
  1414. DEBUG_FUNCTION_NAME(TEXT("FaxSetReceiptsConfigurationW"));
  1415. //
  1416. // Validate Parameters
  1417. //
  1418. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1419. {
  1420. SetLastError(ERROR_INVALID_HANDLE);
  1421. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1422. return FALSE;
  1423. }
  1424. if (!pReceipts)
  1425. {
  1426. SetLastError(ERROR_INVALID_PARAMETER);
  1427. DebugPrintEx(DEBUG_ERR, _T("pReceipts is NULL."));
  1428. return FALSE;
  1429. }
  1430. if (sizeof (FAX_RECEIPTS_CONFIGW) != pReceipts->dwSizeOfStruct)
  1431. {
  1432. SetLastError(ERROR_INVALID_PARAMETER);
  1433. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_RECEIPTS_CONFIGW) != pReceipts->dwSizeOfStruct"));
  1434. return FALSE;
  1435. }
  1436. if ((pReceipts->SMTPAuthOption < FAX_SMTP_AUTH_ANONYMOUS) ||
  1437. (pReceipts->SMTPAuthOption > FAX_SMTP_AUTH_NTLM))
  1438. {
  1439. //
  1440. // SMTP auth type type is invalid
  1441. //
  1442. SetLastError(ERROR_INVALID_PARAMETER);
  1443. DebugPrintEx(DEBUG_ERR, _T("SMTP auth type is invalid."));
  1444. return FALSE;
  1445. }
  1446. if ((pReceipts->dwAllowedReceipts) & ~DRT_ALL)
  1447. {
  1448. //
  1449. // Receipts type is invalid
  1450. //
  1451. SetLastError(ERROR_INVALID_PARAMETER);
  1452. DebugPrintEx(DEBUG_ERR,
  1453. _T("Receipts type is invalid : (pReceipts->dwAllowedReceipts) & ~DRT_ALL."));
  1454. return FALSE;
  1455. }
  1456. __try
  1457. {
  1458. ec = FAX_SetReceiptsConfiguration(
  1459. FH_FAX_HANDLE(hFaxHandle),
  1460. pReceipts );
  1461. }
  1462. __except (EXCEPTION_EXECUTE_HANDLER)
  1463. {
  1464. //
  1465. // For some reason we got an exception.
  1466. //
  1467. ec = GetExceptionCode();
  1468. DebugPrintEx(
  1469. DEBUG_ERR,
  1470. TEXT("Exception on RPC call to FAX_SetReceiptsConfiguration. (ec: %ld)"),
  1471. ec);
  1472. }
  1473. if (ERROR_SUCCESS != ec)
  1474. {
  1475. DumpRPCExtendedStatus();
  1476. SetLastError(ec);
  1477. return FALSE;
  1478. }
  1479. return TRUE;
  1480. } // FaxSetReceiptsConfigurationW
  1481. #ifndef UNICODE
  1482. BOOL
  1483. WINAPI
  1484. FaxSetReceiptsConfigurationX (
  1485. IN HANDLE hFaxHandle,
  1486. IN CONST PFAX_RECEIPTS_CONFIGW pReceipts
  1487. )
  1488. {
  1489. UNREFERENCED_PARAMETER (hFaxHandle);
  1490. UNREFERENCED_PARAMETER (pReceipts);
  1491. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  1492. return FALSE;
  1493. }
  1494. #endif // #ifndef UNICODE
  1495. //********************************************
  1496. //* Server version
  1497. //********************************************
  1498. BOOL
  1499. WINAPI
  1500. FaxGetVersion (
  1501. IN HANDLE hFaxHandle,
  1502. OUT PFAX_VERSION pVersion
  1503. )
  1504. /*++
  1505. Routine name : FaxGetVersion
  1506. Routine description:
  1507. Retrieves the version of the fax server
  1508. Author:
  1509. Eran Yariv (EranY), Nov, 1999
  1510. Arguments:
  1511. hFaxHandle [in ] - Handle to fax server
  1512. pVersion [in\out] - Returned version structure
  1513. Return Value:
  1514. TRUE - Success
  1515. FALSE - Failure, call GetLastError() for more error information.
  1516. --*/
  1517. {
  1518. error_status_t ec;
  1519. DEBUG_FUNCTION_NAME(TEXT("FaxGetVersion"));
  1520. //
  1521. // Validate Parameters
  1522. //
  1523. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1524. {
  1525. SetLastError(ERROR_INVALID_HANDLE);
  1526. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1527. return FALSE;
  1528. }
  1529. if (!pVersion)
  1530. {
  1531. SetLastError(ERROR_INVALID_PARAMETER);
  1532. DebugPrintEx(DEBUG_ERR, _T("pVersion is NULL."));
  1533. return FALSE;
  1534. }
  1535. if (sizeof (FAX_VERSION) != pVersion->dwSizeOfStruct)
  1536. {
  1537. SetLastError(ERROR_INVALID_PARAMETER);
  1538. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_VERSION) != pVersion->dwSizeOfStruct."));
  1539. return FALSE;
  1540. }
  1541. __try
  1542. {
  1543. ec = FAX_GetVersion(
  1544. FH_FAX_HANDLE(hFaxHandle),
  1545. pVersion );
  1546. }
  1547. __except (EXCEPTION_EXECUTE_HANDLER)
  1548. {
  1549. //
  1550. // For some reason we got an exception.
  1551. //
  1552. ec = GetExceptionCode();
  1553. DebugPrintEx(
  1554. DEBUG_ERR,
  1555. TEXT("Exception on RPC call to FAX_GetVersion. (ec: %ld)"),
  1556. ec);
  1557. }
  1558. if (ERROR_SUCCESS != ec)
  1559. {
  1560. DumpRPCExtendedStatus();
  1561. SetLastError(ec);
  1562. return FALSE;
  1563. }
  1564. return TRUE;
  1565. } // FaxGetVersion
  1566. //********************************************
  1567. //* Outbox configuration
  1568. //********************************************
  1569. BOOL
  1570. WINAPI
  1571. FaxGetOutboxConfiguration (
  1572. IN HANDLE hFaxHandle,
  1573. OUT PFAX_OUTBOX_CONFIG *ppOutboxCfg
  1574. )
  1575. /*++
  1576. Routine name : FaxGetOutboxConfiguration
  1577. Routine description:
  1578. Get Outbox configuration
  1579. Author:
  1580. Eran Yariv (EranY), Nov, 1999
  1581. Arguments:
  1582. hFaxHandle [in ] - Handle to fax server
  1583. ppOutboxCfg [out] - New Outbox configuration buffer
  1584. Return Value:
  1585. TRUE - Success
  1586. FALSE - Failure, call GetLastError() for more error information.
  1587. --*/
  1588. {
  1589. error_status_t ec;
  1590. DWORD dwConfigSize = 0;
  1591. DEBUG_FUNCTION_NAME(TEXT("FaxGetOutboxConfiguration"));
  1592. //
  1593. // Validate Parameters
  1594. //
  1595. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1596. {
  1597. SetLastError(ERROR_INVALID_HANDLE);
  1598. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1599. return FALSE;
  1600. }
  1601. if (!ppOutboxCfg)
  1602. {
  1603. SetLastError(ERROR_INVALID_PARAMETER);
  1604. DebugPrintEx(DEBUG_ERR, _T("ppOutboxCfg is NULL."));
  1605. return FALSE;
  1606. }
  1607. *ppOutboxCfg = NULL;
  1608. __try
  1609. {
  1610. ec = FAX_GetOutboxConfiguration(
  1611. FH_FAX_HANDLE(hFaxHandle),
  1612. (LPBYTE*)ppOutboxCfg,
  1613. &dwConfigSize
  1614. );
  1615. }
  1616. __except (EXCEPTION_EXECUTE_HANDLER)
  1617. {
  1618. //
  1619. // For some reason we got an exception.
  1620. //
  1621. ec = GetExceptionCode();
  1622. DebugPrintEx(
  1623. DEBUG_ERR,
  1624. TEXT("Exception on RPC call to FAX_GetOutboxConfiguration. (ec: %ld)"),
  1625. ec);
  1626. }
  1627. if (ERROR_SUCCESS != ec)
  1628. {
  1629. DumpRPCExtendedStatus();
  1630. SetLastError(ec);
  1631. return FALSE;
  1632. }
  1633. return TRUE;
  1634. } // FaxGetOutboxConfiguration
  1635. BOOL
  1636. WINAPI
  1637. FaxSetOutboxConfiguration (
  1638. IN HANDLE hFaxHandle,
  1639. IN CONST PFAX_OUTBOX_CONFIG pOutboxCfg
  1640. )
  1641. /*++
  1642. Routine name : FaxSetOutboxConfiguration
  1643. Routine description:
  1644. Set Outbox configuration
  1645. Author:
  1646. Eran Yariv (EranY), Nov, 1999
  1647. Arguments:
  1648. hFaxHandle [in] - Handle to fax server
  1649. pOutboxCfg [in] - New configuration
  1650. Return Value:
  1651. TRUE - Success
  1652. FALSE - Failure, call GetLastError() for more error information.
  1653. --*/
  1654. {
  1655. error_status_t ec;
  1656. DEBUG_FUNCTION_NAME(TEXT("FaxSetOutboxConfiguration"));
  1657. //
  1658. // Validate Parameters
  1659. //
  1660. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1661. {
  1662. SetLastError(ERROR_INVALID_HANDLE);
  1663. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1664. return FALSE;
  1665. }
  1666. if (!pOutboxCfg)
  1667. {
  1668. SetLastError(ERROR_INVALID_PARAMETER);
  1669. DebugPrintEx(DEBUG_ERR, _T("pOutboxCfg is NULL."));
  1670. return FALSE;
  1671. }
  1672. if (sizeof (FAX_OUTBOX_CONFIG) != pOutboxCfg->dwSizeOfStruct)
  1673. {
  1674. SetLastError(ERROR_INVALID_PARAMETER);
  1675. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_OUTBOX_CONFIG) != pOutboxCfg->dwSizeOfStruct."));
  1676. return FALSE;
  1677. }
  1678. if ((pOutboxCfg->dtDiscountStart.Hour > 23) ||
  1679. (pOutboxCfg->dtDiscountStart.Minute > 59) ||
  1680. (pOutboxCfg->dtDiscountEnd.Hour > 23) ||
  1681. (pOutboxCfg->dtDiscountEnd.Minute > 59))
  1682. {
  1683. SetLastError(ERROR_INVALID_PARAMETER);
  1684. DebugPrintEx(DEBUG_ERR, _T("wrong pOutboxCfg->dwDiscountStart OR ->dwDiscountEnd."));
  1685. return FALSE;
  1686. }
  1687. __try
  1688. {
  1689. ec = FAX_SetOutboxConfiguration(
  1690. FH_FAX_HANDLE(hFaxHandle),
  1691. pOutboxCfg );
  1692. }
  1693. __except (EXCEPTION_EXECUTE_HANDLER)
  1694. {
  1695. //
  1696. // For some reason we got an exception.
  1697. //
  1698. ec = GetExceptionCode();
  1699. DebugPrintEx(
  1700. DEBUG_ERR,
  1701. TEXT("Exception on RPC call to FAX_SetOutboxConfiguration. (ec: %ld)"),
  1702. ec);
  1703. }
  1704. if (ERROR_SUCCESS != ec)
  1705. {
  1706. DumpRPCExtendedStatus();
  1707. SetLastError(ec);
  1708. return FALSE;
  1709. }
  1710. return TRUE;
  1711. } // FaxSetOutboxConfiguration
  1712. //********************************************
  1713. //* Archive configuration
  1714. //********************************************
  1715. BOOL
  1716. WINAPI
  1717. FaxGetArchiveConfigurationA (
  1718. IN HANDLE hFaxHandle,
  1719. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  1720. OUT PFAX_ARCHIVE_CONFIGA *ppArchiveCfg
  1721. )
  1722. /*++
  1723. Routine name : FaxGetArchiveConfigurationA
  1724. Routine description:
  1725. Gets the archive configuration - ANSI version
  1726. Author:
  1727. Eran Yariv (EranY), Nov, 1999
  1728. Arguments:
  1729. hFaxHandle [in ] - Handle to fax server
  1730. Folder [in ] - Folder type
  1731. ppArchiveCfg [out] - Configuration buffer
  1732. Return Value:
  1733. TRUE - Success
  1734. FALSE - Failure, call GetLastError() for more error information.
  1735. --*/
  1736. {
  1737. DEBUG_FUNCTION_NAME(TEXT("FaxGetArchiveConfigurationA"));
  1738. //
  1739. // no need to validate parameters, FaxGetArchiveConfigurationW() will do that
  1740. //
  1741. if (!FaxGetArchiveConfigurationW(
  1742. hFaxHandle,
  1743. Folder,
  1744. (PFAX_ARCHIVE_CONFIGW*) ppArchiveCfg
  1745. ))
  1746. {
  1747. DebugPrintEx(DEBUG_ERR, _T("FaxGetArchiveConfigurationW() is failed."));
  1748. return FALSE;
  1749. }
  1750. if (!ConvertUnicodeStringInPlace((LPWSTR)(*ppArchiveCfg)->lpcstrFolder))
  1751. {
  1752. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  1753. MemFree (*ppArchiveCfg);
  1754. return FALSE;
  1755. }
  1756. (*ppArchiveCfg)->dwSizeOfStruct = sizeof(FAX_ARCHIVE_CONFIGA);
  1757. return TRUE;
  1758. } // FaxGetArchiveConfigurationA
  1759. BOOL
  1760. WINAPI
  1761. FaxGetArchiveConfigurationW (
  1762. IN HANDLE hFaxHandle,
  1763. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  1764. OUT PFAX_ARCHIVE_CONFIGW *ppArchiveCfg
  1765. )
  1766. /*++
  1767. Routine name : FaxGetArchiveConfigurationW
  1768. Routine description:
  1769. Gets the archive configuration - UNICODE version
  1770. Author:
  1771. Eran Yariv (EranY), Nov, 1999
  1772. Arguments:
  1773. hFaxHandle [in ] - Handle to fax server
  1774. Folder [in ] - Folder type
  1775. ppArchiveCfg [out] - Configuration buffer
  1776. Return Value:
  1777. TRUE - Success
  1778. FALSE - Failure, call GetLastError() for more error information.
  1779. --*/
  1780. {
  1781. DWORD dwConfigSize = 0;
  1782. error_status_t ec;
  1783. DEBUG_FUNCTION_NAME(TEXT("FaxGetArchiveConfigurationA"));
  1784. //
  1785. // Validate Parameters
  1786. //
  1787. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1788. {
  1789. SetLastError(ERROR_INVALID_HANDLE);
  1790. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1791. return FALSE;
  1792. }
  1793. if (!ppArchiveCfg)
  1794. {
  1795. SetLastError(ERROR_INVALID_PARAMETER);
  1796. DebugPrintEx(DEBUG_ERR, _T("ppArchiveCfg is NULL."));
  1797. return FALSE;
  1798. }
  1799. if ((Folder != FAX_MESSAGE_FOLDER_SENTITEMS) &&
  1800. (Folder != FAX_MESSAGE_FOLDER_INBOX)
  1801. )
  1802. {
  1803. SetLastError(ERROR_INVALID_PARAMETER);
  1804. DebugPrintEx(DEBUG_ERR, _T("Folder is neither SentItems nor Inbox."));
  1805. return FALSE;
  1806. }
  1807. *ppArchiveCfg = NULL;
  1808. __try
  1809. {
  1810. ec = FAX_GetArchiveConfiguration(
  1811. FH_FAX_HANDLE(hFaxHandle),
  1812. Folder,
  1813. (LPBYTE*)ppArchiveCfg,
  1814. &dwConfigSize
  1815. );
  1816. }
  1817. __except (EXCEPTION_EXECUTE_HANDLER)
  1818. {
  1819. //
  1820. // For some reason we got an exception.
  1821. //
  1822. ec = GetExceptionCode();
  1823. DebugPrintEx(
  1824. DEBUG_ERR,
  1825. TEXT("Exception on RPC call to FAX_GetArchiveConfiguration. (ec: %ld)"),
  1826. ec);
  1827. }
  1828. if (ERROR_SUCCESS != ec)
  1829. {
  1830. DumpRPCExtendedStatus();
  1831. SetLastError(ec);
  1832. return FALSE;
  1833. }
  1834. FixupStringPtrW( ppArchiveCfg, (*ppArchiveCfg)->lpcstrFolder );
  1835. return TRUE;
  1836. } // FaxGetArchiveConfigurationW
  1837. #ifndef UNICODE
  1838. FaxGetArchiveConfigurationX (
  1839. IN HANDLE hFaxHandle,
  1840. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  1841. OUT PFAX_ARCHIVE_CONFIGW *ppArchiveCfg
  1842. )
  1843. {
  1844. UNREFERENCED_PARAMETER (hFaxHandle);
  1845. UNREFERENCED_PARAMETER (Folder);
  1846. UNREFERENCED_PARAMETER (ppArchiveCfg);
  1847. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  1848. return FALSE;
  1849. }
  1850. #endif // #ifndef UNICODE
  1851. BOOL
  1852. WINAPI
  1853. FaxSetArchiveConfigurationA (
  1854. IN HANDLE hFaxHandle,
  1855. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  1856. IN CONST PFAX_ARCHIVE_CONFIGA pArchiveCfg
  1857. )
  1858. /*++
  1859. Routine name : FaxSetArchiveConfigurationA
  1860. Routine description:
  1861. Sets the archive configuration - ANSI version
  1862. Author:
  1863. Eran Yariv (EranY), Nov, 1999
  1864. Arguments:
  1865. hFaxHandle [in ] - Handle to fax server
  1866. Folder [in ] - Folder type
  1867. pArchiveCfg [in ] - New configuration.
  1868. Return Value:
  1869. TRUE - Success
  1870. FALSE - Failure, call GetLastError() for more error information.
  1871. --*/
  1872. {
  1873. FAX_ARCHIVE_CONFIGW ConfigW;
  1874. BOOL bRes;
  1875. DEBUG_FUNCTION_NAME(TEXT("FaxSetArchiveConfigurationA"));
  1876. //
  1877. // Validate Parameters
  1878. //
  1879. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1880. {
  1881. SetLastError(ERROR_INVALID_HANDLE);
  1882. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle is failed."));
  1883. return FALSE;
  1884. }
  1885. if (!pArchiveCfg)
  1886. {
  1887. SetLastError(ERROR_INVALID_PARAMETER);
  1888. DebugPrintEx(DEBUG_ERR, _T("pArchiveCfg is NULL."));
  1889. return FALSE;
  1890. }
  1891. if (sizeof(FAX_ARCHIVE_CONFIGA) != pArchiveCfg->dwSizeOfStruct)
  1892. {
  1893. SetLastError(ERROR_INVALID_PARAMETER);
  1894. DebugPrintEx(DEBUG_ERR, _T("pArchiveCfg->dwSizeOfStruct != sizeof(FAX_ARCHIVE_CONFIGA)."));
  1895. return FALSE;
  1896. }
  1897. //
  1898. // Create a UNICODE structure and pass along to UNICODE function
  1899. // Ansi structure is same size as unicode structure, so we can just copy it, then
  1900. // cast the string pointers correctly
  1901. //
  1902. CopyMemory(&ConfigW, pArchiveCfg, sizeof(FAX_ARCHIVE_CONFIGA));
  1903. ConfigW.lpcstrFolder = NULL;
  1904. ConfigW.dwSizeOfStruct = sizeof (FAX_ARCHIVE_CONFIGW);
  1905. if (pArchiveCfg->lpcstrFolder)
  1906. {
  1907. if (NULL ==
  1908. (ConfigW.lpcstrFolder = AnsiStringToUnicodeString(pArchiveCfg->lpcstrFolder))
  1909. )
  1910. {
  1911. DebugPrintEx(DEBUG_ERR,
  1912. _T("AnsiStringToUnicodeString(pArchiveCfg->lpcstrFolder) returns NULL."));
  1913. return FALSE;
  1914. }
  1915. }
  1916. bRes = FaxSetArchiveConfigurationW (hFaxHandle, Folder, &ConfigW);
  1917. MemFree((PVOID)ConfigW.lpcstrFolder);
  1918. return bRes;
  1919. } // FaxSetArchiveConfigurationA
  1920. BOOL
  1921. WINAPI
  1922. FaxSetArchiveConfigurationW (
  1923. IN HANDLE hFaxHandle,
  1924. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  1925. IN CONST PFAX_ARCHIVE_CONFIGW pArchiveCfg
  1926. )
  1927. /*++
  1928. Routine name : FaxSetArchiveConfigurationW
  1929. Routine description:
  1930. Sets the archive configuration - UNICODE version
  1931. Author:
  1932. Eran Yariv (EranY), Nov, 1999
  1933. Arguments:
  1934. hFaxHandle [in ] - Handle to fax server
  1935. Folder [in ] - Folder type
  1936. pArchiveCfg [in ] - New configuration.
  1937. Return Value:
  1938. TRUE - Success
  1939. FALSE - Failure, call GetLastError() for more error information.
  1940. --*/
  1941. {
  1942. error_status_t ec;
  1943. DEBUG_FUNCTION_NAME(TEXT("FaxSetArchiveConfigurationW"));
  1944. //
  1945. // Validate Parameters
  1946. //
  1947. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  1948. {
  1949. SetLastError(ERROR_INVALID_HANDLE);
  1950. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  1951. return FALSE;
  1952. }
  1953. if (!pArchiveCfg)
  1954. {
  1955. SetLastError(ERROR_INVALID_PARAMETER);
  1956. DebugPrintEx(DEBUG_ERR, _T("pArchiveCfg is NULL."));
  1957. return FALSE;
  1958. }
  1959. if ((Folder != FAX_MESSAGE_FOLDER_SENTITEMS) &&
  1960. (Folder != FAX_MESSAGE_FOLDER_INBOX)
  1961. )
  1962. {
  1963. DebugPrintEx(DEBUG_ERR, _T("Invalid folder id (%ld)"), Folder);
  1964. SetLastError(ERROR_INVALID_PARAMETER);
  1965. return FALSE;
  1966. }
  1967. if (sizeof(FAX_ARCHIVE_CONFIGW) != pArchiveCfg->dwSizeOfStruct)
  1968. {
  1969. SetLastError(ERROR_INVALID_PARAMETER);
  1970. DebugPrintEx(DEBUG_ERR, _T("sizeof(FAX_ARCHIVE_CONFIGW) != pArchiveCfg->dwSizeOfStruct."));
  1971. return FALSE;
  1972. }
  1973. if (pArchiveCfg->bUseArchive)
  1974. {
  1975. if (pArchiveCfg->dwSizeQuotaHighWatermark < pArchiveCfg->dwSizeQuotaLowWatermark)
  1976. {
  1977. DebugPrintEx(DEBUG_ERR,
  1978. _T("Watermarks mismatch (high=%ld, low=%ld)"),
  1979. pArchiveCfg->dwSizeQuotaHighWatermark,
  1980. pArchiveCfg->dwSizeQuotaLowWatermark);
  1981. SetLastError(ERROR_INVALID_PARAMETER);
  1982. return FALSE;
  1983. }
  1984. if ((NULL == pArchiveCfg->lpcstrFolder) || (L'\0' == pArchiveCfg->lpcstrFolder[0]))
  1985. {
  1986. DebugPrintEx(DEBUG_ERR, _T("Empty archive folder specified"));
  1987. SetLastError(ERROR_INVALID_PARAMETER);
  1988. return FALSE;
  1989. }
  1990. if (lstrlenW (pArchiveCfg->lpcstrFolder) > MAX_ARCHIVE_FOLDER_PATH)
  1991. {
  1992. DebugPrintEx(DEBUG_ERR, _T("DB file name exceeds MAX_PATH"));
  1993. SetLastError (ERROR_BUFFER_OVERFLOW);
  1994. return FALSE;
  1995. }
  1996. }
  1997. __try
  1998. {
  1999. ec = FAX_SetArchiveConfiguration(
  2000. FH_FAX_HANDLE(hFaxHandle),
  2001. Folder,
  2002. pArchiveCfg );
  2003. }
  2004. __except (EXCEPTION_EXECUTE_HANDLER)
  2005. {
  2006. //
  2007. // For some reason we got an exception.
  2008. //
  2009. ec = GetExceptionCode();
  2010. DebugPrintEx(
  2011. DEBUG_ERR,
  2012. TEXT("Exception on RPC call to FAX_SetArchiveConfiguration. (ec: %ld)"),
  2013. ec);
  2014. }
  2015. if (ERROR_SUCCESS != ec)
  2016. {
  2017. DumpRPCExtendedStatus();
  2018. SetLastError(ec);
  2019. return FALSE;
  2020. }
  2021. return TRUE;
  2022. } // FaxSetArchiveConfigurationW
  2023. #ifndef UNICODE
  2024. FaxSetArchiveConfigurationX (
  2025. IN HANDLE hFaxHandle,
  2026. IN FAX_ENUM_MESSAGE_FOLDER Folder,
  2027. IN CONST PFAX_ARCHIVE_CONFIGW pArchiveCfg
  2028. )
  2029. {
  2030. UNREFERENCED_PARAMETER (hFaxHandle);
  2031. UNREFERENCED_PARAMETER (Folder);
  2032. UNREFERENCED_PARAMETER (pArchiveCfg);
  2033. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2034. return FALSE;
  2035. }
  2036. #endif // #ifndef UNICODE
  2037. //********************************************
  2038. //* Activity logging
  2039. //********************************************
  2040. BOOL
  2041. WINAPI
  2042. FaxGetActivityLoggingConfigurationA (
  2043. IN HANDLE hFaxHandle,
  2044. OUT PFAX_ACTIVITY_LOGGING_CONFIGA *ppLoggingCfg
  2045. )
  2046. /*++
  2047. Routine name : FaxGetActivityLoggingConfigurationA
  2048. Routine description:
  2049. Gets the activity logging configuration - ANSI version
  2050. Author:
  2051. Eran Yariv (EranY), Nov, 1999
  2052. Arguments:
  2053. hFaxHandle [in ] - Handle to fax server
  2054. ppLoggingCfg [out] - Configuration buffer
  2055. Return Value:
  2056. TRUE - Success
  2057. FALSE - Failure, call GetLastError() for more error information.
  2058. --*/
  2059. {
  2060. DEBUG_FUNCTION_NAME(TEXT("FaxGetActivityLoggingConfigurationA"));
  2061. //
  2062. // no need to validate parameters, FaxGetActivityLoggingConfigurationW() will do that
  2063. //
  2064. if (!FaxGetActivityLoggingConfigurationW(
  2065. hFaxHandle,
  2066. (PFAX_ACTIVITY_LOGGING_CONFIGW*) ppLoggingCfg
  2067. ))
  2068. {
  2069. DebugPrintEx(DEBUG_ERR, _T("FaxGetActivityLoggingConfigurationW() is failed."));
  2070. return FALSE;
  2071. }
  2072. if (!ConvertUnicodeStringInPlace((LPWSTR) (*ppLoggingCfg)->lptstrDBPath))
  2073. {
  2074. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  2075. MemFree (*ppLoggingCfg);
  2076. return FALSE;
  2077. }
  2078. (*ppLoggingCfg)->dwSizeOfStruct = sizeof(FAX_ACTIVITY_LOGGING_CONFIGA);
  2079. return TRUE;
  2080. } // FaxGetActivityLoggingConfigurationA
  2081. BOOL
  2082. WINAPI
  2083. FaxGetActivityLoggingConfigurationW (
  2084. IN HANDLE hFaxHandle,
  2085. OUT PFAX_ACTIVITY_LOGGING_CONFIGW *ppLoggingCfg
  2086. )
  2087. /*++
  2088. Routine name : FaxGetActivityLoggingConfigurationW
  2089. Routine description:
  2090. Gets the activity logging configuration - UNICODE version
  2091. Author:
  2092. Eran Yariv (EranY), Nov, 1999
  2093. Arguments:
  2094. hFaxHandle [in ] - Handle to fax server
  2095. ppLoggingCfg [out] - Configuration buffer
  2096. Return Value:
  2097. TRUE - Success
  2098. FALSE - Failure, call GetLastError() for more error information.
  2099. --*/
  2100. {
  2101. DWORD dwConfigSize = 0;
  2102. error_status_t ec;
  2103. DEBUG_FUNCTION_NAME(TEXT("FaxGetActivityLoggingConfigurationW"));
  2104. //
  2105. // Validate Parameters
  2106. //
  2107. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2108. {
  2109. SetLastError(ERROR_INVALID_HANDLE);
  2110. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2111. return FALSE;
  2112. }
  2113. if (!ppLoggingCfg)
  2114. {
  2115. SetLastError(ERROR_INVALID_PARAMETER);
  2116. DebugPrintEx(DEBUG_ERR, _T("ppLoggingCfg is NULL."));
  2117. return FALSE;
  2118. }
  2119. *ppLoggingCfg = NULL;
  2120. __try
  2121. {
  2122. ec = FAX_GetActivityLoggingConfiguration(
  2123. FH_FAX_HANDLE(hFaxHandle),
  2124. (LPBYTE*)ppLoggingCfg,
  2125. &dwConfigSize
  2126. );
  2127. }
  2128. __except (EXCEPTION_EXECUTE_HANDLER)
  2129. {
  2130. //
  2131. // For some reason we got an exception.
  2132. //
  2133. ec = GetExceptionCode();
  2134. DebugPrintEx(
  2135. DEBUG_ERR,
  2136. TEXT("Exception on RPC call to FAX_GetActivityLoggingConfiguration. (ec: %ld)"),
  2137. ec);
  2138. }
  2139. if (ERROR_SUCCESS != ec)
  2140. {
  2141. DumpRPCExtendedStatus();
  2142. SetLastError(ec);
  2143. return FALSE;
  2144. }
  2145. FixupStringPtrW( ppLoggingCfg, (*ppLoggingCfg)->lptstrDBPath );
  2146. return TRUE;
  2147. } // FaxGetActivityLoggingConfigurationW
  2148. #ifndef UNICODE
  2149. FaxGetActivityLoggingConfigurationX (
  2150. IN HANDLE hFaxHandle,
  2151. OUT PFAX_ACTIVITY_LOGGING_CONFIGW *ppLoggingCfg
  2152. )
  2153. {
  2154. UNREFERENCED_PARAMETER (hFaxHandle);
  2155. UNREFERENCED_PARAMETER (ppLoggingCfg);
  2156. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2157. return FALSE;
  2158. } // FaxGetActivityLoggingConfigurationX
  2159. #endif // #ifndef UNICODE
  2160. BOOL
  2161. WINAPI
  2162. FaxSetActivityLoggingConfigurationA (
  2163. IN HANDLE hFaxHandle,
  2164. IN CONST PFAX_ACTIVITY_LOGGING_CONFIGA pLoggingCfg
  2165. )
  2166. /*++
  2167. Routine name : FaxSetActivityLoggingConfigurationA
  2168. Routine description:
  2169. Sets the activity logging configuration - ANSI version
  2170. Author:
  2171. Eran Yariv (EranY), Nov, 1999
  2172. Arguments:
  2173. hFaxHandle [in ] - Handle to fax server
  2174. pLoggingCfg [in ] - New configuration
  2175. Return Value:
  2176. TRUE - Success
  2177. FALSE - Failure, call GetLastError() for more error information.
  2178. --*/
  2179. {
  2180. FAX_ACTIVITY_LOGGING_CONFIGW ConfigW;
  2181. BOOL bRes;
  2182. DEBUG_FUNCTION_NAME(TEXT("FaxSetActivityLoggingConfigurationA"));
  2183. //
  2184. // Validate Parameters
  2185. //
  2186. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2187. {
  2188. SetLastError(ERROR_INVALID_HANDLE);
  2189. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2190. return FALSE;
  2191. }
  2192. if (!pLoggingCfg)
  2193. {
  2194. SetLastError(ERROR_INVALID_PARAMETER);
  2195. DebugPrintEx(DEBUG_ERR, _T("pLoggingCfg is NULL."));
  2196. return FALSE;
  2197. }
  2198. if (sizeof (FAX_ACTIVITY_LOGGING_CONFIGA) != pLoggingCfg->dwSizeOfStruct)
  2199. {
  2200. SetLastError(ERROR_INVALID_PARAMETER);
  2201. DebugPrintEx(DEBUG_ERR,
  2202. _T("sizeof (FAX_ACTIVITY_LOGGING_CONFIGA) != pLoggingCfg->dwSizeOfStruct."));
  2203. return FALSE;
  2204. }
  2205. //
  2206. // Create a UNICODE structure and pass along to UNICODE function
  2207. // Ansi structure is same size as unicode structure, so we can just copy it, then
  2208. // cast the string pointers correctly
  2209. //
  2210. CopyMemory(&ConfigW, pLoggingCfg, sizeof(FAX_ACTIVITY_LOGGING_CONFIGA));
  2211. ConfigW.lptstrDBPath = NULL;
  2212. ConfigW.dwSizeOfStruct = sizeof (FAX_ACTIVITY_LOGGING_CONFIGW);
  2213. if (pLoggingCfg->lptstrDBPath)
  2214. {
  2215. if (NULL ==
  2216. (ConfigW.lptstrDBPath = AnsiStringToUnicodeString(pLoggingCfg->lptstrDBPath))
  2217. )
  2218. {
  2219. DebugPrintEx(DEBUG_ERR,
  2220. _T("AnsiStringToUnicodeString(pLoggingCfg->lptstrDBPath) returns NULL."));
  2221. return FALSE;
  2222. }
  2223. }
  2224. bRes = FaxSetActivityLoggingConfigurationW (hFaxHandle, &ConfigW);
  2225. MemFree((PVOID)ConfigW.lptstrDBPath);
  2226. return bRes;
  2227. } // FaxSetActivityLoggingConfigurationA
  2228. BOOL
  2229. WINAPI
  2230. FaxSetActivityLoggingConfigurationW (
  2231. IN HANDLE hFaxHandle,
  2232. IN CONST PFAX_ACTIVITY_LOGGING_CONFIGW pLoggingCfg
  2233. )
  2234. /*++
  2235. Routine name : FaxSetActivityLoggingConfigurationW
  2236. Routine description:
  2237. Sets the activity logging configuration - UNICODE version
  2238. Author:
  2239. Eran Yariv (EranY), Nov, 1999
  2240. Arguments:
  2241. hFaxHandle [in ] - Handle to fax server
  2242. pLoggingCfg [in ] - New configuration
  2243. Return Value:
  2244. TRUE - Success
  2245. FALSE - Failure, call GetLastError() for more error information.
  2246. --*/
  2247. {
  2248. error_status_t ec;
  2249. DEBUG_FUNCTION_NAME(TEXT("FaxSetActivityLoggingConfigurationW"));
  2250. //
  2251. // Validate Parameters
  2252. //
  2253. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2254. {
  2255. SetLastError(ERROR_INVALID_HANDLE);
  2256. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2257. return FALSE;
  2258. }
  2259. if (!pLoggingCfg)
  2260. {
  2261. SetLastError(ERROR_INVALID_PARAMETER);
  2262. DebugPrintEx(DEBUG_ERR, _T("pLoggingCfg is NULL."));
  2263. return FALSE;
  2264. }
  2265. if (sizeof (FAX_ACTIVITY_LOGGING_CONFIGW) != pLoggingCfg->dwSizeOfStruct)
  2266. {
  2267. SetLastError(ERROR_INVALID_PARAMETER);
  2268. DebugPrintEx(DEBUG_ERR,
  2269. _T("sizeof (FAX_ACTIVITY_LOGGING_CONFIGW) != pLoggingCfg->dwSizeOfStruct."));
  2270. return FALSE;
  2271. }
  2272. if (pLoggingCfg->bLogIncoming || pLoggingCfg->bLogOutgoing)
  2273. {
  2274. if ((NULL == pLoggingCfg->lptstrDBPath) || (L'\0' == pLoggingCfg->lptstrDBPath[0]))
  2275. {
  2276. DebugPrintEx(DEBUG_ERR, _T("Empty logging database specified"));
  2277. SetLastError(ERROR_INVALID_PARAMETER);
  2278. return FALSE;
  2279. }
  2280. if (lstrlenW (pLoggingCfg->lptstrDBPath) > MAX_DIR_PATH) // Limit of directory path length
  2281. {
  2282. DebugPrintEx(DEBUG_ERR, _T("DB file name exceeds MAX_PATH"));
  2283. SetLastError (ERROR_BUFFER_OVERFLOW);
  2284. return FALSE;
  2285. }
  2286. }
  2287. __try
  2288. {
  2289. ec = FAX_SetActivityLoggingConfiguration(
  2290. FH_FAX_HANDLE(hFaxHandle),
  2291. pLoggingCfg );
  2292. }
  2293. __except (EXCEPTION_EXECUTE_HANDLER)
  2294. {
  2295. //
  2296. // For some reason we got an exception.
  2297. //
  2298. ec = GetExceptionCode();
  2299. DebugPrintEx(
  2300. DEBUG_ERR,
  2301. TEXT("Exception on RPC call to FAX_SetActivityLoggingConfiguration. (ec: %ld)"),
  2302. ec);
  2303. }
  2304. if (ERROR_SUCCESS != ec)
  2305. {
  2306. DumpRPCExtendedStatus();
  2307. SetLastError(ec);
  2308. return FALSE;
  2309. }
  2310. return TRUE;
  2311. } // FaxSetActivityLoggingConfigurationW
  2312. #ifndef UNICODE
  2313. FaxSetActivityLoggingConfigurationX (
  2314. IN HANDLE hFaxHandle,
  2315. IN CONST PFAX_ACTIVITY_LOGGING_CONFIGW pLoggingCfg
  2316. )
  2317. {
  2318. UNREFERENCED_PARAMETER (hFaxHandle);
  2319. UNREFERENCED_PARAMETER (pLoggingCfg);
  2320. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2321. return FALSE;
  2322. } // FaxSetActivityLoggingConfigurationX
  2323. #endif // #ifndef UNICODE
  2324. //********************************************
  2325. //* Outbound routing
  2326. //********************************************
  2327. BOOL
  2328. WINAPI
  2329. FaxAddOutboundGroupA (
  2330. IN HANDLE hFaxHandle,
  2331. IN LPCSTR lpctstrGroupName
  2332. )
  2333. {
  2334. LPWSTR lpwstrGroupName;
  2335. BOOL bRes;
  2336. DEBUG_FUNCTION_NAME(TEXT("FaxAddOutboundGroupA"));
  2337. //
  2338. // Validate Parameters
  2339. //
  2340. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2341. {
  2342. SetLastError(ERROR_INVALID_HANDLE);
  2343. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2344. return FALSE;
  2345. }
  2346. if (!lpctstrGroupName)
  2347. {
  2348. SetLastError(ERROR_INVALID_PARAMETER);
  2349. DebugPrintEx(DEBUG_ERR, _T("lpctstrGroupName is NULL."));
  2350. return FALSE;
  2351. }
  2352. if (_mbsicmp((PUCHAR)lpctstrGroupName, (PUCHAR)ROUTING_GROUP_ALL_DEVICESA) == 0)
  2353. {
  2354. SetLastError(ERROR_DUP_NAME);
  2355. DebugPrintEx(DEBUG_ERR,
  2356. _T("_mbsicmp((PUCHAR)lpctstrGroupName, (PUCHAR)ROUTING_GROUP_ALL_DEVICESA) == 0."));
  2357. return FALSE;
  2358. }
  2359. if (strlen(lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2360. {
  2361. SetLastError(ERROR_BUFFER_OVERFLOW);
  2362. DebugPrintEx(DEBUG_ERR, _T("strlen(lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME."));
  2363. return FALSE;
  2364. }
  2365. if (NULL == (lpwstrGroupName = AnsiStringToUnicodeString(lpctstrGroupName)))
  2366. {
  2367. DebugPrintEx(
  2368. DEBUG_ERR,
  2369. TEXT("AnsiStringToUnicodeString failed. (ec: %ld)"),
  2370. GetLastError());
  2371. return FALSE;
  2372. }
  2373. bRes = FaxAddOutboundGroupW (hFaxHandle, lpwstrGroupName);
  2374. MemFree (lpwstrGroupName);
  2375. return bRes;
  2376. }
  2377. BOOL
  2378. WINAPI
  2379. FaxAddOutboundGroupW (
  2380. IN HANDLE hFaxHandle,
  2381. IN LPCWSTR lpctstrGroupName
  2382. )
  2383. /*++
  2384. Routine name : FaxAddOutboundGroupW
  2385. Routine description:
  2386. Adds an empty outbound routing group for a Fax server
  2387. Author:
  2388. Oded Sacher (OdedS), Nov, 1999
  2389. Arguments:
  2390. hFaxHandle [ in ] - Fax server handle obtained from a call to FaxConnectFaxServer
  2391. lpctstrGroupName [ in ] - A pointer to a null-terminated string that uniqely identifies a new group name
  2392. Return Value:
  2393. TRUE - Success
  2394. FALSE - Failure, call GetLastError() for more error information.
  2395. --*/
  2396. {
  2397. error_status_t ec;
  2398. DEBUG_FUNCTION_NAME(TEXT("FaxAddOutboundGroupW"));
  2399. //
  2400. // Validate Parameters
  2401. //
  2402. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2403. {
  2404. SetLastError(ERROR_INVALID_HANDLE);
  2405. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2406. return FALSE;
  2407. }
  2408. if (!lpctstrGroupName)
  2409. {
  2410. SetLastError(ERROR_INVALID_PARAMETER);
  2411. DebugPrintEx(DEBUG_ERR, _T("lpctstrGroupName is NULL."));
  2412. return FALSE;
  2413. }
  2414. if (_wcsicmp (lpctstrGroupName, ROUTING_GROUP_ALL_DEVICESW) == 0)
  2415. {
  2416. SetLastError(ERROR_DUP_NAME);
  2417. DebugPrintEx(DEBUG_ERR,
  2418. _T("_mbsicmp((PUCHAR)lpctstrGroupName, (PUCHAR)ROUTING_GROUP_ALL_DEVICESA) == 0."));
  2419. return FALSE;
  2420. }
  2421. if (wcslen (lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2422. {
  2423. SetLastError(ERROR_BUFFER_OVERFLOW);
  2424. DebugPrintEx(DEBUG_ERR, _T("strlen(lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME."));
  2425. return FALSE;
  2426. }
  2427. __try
  2428. {
  2429. ec = FAX_AddOutboundGroup( FH_FAX_HANDLE(hFaxHandle),
  2430. lpctstrGroupName );
  2431. }
  2432. __except (EXCEPTION_EXECUTE_HANDLER)
  2433. {
  2434. //
  2435. // For some reason we got an exception.
  2436. //
  2437. ec = GetExceptionCode();
  2438. DebugPrintEx(
  2439. DEBUG_ERR,
  2440. TEXT("Exception on RPC call to FAX_AddOutboundGroup. (ec: %ld)"),
  2441. ec);
  2442. }
  2443. if (ERROR_SUCCESS != ec)
  2444. {
  2445. DumpRPCExtendedStatus();
  2446. SetLastError(ec);
  2447. return FALSE;
  2448. }
  2449. return TRUE;
  2450. }
  2451. #ifndef UNICODE
  2452. FaxAddOutboundGroupX (
  2453. IN HANDLE hFaxHandle,
  2454. IN LPCSTR lpctstrGroupName
  2455. )
  2456. {
  2457. UNREFERENCED_PARAMETER (hFaxHandle);
  2458. UNREFERENCED_PARAMETER (lpctstrGroupName);
  2459. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2460. return FALSE;
  2461. }
  2462. #endif // #ifndef UNICODE
  2463. BOOL
  2464. WINAPI
  2465. FaxSetOutboundGroupA (
  2466. IN HANDLE hFaxHandle,
  2467. IN PFAX_OUTBOUND_ROUTING_GROUPA pGroup
  2468. )
  2469. {
  2470. FAX_OUTBOUND_ROUTING_GROUPW GroupW;
  2471. BOOL bRes;
  2472. DEBUG_FUNCTION_NAME(TEXT("FaxSetOutboundGroupA"));
  2473. //
  2474. // Validate Parameters
  2475. //
  2476. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2477. {
  2478. SetLastError(ERROR_INVALID_HANDLE);
  2479. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2480. return FALSE;
  2481. }
  2482. if (!pGroup)
  2483. {
  2484. SetLastError(ERROR_INVALID_PARAMETER);
  2485. DebugPrintEx(DEBUG_ERR, _T("pGroup is NULL."));
  2486. return FALSE;
  2487. }
  2488. if (sizeof (FAX_OUTBOUND_ROUTING_GROUPA) != pGroup->dwSizeOfStruct)
  2489. {
  2490. SetLastError(ERROR_INVALID_PARAMETER);
  2491. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_OUTBOUND_ROUTING_GROUPA) != pGroup->dwSizeOfStruct."));
  2492. return FALSE;
  2493. }
  2494. if (!pGroup->lpctstrGroupName)
  2495. {
  2496. SetLastError(ERROR_INVALID_PARAMETER);
  2497. DebugPrintEx(DEBUG_ERR, _T("pGroup->lpctstrGroupName is NULL."));
  2498. return FALSE;
  2499. }
  2500. if (strlen (pGroup->lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2501. {
  2502. SetLastError(ERROR_BUFFER_OVERFLOW);
  2503. DebugPrintEx(DEBUG_ERR, _T("strlen (pGroup->lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME."));
  2504. return FALSE;
  2505. }
  2506. if (!pGroup->lpdwDevices && pGroup->dwNumDevices)
  2507. {
  2508. SetLastError(ERROR_INVALID_PARAMETER);
  2509. DebugPrintEx(DEBUG_ERR, _T("!pGroup->lpdwDevices && pGroup->dwNumDevices."));
  2510. return FALSE;
  2511. }
  2512. //
  2513. // Create a UNICODE structure and pass along to UNICODE function
  2514. // Ansi structure is same size as unicode structure, so we can just copy it, then
  2515. // cast the string pointers correctly
  2516. //
  2517. CopyMemory(&GroupW, pGroup, sizeof(FAX_OUTBOUND_ROUTING_GROUPA));
  2518. GroupW.dwSizeOfStruct = sizeof (FAX_OUTBOUND_ROUTING_GROUPW);
  2519. if (NULL == (GroupW.lpctstrGroupName = AnsiStringToUnicodeString(pGroup->lpctstrGroupName)))
  2520. {
  2521. DebugPrintEx(
  2522. DEBUG_ERR,
  2523. TEXT("AnsiStringToUnicodeString failed. (ec: %ld)"),
  2524. GetLastError());
  2525. return FALSE;
  2526. }
  2527. bRes = FaxSetOutboundGroupW (hFaxHandle, &GroupW);
  2528. MemFree((PVOID)GroupW.lpctstrGroupName);
  2529. return bRes;
  2530. }
  2531. BOOL
  2532. WINAPI
  2533. FaxSetOutboundGroupW (
  2534. IN HANDLE hFaxHandle,
  2535. IN PFAX_OUTBOUND_ROUTING_GROUPW pGroup
  2536. )
  2537. /*++
  2538. Routine name : FaxSetOutboundGroupW
  2539. Routine description:
  2540. Sets an outbound routing group settings for a Fax server
  2541. Author:
  2542. Oded Sacher (OdedS), Nov, 1999
  2543. Arguments:
  2544. hFaxHandle [in] - Fax server handle
  2545. pGroup [in] - Pointer to a FAX_OUTBOUND_ROUTING_GROUP buffer to set
  2546. Return Value:
  2547. TRUE - Success
  2548. FALSE - Failure, call GetLastError() for more error information.
  2549. --*/
  2550. {
  2551. error_status_t ec;
  2552. DEBUG_FUNCTION_NAME(TEXT("FaxSetOutboundGroupW"));
  2553. //
  2554. // Validate Parameters
  2555. //
  2556. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2557. {
  2558. SetLastError(ERROR_INVALID_HANDLE);
  2559. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2560. return FALSE;
  2561. }
  2562. if (!pGroup)
  2563. {
  2564. SetLastError(ERROR_INVALID_PARAMETER);
  2565. DebugPrintEx(DEBUG_ERR, _T("pGroup is NULL."));
  2566. return FALSE;
  2567. }
  2568. if (sizeof (FAX_OUTBOUND_ROUTING_GROUPW) != pGroup->dwSizeOfStruct)
  2569. {
  2570. SetLastError(ERROR_INVALID_PARAMETER);
  2571. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_OUTBOUND_ROUTING_GROUPW) != pGroup->dwSizeOfStruct."));
  2572. return FALSE;
  2573. }
  2574. if (!pGroup->lpctstrGroupName)
  2575. {
  2576. SetLastError(ERROR_INVALID_PARAMETER);
  2577. DebugPrintEx(DEBUG_ERR, _T("pGroup->lpctstrGroupName is NULL."));
  2578. return FALSE;
  2579. }
  2580. if (wcslen (pGroup->lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2581. {
  2582. SetLastError(ERROR_BUFFER_OVERFLOW);
  2583. DebugPrintEx(DEBUG_ERR, _T("wcslen (pGroup->lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME."));
  2584. return FALSE;
  2585. }
  2586. if (!pGroup->lpdwDevices && pGroup->dwNumDevices)
  2587. {
  2588. SetLastError(ERROR_INVALID_PARAMETER);
  2589. DebugPrintEx(DEBUG_ERR, _T("!pGroup->lpdwDevices && pGroup->dwNumDevices."));
  2590. return FALSE;
  2591. }
  2592. Assert (sizeof (RPC_FAX_OUTBOUND_ROUTING_GROUPW) == sizeof (FAX_OUTBOUND_ROUTING_GROUPW));
  2593. __try
  2594. {
  2595. ec = FAX_SetOutboundGroup( FH_FAX_HANDLE(hFaxHandle),
  2596. (PRPC_FAX_OUTBOUND_ROUTING_GROUPW)pGroup
  2597. );
  2598. }
  2599. __except (EXCEPTION_EXECUTE_HANDLER)
  2600. {
  2601. //
  2602. // For some reason we got an exception.
  2603. //
  2604. ec = GetExceptionCode();
  2605. DebugPrintEx(
  2606. DEBUG_ERR,
  2607. TEXT("Exception on RPC call to FAX_SetOutboundGroup. (ec: %ld)"),
  2608. ec);
  2609. }
  2610. if (ERROR_SUCCESS != ec)
  2611. {
  2612. DumpRPCExtendedStatus();
  2613. SetLastError(ec);
  2614. return FALSE;
  2615. }
  2616. return TRUE;
  2617. }
  2618. #ifndef UNICODE
  2619. FaxSetOutboundGroupX (
  2620. IN HANDLE hFaxHandle,
  2621. IN PFAX_OUTBOUND_ROUTING_GROUPW pGroup
  2622. )
  2623. {
  2624. UNREFERENCED_PARAMETER (hFaxHandle);
  2625. UNREFERENCED_PARAMETER (pGroup);
  2626. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2627. return FALSE;
  2628. }
  2629. #endif // #ifndef UNICODE
  2630. WINFAXAPI
  2631. BOOL
  2632. WINAPI
  2633. FaxEnumOutboundGroupsA (
  2634. IN HANDLE hFaxHandle,
  2635. OUT PFAX_OUTBOUND_ROUTING_GROUPA *ppGroups,
  2636. OUT LPDWORD lpdwNumGroups
  2637. )
  2638. {
  2639. PFAX_OUTBOUND_ROUTING_GROUPW pGroup;
  2640. DWORD i;
  2641. DEBUG_FUNCTION_NAME(TEXT("FaxEnumOutboundGroupsA"));
  2642. //
  2643. // no need to validate parameters, FaxEnumOutboundGroupsW() will do that
  2644. //
  2645. if (!FaxEnumOutboundGroupsW (hFaxHandle,
  2646. (PFAX_OUTBOUND_ROUTING_GROUPW*) ppGroups,
  2647. lpdwNumGroups))
  2648. {
  2649. DebugPrintEx(DEBUG_ERR, _T("FaxEnumOutboundGroupsW() is failed. (ec: %ld)"), GetLastError());
  2650. return FALSE;
  2651. }
  2652. pGroup = (PFAX_OUTBOUND_ROUTING_GROUPW) *ppGroups;
  2653. for (i = 0; i < *lpdwNumGroups; i++)
  2654. {
  2655. if (!ConvertUnicodeStringInPlace((LPWSTR) pGroup[i].lpctstrGroupName))
  2656. {
  2657. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  2658. MemFree (*ppGroups);
  2659. return FALSE;
  2660. }
  2661. }
  2662. return TRUE;
  2663. } //FaxEnumOutboundGroupsA
  2664. WINFAXAPI
  2665. BOOL
  2666. WINAPI
  2667. FaxEnumOutboundGroupsW (
  2668. IN HANDLE hFaxHandle,
  2669. OUT PFAX_OUTBOUND_ROUTING_GROUPW *ppGroups,
  2670. OUT LPDWORD lpdwNumGroups
  2671. )
  2672. /*++
  2673. Routine name : FaxEnumOutboundGroupsW
  2674. Routine description:
  2675. Enumerates all the outbound routing groups of a fax server.
  2676. Author:
  2677. Oded Sacher (OdedS), Dec, 1999
  2678. Arguments:
  2679. hFaxHandle [in ] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  2680. ppGroups [out ] - A pointer to a buffer of FAX_OUTBOUND_ROUTING_GROUP structures.
  2681. This buffer is allocated by the function and the client should call FaxFreeBuffer to free it.
  2682. lpdwNumGroups [out ] - Pointer to a DWORD value indicating the number of groups retrieved.
  2683. Return Value:
  2684. TRUE - Success
  2685. FALSE - Failure, call GetLastError() for more error information.
  2686. --*/
  2687. {
  2688. error_status_t ec;
  2689. DWORD dwBufferSize = 0;
  2690. DWORD i;
  2691. DEBUG_FUNCTION_NAME(TEXT("FaxEnumOutboundGroupsW"));
  2692. //
  2693. // Validate Parameters
  2694. //
  2695. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2696. {
  2697. SetLastError(ERROR_INVALID_HANDLE);
  2698. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2699. return FALSE;
  2700. }
  2701. if (!ppGroups)
  2702. {
  2703. SetLastError(ERROR_INVALID_PARAMETER);
  2704. DebugPrintEx(DEBUG_ERR, _T("ppGroups is NULL."));
  2705. return FALSE;
  2706. }
  2707. if (!lpdwNumGroups)
  2708. {
  2709. SetLastError(ERROR_INVALID_PARAMETER);
  2710. DebugPrintEx(DEBUG_ERR, _T("lpdwNumGroups is NULL."));
  2711. return FALSE;
  2712. }
  2713. *ppGroups = NULL;
  2714. *lpdwNumGroups = 0;
  2715. __try
  2716. {
  2717. ec = FAX_EnumOutboundGroups( FH_FAX_HANDLE(hFaxHandle),
  2718. (LPBYTE*) ppGroups,
  2719. &dwBufferSize,
  2720. lpdwNumGroups
  2721. );
  2722. }
  2723. __except (EXCEPTION_EXECUTE_HANDLER)
  2724. {
  2725. //
  2726. // For some reason we got an exception.
  2727. //
  2728. ec = GetExceptionCode();
  2729. DebugPrintEx(
  2730. DEBUG_ERR,
  2731. TEXT("Exception on RPC call to FAX_EnumOutboundGroups. (ec: %ld)"),
  2732. ec);
  2733. }
  2734. if (ERROR_SUCCESS != ec)
  2735. {
  2736. DumpRPCExtendedStatus();
  2737. SetLastError(ec);
  2738. return FALSE;
  2739. }
  2740. //
  2741. // Unpack buffer
  2742. //
  2743. for (i = 0; i < *lpdwNumGroups; i++)
  2744. {
  2745. FixupStringPtrW( ppGroups, (*ppGroups)[i].lpctstrGroupName );
  2746. if ((*ppGroups)[i].lpdwDevices != NULL)
  2747. {
  2748. (*ppGroups)[i].lpdwDevices =
  2749. (LPDWORD)((LPBYTE)(*ppGroups) + (ULONG_PTR)((*ppGroups)[i].lpdwDevices));
  2750. }
  2751. }
  2752. return TRUE;
  2753. }//FaxEnumOutboundGroupsW
  2754. #ifndef UNICODE
  2755. WINFAXAPI
  2756. BOOL
  2757. WINAPI
  2758. FaxEnumOutboundGroupsX (
  2759. IN HANDLE hFaxHandle,
  2760. OUT PFAX_OUTBOUND_ROUTING_GROUPW *ppGroups,
  2761. OUT LPDWORD lpdwNumGroups
  2762. )
  2763. {
  2764. UNREFERENCED_PARAMETER (hFaxHandle);
  2765. UNREFERENCED_PARAMETER (ppGroups);
  2766. UNREFERENCED_PARAMETER (lpdwNumGroups);
  2767. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2768. return FALSE;
  2769. }
  2770. #endif // #ifndef UNICODE
  2771. WINFAXAPI
  2772. BOOL
  2773. WINAPI
  2774. FaxRemoveOutboundGroupA (
  2775. IN HANDLE hFaxHandle,
  2776. IN LPCSTR lpctstrGroupName
  2777. )
  2778. {
  2779. LPWSTR lpwstrGroupName;
  2780. BOOL bRes;
  2781. DEBUG_FUNCTION_NAME(TEXT("FaxRemoveOutboundGroupA"));
  2782. if (NULL == (lpwstrGroupName = AnsiStringToUnicodeString(lpctstrGroupName)))
  2783. {
  2784. DebugPrintEx(
  2785. DEBUG_ERR,
  2786. TEXT("AnsiStringToUnicodeString failed. (ec: %ld)"),
  2787. GetLastError());
  2788. return FALSE;
  2789. }
  2790. bRes = FaxRemoveOutboundGroupW (hFaxHandle, lpwstrGroupName);
  2791. MemFree (lpwstrGroupName);
  2792. return bRes;
  2793. }//FaxRemoveOutboundGroupA
  2794. WINFAXAPI
  2795. BOOL
  2796. WINAPI
  2797. FaxRemoveOutboundGroupW (
  2798. IN HANDLE hFaxHandle,
  2799. IN LPCWSTR lpctstrGroupName
  2800. )
  2801. /*++
  2802. Routine name : FaxRemoveOutboundGroupW
  2803. Routine description:
  2804. Removes an existing outbound routing group for a Fax server
  2805. Author:
  2806. Oded Sacher (OdedS), Nov, 1999
  2807. Arguments:
  2808. hFaxHandle [ in ] - Fax server handle obtained from a call to FaxConnectFaxServer
  2809. lpctstrGroupName [ in ] - A pointer to a null-terminated string that uniqely identifies the group name
  2810. Return Value:
  2811. TRUE - Success
  2812. FALSE - Failure, call GetLastError() for more error information.
  2813. --*/
  2814. {
  2815. error_status_t ec;
  2816. DEBUG_FUNCTION_NAME(TEXT("FaxRemoveOutboundGroupW"));
  2817. //
  2818. // Validate Parameters
  2819. //
  2820. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2821. {
  2822. SetLastError(ERROR_INVALID_HANDLE);
  2823. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2824. return FALSE;
  2825. }
  2826. if (!lpctstrGroupName)
  2827. {
  2828. SetLastError(ERROR_INVALID_PARAMETER);
  2829. DebugPrintEx(DEBUG_ERR, _T("lpctstrGroupName is NULL."));
  2830. return FALSE;
  2831. }
  2832. if (_wcsicmp (lpctstrGroupName, ROUTING_GROUP_ALL_DEVICESW) == 0)
  2833. {
  2834. SetLastError(ERROR_INVALID_OPERATION);
  2835. DebugPrintEx(DEBUG_ERR, _T("_wcsicmp (lpctstrGroupName, ROUTING_GROUP_ALL_DEVICESW) == 0."));
  2836. return FALSE;
  2837. }
  2838. if (wcslen (lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2839. {
  2840. SetLastError(ERROR_BUFFER_OVERFLOW);
  2841. DebugPrintEx(DEBUG_ERR, _T("wcslen (lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME."));
  2842. return FALSE;
  2843. }
  2844. __try
  2845. {
  2846. ec = FAX_RemoveOutboundGroup( FH_FAX_HANDLE(hFaxHandle),
  2847. lpctstrGroupName );
  2848. }
  2849. __except (EXCEPTION_EXECUTE_HANDLER)
  2850. {
  2851. //
  2852. // For some reason we got an exception.
  2853. //
  2854. ec = GetExceptionCode();
  2855. DebugPrintEx(
  2856. DEBUG_ERR,
  2857. TEXT("Exception on RPC call to FAX_RemoveOutboundGroup. (ec: %ld)"),
  2858. ec);
  2859. }
  2860. if (ERROR_SUCCESS != ec)
  2861. {
  2862. DumpRPCExtendedStatus();
  2863. SetLastError(ec);
  2864. return FALSE;
  2865. }
  2866. return TRUE;
  2867. }//FaxRemoveOutboundGroupW
  2868. #ifndef UNICODE
  2869. WINFAXAPI
  2870. BOOL
  2871. WINAPI
  2872. FaxRemoveOutboundGroupX (
  2873. IN HANDLE hFaxHandle,
  2874. IN LPCWSTR lpctstrGroupName
  2875. )
  2876. {
  2877. UNREFERENCED_PARAMETER (hFaxHandle);
  2878. UNREFERENCED_PARAMETER (lpctstrGroupName);
  2879. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  2880. return FALSE;
  2881. }
  2882. #endif // #ifndef UNICODE
  2883. BOOL
  2884. WINAPI
  2885. FaxSetDeviceOrderInGroupA (
  2886. IN HANDLE hFaxHandle,
  2887. IN LPCSTR lpctstrGroupName,
  2888. IN DWORD dwDeviceId,
  2889. IN DWORD dwNewOrder
  2890. )
  2891. {
  2892. LPWSTR lpwstrGroupName;
  2893. BOOL bRes;
  2894. DEBUG_FUNCTION_NAME(TEXT("FaxSetDeviceOrderInGroupA"));
  2895. if (NULL == (lpwstrGroupName = AnsiStringToUnicodeString(lpctstrGroupName)))
  2896. {
  2897. DebugPrintEx(
  2898. DEBUG_ERR,
  2899. TEXT("AnsiStringToUnicodeString failed. (ec: %ld)"),
  2900. GetLastError());
  2901. return FALSE;
  2902. }
  2903. bRes = FaxSetDeviceOrderInGroupW (hFaxHandle, lpwstrGroupName, dwDeviceId, dwNewOrder);
  2904. MemFree (lpwstrGroupName);
  2905. return bRes;
  2906. }//FaxSetDeviceOrderInGroupA
  2907. BOOL
  2908. WINAPI
  2909. FaxSetDeviceOrderInGroupW (
  2910. IN HANDLE hFaxHandle,
  2911. IN LPCWSTR lpctstrGroupName,
  2912. IN DWORD dwDeviceId,
  2913. IN DWORD dwNewOrder
  2914. )
  2915. /*++
  2916. Routine name : FaxSetDeviceOrderInGroupW
  2917. Routine description:
  2918. Sets the order of a single device in a group of outbound routing devices.
  2919. Author:
  2920. Oded Sacher (OdedS), Dec, 1999
  2921. Arguments:
  2922. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function
  2923. lpctstrGroupName [in] - A pointer to a null-terminated string that uniquely identifies a group.
  2924. dwDeviceId [in] - A DWORD value specifying the id of the device in the group. The specified device must exist in the group.
  2925. dwNewOrder [in] - A DWORD value specifying the new 1-based order of the device in the group. If there are N devices in the group, this value must be between 1 and N (including).
  2926. Return Value:
  2927. TRUE - Success
  2928. FALSE - Failure, call GetLastError() for more error information.
  2929. --*/
  2930. {
  2931. error_status_t ec;
  2932. DEBUG_FUNCTION_NAME(TEXT("FaxSetDeviceOrderInGroupW"));
  2933. //
  2934. // Validate Parameters
  2935. //
  2936. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  2937. {
  2938. SetLastError(ERROR_INVALID_HANDLE);
  2939. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  2940. return FALSE;
  2941. }
  2942. if (!dwDeviceId)
  2943. {
  2944. SetLastError(ERROR_INVALID_PARAMETER);
  2945. DebugPrintEx(DEBUG_ERR, _T("dwDeviceId is ZERO."));
  2946. return FALSE;
  2947. }
  2948. if (!dwNewOrder)
  2949. {
  2950. SetLastError(ERROR_INVALID_PARAMETER);
  2951. DebugPrintEx(DEBUG_ERR, _T("dwNewOrder is ZERO."));
  2952. return FALSE;
  2953. }
  2954. if (!lpctstrGroupName)
  2955. {
  2956. SetLastError(ERROR_INVALID_PARAMETER);
  2957. DebugPrintEx(DEBUG_ERR, _T("lpctstrGroupName is NULL."));
  2958. return FALSE;
  2959. }
  2960. if (wcslen (lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  2961. {
  2962. DebugPrintEx(DEBUG_ERR, _T("Group name length exceeded MAX_ROUTING_GROUP_NAME"));
  2963. SetLastError(ERROR_BUFFER_OVERFLOW);
  2964. return FALSE;
  2965. }
  2966. __try
  2967. {
  2968. ec = FAX_SetDeviceOrderInGroup( FH_FAX_HANDLE(hFaxHandle),
  2969. lpctstrGroupName,
  2970. dwDeviceId,
  2971. dwNewOrder);
  2972. }
  2973. __except (EXCEPTION_EXECUTE_HANDLER)
  2974. {
  2975. //
  2976. // For some reason we got an exception.
  2977. //
  2978. ec = GetExceptionCode();
  2979. DebugPrintEx(
  2980. DEBUG_ERR,
  2981. TEXT("Exception on RPC call to FAX_SetDeviceOrderInGroup. (ec: %ld)"),
  2982. ec);
  2983. }
  2984. if (ERROR_SUCCESS != ec)
  2985. {
  2986. DumpRPCExtendedStatus();
  2987. SetLastError(ec);
  2988. return FALSE;
  2989. }
  2990. return TRUE;
  2991. }//FaxSetDeviceOrderInGroupW
  2992. #ifndef UNICODE
  2993. BOOL
  2994. WINAPI
  2995. FaxSetDeviceOrderInGroupX (
  2996. IN HANDLE hFaxHandle,
  2997. IN LPCWSTR lpctstrGroupName,
  2998. IN DWORD dwDeviceId,
  2999. IN DWORD dwNewOrder
  3000. )
  3001. {
  3002. UNREFERENCED_PARAMETER (hFaxHandle);
  3003. UNREFERENCED_PARAMETER (lpctstrGroupName);
  3004. UNREFERENCED_PARAMETER (dwDeviceId);
  3005. UNREFERENCED_PARAMETER (dwNewOrder);
  3006. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  3007. return FALSE;
  3008. }
  3009. #endif // #ifndef UNICODE
  3010. BOOL
  3011. WINAPI
  3012. FaxAddOutboundRuleA (
  3013. IN HANDLE hFaxHandle,
  3014. IN DWORD dwAreaCode,
  3015. IN DWORD dwCountryCode,
  3016. IN DWORD dwDeviceID,
  3017. IN LPCSTR lpctstrGroupName,
  3018. IN BOOL bUseGroup
  3019. )
  3020. {
  3021. LPWSTR lpwstrGroupName = NULL;
  3022. BOOL bRes;
  3023. DEBUG_FUNCTION_NAME(TEXT("FaxAddOutboundRuleA"));
  3024. if (TRUE == bUseGroup)
  3025. {
  3026. if (!lpctstrGroupName)
  3027. {
  3028. DebugPrintEx(
  3029. DEBUG_ERR,
  3030. TEXT("lpctstrGroupName is NULL"));
  3031. SetLastError(ERROR_INVALID_PARAMETER);
  3032. return FALSE;
  3033. }
  3034. if (NULL == (lpwstrGroupName = AnsiStringToUnicodeString(lpctstrGroupName)))
  3035. {
  3036. DebugPrintEx(
  3037. DEBUG_ERR,
  3038. TEXT("AnsiStringToUnicodeString failed. (ec: %ld)"),
  3039. GetLastError());
  3040. return FALSE;
  3041. }
  3042. }
  3043. bRes = FaxAddOutboundRuleW (hFaxHandle,
  3044. dwAreaCode,
  3045. dwCountryCode,
  3046. dwDeviceID,
  3047. lpwstrGroupName,
  3048. bUseGroup);
  3049. MemFree (lpwstrGroupName);
  3050. return bRes;
  3051. }
  3052. BOOL
  3053. WINAPI
  3054. FaxAddOutboundRuleW (
  3055. IN HANDLE hFaxHandle,
  3056. IN DWORD dwAreaCode,
  3057. IN DWORD dwCountryCode,
  3058. IN DWORD dwDeviceID,
  3059. IN LPCWSTR lpctstrGroupName,
  3060. IN BOOL bUseGroup
  3061. )
  3062. /*++
  3063. Routine name : FaxAddOutboundRuleW
  3064. Routine description:
  3065. Adds a new outbound routing rule to the fax service
  3066. Author:
  3067. Oded Sacher (OdedS), Dec, 1999
  3068. Arguments:
  3069. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3070. dwAreaCode [in] - The area code of the rule.
  3071. dwCountryCode [in] - The country code of the rule.
  3072. dwDeviceID [in] - The destination device of the rule.
  3073. lpctstrGroupName [in] - The destination group of the rule. This value is valid only if the bUseGroup member is TRUE.
  3074. bUseGroup [in] - A Boolean value specifying whether the group should be used as the destination.
  3075. Return Value:
  3076. TRUE - Success
  3077. FALSE - Failure, call GetLastError() for more error information.
  3078. --*/
  3079. {
  3080. error_status_t ec;
  3081. DEBUG_FUNCTION_NAME(TEXT("FaxAddOutboundRuleW"));
  3082. //
  3083. // Validate Parameters
  3084. //
  3085. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3086. {
  3087. SetLastError(ERROR_INVALID_HANDLE);
  3088. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3089. return FALSE;
  3090. }
  3091. if (dwCountryCode == ROUTING_RULE_COUNTRY_CODE_ANY)
  3092. {
  3093. //
  3094. // *.* can not be added; *.AreaCode is not a valid rule dialing location.
  3095. //
  3096. DebugPrintEx(DEBUG_ERR,
  3097. _T("dwCountryCode = 0; *.* can not be added; *.AreaCode is not a valid rule dialing location"));
  3098. SetLastError(ERROR_INVALID_PARAMETER);
  3099. return FALSE;
  3100. }
  3101. if (TRUE == bUseGroup)
  3102. {
  3103. if (!lpctstrGroupName)
  3104. {
  3105. DebugPrintEx(DEBUG_ERR, _T("lpctstrGroupName is NULL"));
  3106. SetLastError(ERROR_INVALID_PARAMETER);
  3107. return FALSE;
  3108. }
  3109. if (wcslen (lpctstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  3110. {
  3111. DebugPrintEx(DEBUG_ERR, _T("Group name length exceeded MAX_ROUTING_GROUP_NAME"));
  3112. SetLastError(ERROR_BUFFER_OVERFLOW);
  3113. return FALSE;
  3114. }
  3115. }
  3116. else
  3117. {
  3118. if (!dwDeviceID)
  3119. {
  3120. DebugPrintEx(DEBUG_ERR, _T("dwDeviceId = 0; Not a valid device ID"));
  3121. SetLastError(ERROR_INVALID_PARAMETER);
  3122. return FALSE;
  3123. }
  3124. lpctstrGroupName = NULL;
  3125. }
  3126. __try
  3127. {
  3128. ec = FAX_AddOutboundRule( FH_FAX_HANDLE(hFaxHandle),
  3129. dwAreaCode,
  3130. dwCountryCode,
  3131. dwDeviceID,
  3132. lpctstrGroupName,
  3133. bUseGroup);
  3134. }
  3135. __except (EXCEPTION_EXECUTE_HANDLER)
  3136. {
  3137. //
  3138. // For some reason we got an exception.
  3139. //
  3140. ec = GetExceptionCode();
  3141. DebugPrintEx(
  3142. DEBUG_ERR,
  3143. TEXT("Exception on RPC call to FAX_AddOutboundRule. (ec: %ld)"),
  3144. ec);
  3145. }
  3146. if (ERROR_SUCCESS != ec)
  3147. {
  3148. DumpRPCExtendedStatus();
  3149. SetLastError(ec);
  3150. return FALSE;
  3151. }
  3152. return TRUE;
  3153. } //FaxAddOutboundRuleW
  3154. #ifndef UNICODE
  3155. BOOL
  3156. WINAPI
  3157. FaxAddOutboundRuleX (
  3158. IN HANDLE hFaxHandle,
  3159. IN DWORD dwAreaCode,
  3160. IN DWORD dwCountryCode,
  3161. IN DWORD dwDeviceID,
  3162. IN LPCWSTR lpctstrGroupName,
  3163. IN BOOL bUseGroup
  3164. )
  3165. {
  3166. UNREFERENCED_PARAMETER (hFaxHandle);
  3167. UNREFERENCED_PARAMETER (dwAreaCode);
  3168. UNREFERENCED_PARAMETER (dwCountryCode);
  3169. UNREFERENCED_PARAMETER (dwDeviceID);
  3170. UNREFERENCED_PARAMETER (lpctstrGroupName);
  3171. UNREFERENCED_PARAMETER (bUseGroup);
  3172. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  3173. return FALSE;
  3174. }
  3175. #endif // #ifndef UNICODE
  3176. BOOL
  3177. WINAPI
  3178. FaxRemoveOutboundRule (
  3179. IN HANDLE hFaxHandle,
  3180. IN DWORD dwAreaCode,
  3181. IN DWORD dwCountryCode
  3182. )
  3183. /*++
  3184. Routine name : FaxRemoveOutboundRule
  3185. Routine description:
  3186. Removes an existing outbound routing rule from the fax service
  3187. Author:
  3188. Oded Sacher (OdedS), Dec, 1999
  3189. Arguments:
  3190. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3191. dwAreaCode [in] - The area code of the rule.
  3192. dwCountryCode [in] - The country code of the rule.
  3193. Return Value:
  3194. TRUE - Success
  3195. FALSE - Failure, call GetLastError() for more error information.
  3196. --*/
  3197. {
  3198. error_status_t ec;
  3199. DEBUG_FUNCTION_NAME(TEXT("FaxRemoveOutboundRule"));
  3200. //
  3201. // Validate Parameters
  3202. //
  3203. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3204. {
  3205. SetLastError(ERROR_INVALID_HANDLE);
  3206. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3207. return FALSE;
  3208. }
  3209. if (dwCountryCode == ROUTING_RULE_COUNTRY_CODE_ANY)
  3210. {
  3211. //
  3212. // *.* can not be removed; *.AreaCode is not a valid rule dialing location.
  3213. //
  3214. DebugPrintEx(DEBUG_ERR,
  3215. _T("dwCountryCode = 0; *.* can not be removed; *.AreaCode is not a valid rule dialing location"));
  3216. SetLastError(ERROR_INVALID_PARAMETER);
  3217. return FALSE;
  3218. }
  3219. __try
  3220. {
  3221. ec = FAX_RemoveOutboundRule( FH_FAX_HANDLE(hFaxHandle),
  3222. dwAreaCode,
  3223. dwCountryCode);
  3224. }
  3225. __except (EXCEPTION_EXECUTE_HANDLER)
  3226. {
  3227. //
  3228. // For some reason we got an exception.
  3229. //
  3230. ec = GetExceptionCode();
  3231. DebugPrintEx(
  3232. DEBUG_ERR,
  3233. TEXT("Exception on RPC call to FAX_RemoveOutboundRule. (ec: %ld)"),
  3234. ec);
  3235. }
  3236. if (ERROR_SUCCESS != ec)
  3237. {
  3238. DumpRPCExtendedStatus();
  3239. SetLastError(ec);
  3240. return FALSE;
  3241. }
  3242. return TRUE;
  3243. } // FaxRemoveOutboundRule
  3244. BOOL
  3245. WINAPI
  3246. FaxEnumOutboundRulesA (
  3247. IN HANDLE hFaxHandle,
  3248. OUT PFAX_OUTBOUND_ROUTING_RULEA *ppRules,
  3249. OUT LPDWORD lpdwNumRules
  3250. )
  3251. {
  3252. PFAX_OUTBOUND_ROUTING_RULEW pRule;
  3253. DWORD i;
  3254. DEBUG_FUNCTION_NAME(TEXT("FaxEnumOutboundRulesA"));
  3255. //
  3256. // no need to validate parameters, FaxEnumOutboundRulesW() will do that
  3257. //
  3258. if (!FaxEnumOutboundRulesW (hFaxHandle,
  3259. (PFAX_OUTBOUND_ROUTING_RULEW*) ppRules,
  3260. lpdwNumRules))
  3261. {
  3262. DebugPrintEx(DEBUG_ERR, _T("FaxEnumOutboundRulesW() is failed. (ec: %ld)"), GetLastError());
  3263. return FALSE;
  3264. }
  3265. pRule = (PFAX_OUTBOUND_ROUTING_RULEW) *ppRules;
  3266. for (i = 0; i < *lpdwNumRules; i++)
  3267. {
  3268. if (TRUE == pRule[i].bUseGroup)
  3269. {
  3270. if (!ConvertUnicodeStringInPlace((LPWSTR) pRule[i].Destination.lpcstrGroupName))
  3271. {
  3272. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  3273. MemFree (*ppRules);
  3274. return FALSE;
  3275. }
  3276. }
  3277. if (!ConvertUnicodeStringInPlace((LPWSTR) pRule[i].lpctstrCountryName))
  3278. {
  3279. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  3280. MemFree (*ppRules);
  3281. return FALSE;
  3282. }
  3283. }
  3284. return TRUE;
  3285. } // FaxEnumOutboundRulesA
  3286. BOOL
  3287. WINAPI
  3288. FaxEnumOutboundRulesW (
  3289. IN HANDLE hFaxHandle,
  3290. OUT PFAX_OUTBOUND_ROUTING_RULEW *ppRules,
  3291. OUT LPDWORD lpdwNumRules
  3292. )
  3293. /*++
  3294. Routine name : FaxEnumOutboundRulesW
  3295. Routine description:
  3296. Enumerates all the outbound routing rules of a fax server.
  3297. Author:
  3298. Oded Sacher (OdedS), Dec, 1999
  3299. Arguments:
  3300. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3301. ppRules [out] - A pointer to a buffer of FAX_OUTBOUND_ROUTING_RULE structures.
  3302. This buffer is allocated by the function and the client should call FaxFreeBuffer to free it.
  3303. lpdwNumRules [out] - Pointer to a DWORD value indicating the number of rules retrieved.
  3304. Return Value:
  3305. TRUE - Success
  3306. FALSE - Failure, call GetLastError() for more error information.
  3307. --*/
  3308. {
  3309. error_status_t ec;
  3310. DWORD dwBufferSize = 0;
  3311. DWORD i;
  3312. DEBUG_FUNCTION_NAME(TEXT("FaxEnumOutboundRulesW"));
  3313. //
  3314. // Validate Parameters
  3315. //
  3316. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3317. {
  3318. SetLastError(ERROR_INVALID_HANDLE);
  3319. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() failed."));
  3320. return FALSE;
  3321. }
  3322. if (!ppRules)
  3323. {
  3324. SetLastError(ERROR_INVALID_PARAMETER);
  3325. DebugPrintEx(DEBUG_ERR, _T("ppRules is NULL"));
  3326. return FALSE;
  3327. }
  3328. if (!lpdwNumRules)
  3329. {
  3330. SetLastError(ERROR_INVALID_PARAMETER);
  3331. DebugPrintEx(DEBUG_ERR, _T("lpdwNumRules is NULL."));
  3332. return FALSE;
  3333. }
  3334. *ppRules = NULL;
  3335. *lpdwNumRules = 0;
  3336. __try
  3337. {
  3338. ec = FAX_EnumOutboundRules( FH_FAX_HANDLE(hFaxHandle),
  3339. (LPBYTE*) ppRules,
  3340. &dwBufferSize,
  3341. lpdwNumRules
  3342. );
  3343. }
  3344. __except (EXCEPTION_EXECUTE_HANDLER)
  3345. {
  3346. //
  3347. // For some reason we got an exception.
  3348. //
  3349. ec = GetExceptionCode();
  3350. DebugPrintEx(
  3351. DEBUG_ERR,
  3352. TEXT("Exception on RPC call to FAX_EnumOutboundRules. (ec: %ld)"),
  3353. ec);
  3354. }
  3355. if (ERROR_SUCCESS != ec)
  3356. {
  3357. DumpRPCExtendedStatus();
  3358. SetLastError(ec);
  3359. return FALSE;
  3360. }
  3361. //
  3362. // Unpack buffer
  3363. //
  3364. for (i = 0; i < *lpdwNumRules; i++)
  3365. {
  3366. if (TRUE == (*ppRules)[i].bUseGroup)
  3367. {
  3368. FixupStringPtrW( ppRules, (*ppRules)[i].Destination.lpcstrGroupName );
  3369. }
  3370. FixupStringPtrW( ppRules, (*ppRules)[i].lpctstrCountryName);
  3371. }
  3372. return TRUE;
  3373. } // FaxEnumOutboundRulesW
  3374. #ifndef UNICODE
  3375. BOOL
  3376. WINAPI
  3377. FaxEnumOutboundRulesX (
  3378. IN HANDLE hFaxHandle,
  3379. OUT PFAX_OUTBOUND_ROUTING_RULEW *ppRules,
  3380. OUT LPDWORD lpdwNumRules
  3381. )
  3382. {
  3383. UNREFERENCED_PARAMETER (hFaxHandle);
  3384. UNREFERENCED_PARAMETER (ppRules);
  3385. UNREFERENCED_PARAMETER (lpdwNumRules);
  3386. return FALSE;
  3387. } // FaxEnumOutboundRulesX
  3388. #endif // #ifndef UNICODE
  3389. BOOL
  3390. WINAPI
  3391. FaxSetOutboundRuleA (
  3392. IN HANDLE hFaxHandle,
  3393. IN PFAX_OUTBOUND_ROUTING_RULEA pRule
  3394. )
  3395. {
  3396. FAX_OUTBOUND_ROUTING_RULEW RuleW;
  3397. BOOL bRes;
  3398. DEBUG_FUNCTION_NAME(TEXT("FaxSetOutboundRuleA"));
  3399. //
  3400. // Validate Parameters
  3401. //
  3402. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE)) {
  3403. SetLastError(ERROR_INVALID_HANDLE);
  3404. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3405. return FALSE;
  3406. }
  3407. if (!pRule) {
  3408. SetLastError(ERROR_INVALID_PARAMETER);
  3409. DebugPrintEx(DEBUG_ERR, _T("pRule is NULL."));
  3410. return FALSE;
  3411. }
  3412. if (pRule->dwSizeOfStruct != sizeof(FAX_OUTBOUND_ROUTING_RULEA)) {
  3413. SetLastError(ERROR_INVALID_PARAMETER);
  3414. DebugPrintEx(DEBUG_ERR, _T("pRule->dwSizeOfStruct != sizeof(FAX_OUTBOUND_ROUTING_RULEA)."));
  3415. return FALSE;
  3416. }
  3417. //
  3418. // Create a UNICODE structure and pass along to UNICODE function
  3419. // Ansi structure is same size as unicode structure, so we can just copy it, then
  3420. // cast the string pointers correctly
  3421. //
  3422. CopyMemory(&RuleW, pRule, sizeof(FAX_OUTBOUND_ROUTING_RULEA));
  3423. RuleW.dwSizeOfStruct = sizeof (FAX_OUTBOUND_ROUTING_RULEW);
  3424. if (TRUE == pRule->bUseGroup)
  3425. {
  3426. if (!(pRule->Destination).lpcstrGroupName)
  3427. {
  3428. DebugPrintEx(DEBUG_ERR, _T("lpcstrGroupName is NULL"));
  3429. SetLastError(ERROR_INVALID_PARAMETER);
  3430. return FALSE;
  3431. }
  3432. if (NULL == (RuleW.Destination.lpcstrGroupName =
  3433. AnsiStringToUnicodeString((pRule->Destination).lpcstrGroupName)))
  3434. {
  3435. DebugPrintEx(DEBUG_ERR, _T("AnsiStringToUnicodeString failed. (ec: %ld)"), GetLastError());
  3436. return FALSE;
  3437. }
  3438. }
  3439. bRes = FaxSetOutboundRuleW (hFaxHandle, &RuleW);
  3440. if (TRUE == pRule->bUseGroup)
  3441. {
  3442. MemFree ((void*)(RuleW.Destination.lpcstrGroupName));
  3443. }
  3444. return bRes;
  3445. } // FaxSetOutboundRuleA
  3446. BOOL
  3447. WINAPI
  3448. FaxSetOutboundRuleW (
  3449. IN HANDLE hFaxHandle,
  3450. IN PFAX_OUTBOUND_ROUTING_RULEW pRule
  3451. )
  3452. /*++
  3453. Routine name : FaxSetOutboundRuleW
  3454. Routine description:
  3455. Sets an outbound routing rule settings for a fax server.
  3456. Author:
  3457. Oded Sacher (OdedS), Dec, 1999
  3458. Arguments:
  3459. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3460. pRule [in] - A pointer to a FAX_OUTBOUND_ROUTING_RULE buffer to set.
  3461. Return Value:
  3462. TRUE - Success
  3463. FALSE - Failure, call GetLastError() for more error information.
  3464. --*/
  3465. {
  3466. error_status_t ec;
  3467. FAX_OUTBOUND_ROUTING_RULEW Rule;
  3468. DEBUG_FUNCTION_NAME(TEXT("FaxSetOutboundRuleW"));
  3469. //
  3470. // Validate Parameters
  3471. //
  3472. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3473. {
  3474. SetLastError(ERROR_INVALID_HANDLE);
  3475. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3476. return FALSE;
  3477. }
  3478. if (!pRule)
  3479. {
  3480. SetLastError(ERROR_INVALID_PARAMETER);
  3481. DebugPrintEx(DEBUG_ERR, _T("pRule is NULL."));
  3482. return FALSE;
  3483. }
  3484. if (pRule->dwSizeOfStruct != sizeof(FAX_OUTBOUND_ROUTING_RULEW))
  3485. {
  3486. SetLastError(ERROR_INVALID_PARAMETER);
  3487. DebugPrintEx(DEBUG_ERR, _T("pRule->dwSizeOfStruct != sizeof(FAX_OUTBOUND_ROUTING_RULEW)."));
  3488. return FALSE;
  3489. }
  3490. if (pRule->dwCountryCode == ROUTING_RULE_COUNTRY_CODE_ANY &&
  3491. pRule->dwAreaCode != ROUTING_RULE_AREA_CODE_ANY)
  3492. {
  3493. //
  3494. // *.AreaCode is not a valid rule dialing location.
  3495. //
  3496. DebugPrintEx(DEBUG_ERR,
  3497. _T("dwCountryCode = 0 , dwAreaCode != 0; *.AreaCode is not a valid rule dialing location"));
  3498. SetLastError(ERROR_INVALID_PARAMETER);
  3499. return FALSE;
  3500. }
  3501. if (TRUE == pRule->bUseGroup)
  3502. {
  3503. if (!(pRule->Destination).lpcstrGroupName)
  3504. {
  3505. DebugPrintEx(DEBUG_ERR, _T("lpcstrGroupName is NULL"));
  3506. SetLastError(ERROR_INVALID_PARAMETER);
  3507. return FALSE;
  3508. }
  3509. if (wcslen ((pRule->Destination).lpcstrGroupName) >= MAX_ROUTING_GROUP_NAME)
  3510. {
  3511. DebugPrintEx(DEBUG_ERR, _T("Group name length exceeded MAX_ROUTING_GROUP_NAME"));
  3512. SetLastError(ERROR_BUFFER_OVERFLOW);
  3513. return FALSE;
  3514. }
  3515. }
  3516. else
  3517. {
  3518. if (!(pRule->Destination).dwDeviceId)
  3519. {
  3520. DebugPrintEx(DEBUG_ERR, _T("dwDeviceId = 0; Not a valid device ID"));
  3521. SetLastError(ERROR_INVALID_PARAMETER);
  3522. return FALSE;
  3523. }
  3524. }
  3525. //
  3526. // Zero the country name parameter of the rule before calling the RPC function.
  3527. // This parameter is out only but the RPC client will try to marshal it if we don't NULL it.
  3528. // This should be done in the IDL but due to backwards compatability issues with BOS Fax, we can't change that.
  3529. //
  3530. Rule = *pRule;
  3531. Rule.lpctstrCountryName = NULL;
  3532. __try
  3533. {
  3534. ec = FAX_SetOutboundRule( FH_FAX_HANDLE(hFaxHandle),
  3535. (PRPC_FAX_OUTBOUND_ROUTING_RULEW)&Rule);
  3536. }
  3537. __except (EXCEPTION_EXECUTE_HANDLER)
  3538. {
  3539. //
  3540. // For some reason we got an exception.
  3541. //
  3542. ec = GetExceptionCode();
  3543. DebugPrintEx(
  3544. DEBUG_ERR,
  3545. TEXT("Exception on RPC call to FAX_SetOutboundRule. (ec: %ld)"),
  3546. ec);
  3547. }
  3548. if (ERROR_SUCCESS != ec)
  3549. {
  3550. DumpRPCExtendedStatus();
  3551. SetLastError(ec);
  3552. return FALSE;
  3553. }
  3554. return TRUE;
  3555. } // FaxSetOutboundRuleW
  3556. #ifndef UNICODE
  3557. BOOL
  3558. WINAPI
  3559. FaxSetOutboundRuleX (
  3560. IN HANDLE hFaxHandle,
  3561. IN PFAX_OUTBOUND_ROUTING_RULEW pRule
  3562. )
  3563. {
  3564. UNREFERENCED_PARAMETER (hFaxHandle);
  3565. UNREFERENCED_PARAMETER (pRule);
  3566. return FALSE;
  3567. } // FaxSetOutboundRuleX
  3568. #endif // #ifndef UNICODE
  3569. BOOL
  3570. WINAPI
  3571. FaxGetServerActivity (
  3572. IN HANDLE hFaxHandle,
  3573. OUT PFAX_SERVER_ACTIVITY pServerActivity
  3574. )
  3575. /*++
  3576. Routine name : FaxGetServerActivity
  3577. Routine description:
  3578. Retrieves the status of the fax server queue activity and event log reports.
  3579. Author:
  3580. Oded Sacher (OdedS), Feb, 2000
  3581. Arguments:
  3582. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3583. pServerActivity [in] - A pointer to a FAX_SERVER_ACTIVITY object.
  3584. The object will be allocated and freed by the calling client.
  3585. Return Value:
  3586. TRUE - Success
  3587. FALSE - Failure, call GetLastError() for more error information.
  3588. --*/
  3589. {
  3590. error_status_t ec;
  3591. DEBUG_FUNCTION_NAME(TEXT("FaxGetServerActivity"));
  3592. //
  3593. // Validate Parameters
  3594. //
  3595. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3596. {
  3597. SetLastError(ERROR_INVALID_HANDLE);
  3598. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3599. return FALSE;
  3600. }
  3601. if (!pServerActivity)
  3602. {
  3603. SetLastError(ERROR_INVALID_PARAMETER);
  3604. DebugPrintEx(DEBUG_ERR, _T("pServerActivity is NULL."));
  3605. return FALSE;
  3606. }
  3607. if (sizeof (FAX_SERVER_ACTIVITY) != pServerActivity->dwSizeOfStruct)
  3608. {
  3609. SetLastError(ERROR_INVALID_PARAMETER);
  3610. DebugPrintEx(DEBUG_ERR, _T("sizeof (FAX_SERVER_ACTIVITY) != pServerActivity->dwSizeOfStruct."));
  3611. return FALSE;
  3612. }
  3613. __try
  3614. {
  3615. ec = FAX_GetServerActivity( FH_FAX_HANDLE(hFaxHandle),
  3616. pServerActivity);
  3617. }
  3618. __except (EXCEPTION_EXECUTE_HANDLER)
  3619. {
  3620. //
  3621. // For some reason we got an exception.
  3622. //
  3623. ec = GetExceptionCode();
  3624. DebugPrintEx(
  3625. DEBUG_ERR,
  3626. TEXT("Exception on RPC call to FAX_GetServerActivity. (ec: %ld)"),
  3627. ec);
  3628. }
  3629. if (ERROR_SUCCESS != ec)
  3630. {
  3631. DumpRPCExtendedStatus();
  3632. SetLastError(ec);
  3633. return FALSE;
  3634. }
  3635. return TRUE;
  3636. } // FaxGetServerActivity
  3637. BOOL
  3638. WINAPI
  3639. FaxGetReceiptsOptions (
  3640. IN HANDLE hFaxHandle,
  3641. OUT PDWORD pdwReceiptsOptions
  3642. )
  3643. /*++
  3644. Routine name : FaxGetReceiptsOptions
  3645. Routine description:
  3646. Retrieves the supported receipt options on the server.
  3647. Author:
  3648. Eran Yariv (EranY), July, 2000
  3649. Arguments:
  3650. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3651. pdwReceiptsOptions [out] - Buffer to receive receipts options (bit-wise combination of DRT_* constants)
  3652. Return Value:
  3653. TRUE - Success
  3654. FALSE - Failure, call GetLastError() for more error information.
  3655. --*/
  3656. {
  3657. error_status_t ec;
  3658. DEBUG_FUNCTION_NAME(TEXT("FaxGetReceiptsOptions"));
  3659. //
  3660. // Validate Parameters
  3661. //
  3662. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3663. {
  3664. SetLastError(ERROR_INVALID_HANDLE);
  3665. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3666. return FALSE;
  3667. }
  3668. if (!pdwReceiptsOptions)
  3669. {
  3670. DebugPrintEx(DEBUG_ERR, _T("pdwReceiptsOptions is NULL"));
  3671. SetLastError(ERROR_INVALID_PARAMETER);
  3672. return FALSE;
  3673. }
  3674. __try
  3675. {
  3676. ec = FAX_GetReceiptsOptions( FH_FAX_HANDLE(hFaxHandle),
  3677. pdwReceiptsOptions);
  3678. }
  3679. __except (EXCEPTION_EXECUTE_HANDLER)
  3680. {
  3681. //
  3682. // For some reason we got an exception.
  3683. //
  3684. ec = GetExceptionCode();
  3685. DebugPrintEx(
  3686. DEBUG_ERR,
  3687. TEXT("Exception on RPC call to FAX_GetReceiptsOptions. (ec: %ld)"),
  3688. ec);
  3689. }
  3690. if (ERROR_SUCCESS != ec)
  3691. {
  3692. DumpRPCExtendedStatus();
  3693. SetLastError(ec);
  3694. return FALSE;
  3695. }
  3696. return TRUE;
  3697. } // FaxGetReceiptsOptions
  3698. BOOL
  3699. WINAPI
  3700. FaxGetPersonalCoverPagesOption (
  3701. IN HANDLE hFaxHandle,
  3702. OUT LPBOOL lpbPersonalCPAllowed
  3703. )
  3704. /*++
  3705. Routine name : FaxGetPersonalCoverPagesOption
  3706. Routine description:
  3707. Retrieves if the server supports personal cover pages
  3708. Author:
  3709. Eran Yariv (EranY), July, 2000
  3710. Arguments:
  3711. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3712. lpbPersonalCPAllowed [out] - Buffer to receive server support of personal coverpages.
  3713. Return Value:
  3714. TRUE - Success
  3715. FALSE - Failure, call GetLastError() for more error information.
  3716. --*/
  3717. {
  3718. error_status_t ec;
  3719. DEBUG_FUNCTION_NAME(TEXT("FaxGetPersonalCoverPagesOption"));
  3720. //
  3721. // Validate Parameters
  3722. //
  3723. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3724. {
  3725. SetLastError(ERROR_INVALID_HANDLE);
  3726. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3727. return FALSE;
  3728. }
  3729. if (!lpbPersonalCPAllowed)
  3730. {
  3731. SetLastError(ERROR_INVALID_PARAMETER);
  3732. DebugPrintEx(DEBUG_ERR, _T("lpbPersonalCPAllowed is NULL"));
  3733. return FALSE;
  3734. }
  3735. __try
  3736. {
  3737. ec = FAX_GetPersonalCoverPagesOption( FH_FAX_HANDLE(hFaxHandle),
  3738. lpbPersonalCPAllowed);
  3739. }
  3740. __except (EXCEPTION_EXECUTE_HANDLER)
  3741. {
  3742. //
  3743. // For some reason we got an exception.
  3744. //
  3745. ec = GetExceptionCode();
  3746. DebugPrintEx(
  3747. DEBUG_ERR,
  3748. TEXT("Exception on RPC call to FAX_GetPersonalCoverPagesOption. (ec: %ld)"),
  3749. ec);
  3750. }
  3751. if (ERROR_SUCCESS != ec)
  3752. {
  3753. DumpRPCExtendedStatus();
  3754. SetLastError(ec);
  3755. return FALSE;
  3756. }
  3757. return TRUE;
  3758. } // FaxGetPersonalCoverPagesOption
  3759. BOOL
  3760. WINAPI
  3761. FaxGetConfigWizardUsed (
  3762. OUT LPBOOL lpbConfigWizardUsed
  3763. )
  3764. /*++
  3765. Routine name : FaxGetConfigWizardUsed
  3766. Routine description:
  3767. Retrieves if the configuration wizard (devices) was run on the server.
  3768. Author:
  3769. Eran Yariv (EranY), July, 2000
  3770. Arguments:
  3771. lpbConfigWizardUsed [out] - Buffer to receive config wizard usage flag.
  3772. Return Value:
  3773. TRUE - Success
  3774. FALSE - Failure, call GetLastError() for more error information.
  3775. --*/
  3776. {
  3777. DWORD dwRes = ERROR_SUCCESS;
  3778. DWORD dwRes2;
  3779. HKEY hKey;
  3780. DEBUG_FUNCTION_NAME(TEXT("FaxGetConfigWizardUsed"));
  3781. if (!lpbConfigWizardUsed)
  3782. {
  3783. DebugPrintEx(DEBUG_ERR, _T("lpbConfigWizardUsed is NULL"));
  3784. SetLastError(ERROR_INVALID_PARAMETER);
  3785. return FALSE;
  3786. }
  3787. dwRes = RegOpenKeyEx (HKEY_LOCAL_MACHINE, REGKEY_FAX_CLIENT, 0, KEY_READ, &hKey);
  3788. if (ERROR_SUCCESS != dwRes)
  3789. {
  3790. DebugPrintEx(
  3791. DEBUG_ERR,
  3792. TEXT("Error opening server key (ec = %ld)"),
  3793. dwRes);
  3794. goto exit;
  3795. }
  3796. *lpbConfigWizardUsed = GetRegistryDword (hKey, REGVAL_CFGWZRD_DEVICE);
  3797. dwRes2 = RegCloseKey (hKey);
  3798. if (ERROR_SUCCESS != dwRes2)
  3799. {
  3800. DebugPrintEx(
  3801. DEBUG_ERR,
  3802. TEXT("Error closing server key (ec = %ld)"),
  3803. dwRes2);
  3804. }
  3805. Assert (ERROR_SUCCESS == dwRes);
  3806. exit:
  3807. if (ERROR_SUCCESS != dwRes)
  3808. {
  3809. SetLastError(dwRes);
  3810. return FALSE;
  3811. }
  3812. return TRUE;
  3813. } // FaxGetConfigWizardUsed
  3814. BOOL
  3815. WINAPI
  3816. FaxSetConfigWizardUsed (
  3817. IN HANDLE hFaxHandle,
  3818. IN BOOL bConfigWizardUsed
  3819. )
  3820. /*++
  3821. Routine name : FaxSetConfigWizardUsed
  3822. Routine description:
  3823. Sets if the configuration wizard (devices) was run on the server.
  3824. Author:
  3825. Eran Yariv (EranY), July, 2000
  3826. Arguments:
  3827. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  3828. bConfigWizardUsed [in] - Was the configuration wizard used?
  3829. Return Value:
  3830. TRUE - Success
  3831. FALSE - Failure, call GetLastError() for more error information.
  3832. --*/
  3833. {
  3834. error_status_t ec;
  3835. DEBUG_FUNCTION_NAME(TEXT("FaxSetConfigWizardUsed"));
  3836. //
  3837. // Validate Parameters
  3838. //
  3839. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3840. {
  3841. SetLastError(ERROR_INVALID_HANDLE);
  3842. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3843. return FALSE;
  3844. }
  3845. if (!IsLocalFaxConnection(hFaxHandle))
  3846. {
  3847. DebugPrintEx(DEBUG_ERR, _T("Not a local fax connection"));
  3848. SetLastError(ERROR_INVALID_HANDLE);
  3849. return FALSE;
  3850. }
  3851. if (FAX_API_VERSION_1 > FH_SERVER_VER(hFaxHandle))
  3852. {
  3853. //
  3854. // Servers of API version 0 don't support FAX_SetConfigWizardUsed
  3855. //
  3856. ASSERT_FALSE; // Can't happen - if it's local
  3857. DebugPrintEx(DEBUG_ERR,
  3858. _T("Server version is %ld - doesn't support this call"),
  3859. FH_SERVER_VER(hFaxHandle));
  3860. SetLastError(FAX_ERR_VERSION_MISMATCH);
  3861. return FALSE;
  3862. }
  3863. __try
  3864. {
  3865. ec = FAX_SetConfigWizardUsed( FH_FAX_HANDLE(hFaxHandle),
  3866. bConfigWizardUsed);
  3867. }
  3868. __except (EXCEPTION_EXECUTE_HANDLER)
  3869. {
  3870. //
  3871. // For some reason we got an exception.
  3872. //
  3873. ec = GetExceptionCode();
  3874. DebugPrintEx(
  3875. DEBUG_ERR,
  3876. TEXT("Exception on RPC call to FAX_SetConfigWizardUsed. (ec: %ld)"),
  3877. ec);
  3878. }
  3879. if (ERROR_SUCCESS != ec)
  3880. {
  3881. DumpRPCExtendedStatus();
  3882. SetLastError(ec);
  3883. return FALSE;
  3884. }
  3885. return TRUE;
  3886. } // FaxSetConfigWizardUsed
  3887. //********************************************
  3888. //* Routing extensions
  3889. //********************************************
  3890. BOOL
  3891. WINAPI
  3892. FaxEnumRoutingExtensionsA (
  3893. IN HANDLE hFaxHandle,
  3894. OUT PFAX_ROUTING_EXTENSION_INFOA *ppExts,
  3895. OUT LPDWORD lpdwNumExts
  3896. )
  3897. /*++
  3898. Routine name : FaxEnumRoutingExtensionsA
  3899. Routine description:
  3900. Enumerates routing extensions - ANSI version
  3901. Author:
  3902. Eran Yariv (EranY), July, 2000
  3903. Arguments:
  3904. hFaxHandle [in ] - Handle to fax server
  3905. ppExts [out] - Pointer to buffer to return array of extensions.
  3906. lpdwNumExts [out] - Number of extensions returned in the array.
  3907. Return Value:
  3908. TRUE - Success
  3909. FALSE - Failure, call GetLastError() for more error information.
  3910. --*/
  3911. {
  3912. PFAX_ROUTING_EXTENSION_INFOW pUnicodeExts;
  3913. DWORD dwNumExts;
  3914. DWORD dwCur;
  3915. DEBUG_FUNCTION_NAME(TEXT("FaxEnumRoutingExtensionsA"));
  3916. //
  3917. // Validate Parameters
  3918. //
  3919. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3920. {
  3921. SetLastError(ERROR_INVALID_HANDLE);
  3922. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3923. return FALSE;
  3924. }
  3925. if (!ppExts)
  3926. {
  3927. SetLastError(ERROR_INVALID_PARAMETER);
  3928. DebugPrintEx(DEBUG_ERR, _T("ppExts is NULL."));
  3929. return FALSE;
  3930. }
  3931. if (!lpdwNumExts)
  3932. {
  3933. SetLastError(ERROR_INVALID_PARAMETER);
  3934. DebugPrintEx(DEBUG_ERR, _T("pdwNumExts is NULL."));
  3935. return FALSE;
  3936. }
  3937. //
  3938. // Call the UNICODE version first
  3939. //
  3940. if (!FaxEnumRoutingExtensionsW (hFaxHandle, &pUnicodeExts, &dwNumExts))
  3941. {
  3942. DebugPrintEx(DEBUG_ERR, _T("FaxEnumRoutingExtensionsW() is failed. ec = %ld."), GetLastError());
  3943. return FALSE;
  3944. }
  3945. //
  3946. // Convert returned value back into ANSI.
  3947. // We keep the UNICODE structures and do a UNICODE to ANSI convert in place.
  3948. //
  3949. *lpdwNumExts = dwNumExts;
  3950. *ppExts = (PFAX_ROUTING_EXTENSION_INFOA) pUnicodeExts;
  3951. for (dwCur = 0; dwCur < dwNumExts; dwCur++)
  3952. {
  3953. if (!ConvertUnicodeStringInPlace(pUnicodeExts[dwCur].lpctstrFriendlyName) ||
  3954. !ConvertUnicodeStringInPlace(pUnicodeExts[dwCur].lpctstrImageName) ||
  3955. !ConvertUnicodeStringInPlace(pUnicodeExts[dwCur].lpctstrExtensionName))
  3956. {
  3957. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  3958. MemFree (pUnicodeExts);
  3959. return FALSE;
  3960. }
  3961. }
  3962. return TRUE;
  3963. } // FaxEnumRoutingExtensionsA
  3964. BOOL
  3965. WINAPI
  3966. FaxEnumRoutingExtensionsW (
  3967. IN HANDLE hFaxHandle,
  3968. OUT PFAX_ROUTING_EXTENSION_INFOW *ppExts,
  3969. OUT LPDWORD lpdwNumExts
  3970. )
  3971. /*++
  3972. Routine name : FaxEnumRoutingExtensionsW
  3973. Routine description:
  3974. Enumerates routing extensions - UNICODE version
  3975. Author:
  3976. Eran Yariv (EranY), July, 2000
  3977. Arguments:
  3978. hFaxHandle [in ] - Handle to fax server
  3979. ppExts [out] - Pointer to buffer to return array of extensions.
  3980. lpdwNumExts [out] - Number of extensions returned in the array.
  3981. Return Value:
  3982. TRUE - Success
  3983. FALSE - Failure, call GetLastError() for more error information.
  3984. --*/
  3985. {
  3986. DWORD ec = ERROR_SUCCESS;
  3987. DWORD dwConfigSize;
  3988. DWORD dwCur;
  3989. DEBUG_FUNCTION_NAME(TEXT("FaxEnumRoutingExtensionsW"));
  3990. //
  3991. // Validate Parameters
  3992. //
  3993. if (!ValidateFaxHandle(hFaxHandle,FHT_SERVICE))
  3994. {
  3995. SetLastError(ERROR_INVALID_HANDLE);
  3996. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  3997. return FALSE;
  3998. }
  3999. if (!ppExts)
  4000. {
  4001. SetLastError(ERROR_INVALID_PARAMETER);
  4002. DebugPrintEx(DEBUG_ERR, _T("ppExts is NULL."));
  4003. return FALSE;
  4004. }
  4005. if (!lpdwNumExts)
  4006. {
  4007. SetLastError(ERROR_INVALID_PARAMETER);
  4008. DebugPrintEx(DEBUG_ERR, _T("pdwNumExts is NULL."));
  4009. return FALSE;
  4010. }
  4011. *ppExts = NULL;
  4012. if (FAX_API_VERSION_1 > FH_SERVER_VER(hFaxHandle))
  4013. {
  4014. //
  4015. // Servers of API version 0 don't support FAX_EnumRoutingExtensions
  4016. // We'll fake it and return an empty list.
  4017. //
  4018. DebugPrintEx(DEBUG_MSG,
  4019. _T("Server version is %ld - doesn't support this call"),
  4020. FH_SERVER_VER(hFaxHandle));
  4021. SetLastError(FAX_ERR_VERSION_MISMATCH);
  4022. return FALSE;
  4023. }
  4024. //
  4025. // Call the RPC function
  4026. //
  4027. __try
  4028. {
  4029. ec = FAX_EnumRoutingExtensions(
  4030. FH_FAX_HANDLE(hFaxHandle),
  4031. (LPBYTE*)ppExts,
  4032. &dwConfigSize,
  4033. lpdwNumExts
  4034. );
  4035. }
  4036. __except (EXCEPTION_EXECUTE_HANDLER)
  4037. {
  4038. //
  4039. // For some reason we got an exception.
  4040. //
  4041. ec = GetExceptionCode();
  4042. DebugPrintEx(
  4043. DEBUG_ERR,
  4044. TEXT("Exception on RPC call to FAX_EnumRoutingExtensions. (ec: %ld)"),
  4045. ec);
  4046. }
  4047. if (ERROR_SUCCESS != ec)
  4048. {
  4049. DumpRPCExtendedStatus();
  4050. SetLastError(ec);
  4051. return FALSE;
  4052. }
  4053. for (dwCur = 0; dwCur < (*lpdwNumExts); dwCur++)
  4054. {
  4055. FixupStringPtrW( ppExts, (*ppExts)[dwCur].lpctstrFriendlyName );
  4056. FixupStringPtrW( ppExts, (*ppExts)[dwCur].lpctstrImageName );
  4057. FixupStringPtrW( ppExts, (*ppExts)[dwCur].lpctstrExtensionName );
  4058. }
  4059. return TRUE;
  4060. } // FaxEnumRoutingExtensionsW
  4061. #ifndef UNICODE
  4062. BOOL
  4063. WINAPI
  4064. FaxEnumRoutingExtensionsX (
  4065. IN HANDLE hFaxHandle,
  4066. OUT PFAX_ROUTING_EXTENSION_INFOW *ppExts,
  4067. OUT LPDWORD lpdwNumExts
  4068. )
  4069. {
  4070. UNREFERENCED_PARAMETER (hFaxHandle);
  4071. UNREFERENCED_PARAMETER (ppExts);
  4072. UNREFERENCED_PARAMETER (lpdwNumExts);
  4073. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  4074. return FALSE;
  4075. } // FaxEnumRoutingExtensionsX
  4076. #endif // #ifndef UNICODE
  4077. WINFAXAPI
  4078. BOOL
  4079. WINAPI
  4080. FaxGetServicePrintersA(
  4081. IN HANDLE hFaxHandle,
  4082. OUT PFAX_PRINTER_INFOA *ppPrinterInfo,
  4083. OUT LPDWORD lpdwPrintersReturned
  4084. )
  4085. /*++
  4086. Routine name : FaxGetServicePrintersA
  4087. Routine description:
  4088. Retrieves Information about Printers that are known by the Service
  4089. Author:
  4090. Iv Garber (IvG), August, 2000
  4091. Arguments:
  4092. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  4093. pPrinterInfo [out] - Buffer to receive the Printers Info
  4094. PrintersReturned[out] - Count of the Printers Info structures returned
  4095. Return Value:
  4096. TRUE - Success
  4097. FALSE - Failure, call GetLastError() for more error information.
  4098. --*/
  4099. {
  4100. DEBUG_FUNCTION_NAME(TEXT("FaxGetServicePrintersA"));
  4101. //
  4102. // no need to validate parameters, FaxGetServicePrintersW() will do that
  4103. //
  4104. if (!FaxGetServicePrintersW(hFaxHandle,
  4105. (PFAX_PRINTER_INFOW *)ppPrinterInfo,
  4106. lpdwPrintersReturned))
  4107. {
  4108. DebugPrintEx(DEBUG_ERR, _T("FaxGetServicePrintersW() failed. (ec: %ld)"), GetLastError());
  4109. return FALSE;
  4110. }
  4111. DWORD i;
  4112. for ( i = 0 ; i < (*lpdwPrintersReturned) ; i++ )
  4113. {
  4114. if (!ConvertUnicodeStringInPlace((LPWSTR) (*ppPrinterInfo)[i].lptstrPrinterName) ||
  4115. !ConvertUnicodeStringInPlace((LPWSTR) (*ppPrinterInfo)[i].lptstrDriverName) ||
  4116. !ConvertUnicodeStringInPlace((LPWSTR) (*ppPrinterInfo)[i].lptstrServerName))
  4117. {
  4118. DebugPrintEx(DEBUG_ERR, _T("ConvertUnicodeStringInPlace failed, ec = %ld."), GetLastError());
  4119. MemFree (*ppPrinterInfo);
  4120. return FALSE;
  4121. }
  4122. }
  4123. return TRUE;
  4124. } // FaxGetServicePrintersA
  4125. WINFAXAPI
  4126. BOOL
  4127. WINAPI
  4128. FaxGetServicePrintersW(
  4129. IN HANDLE hFaxHandle,
  4130. OUT PFAX_PRINTER_INFOW *ppPrinterInfo,
  4131. OUT LPDWORD lpdwPrintersReturned
  4132. )
  4133. /*++
  4134. Routine name : FaxGetServicePrintersW
  4135. Routine description:
  4136. Retrieves Information about Printers that are known by the Service
  4137. Author:
  4138. Iv Garber (IvG), August, 2000
  4139. Arguments:
  4140. hFaxHandle [in] - Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
  4141. pPrinterInfo [out] - Buffer to receive the Printers Info
  4142. PrintersReturned[out] - Count of the Printers Info structures returned
  4143. Return Value:
  4144. TRUE - Success
  4145. FALSE - Failure, call GetLastError() for more error information.
  4146. --*/
  4147. {
  4148. DEBUG_FUNCTION_NAME(TEXT("FaxGetServicePrintersW"));
  4149. //
  4150. // Validate Parameters
  4151. //
  4152. if (!ValidateFaxHandle(hFaxHandle, FHT_SERVICE))
  4153. {
  4154. SetLastError(ERROR_INVALID_HANDLE);
  4155. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() is failed."));
  4156. return FALSE;
  4157. }
  4158. if (!ppPrinterInfo)
  4159. {
  4160. SetLastError(ERROR_INVALID_PARAMETER);
  4161. DebugPrintEx(DEBUG_ERR, _T("ppPrinterInfo is NULL."));
  4162. return FALSE;
  4163. }
  4164. if (!lpdwPrintersReturned)
  4165. {
  4166. SetLastError(ERROR_INVALID_PARAMETER);
  4167. DebugPrintEx(DEBUG_ERR, _T("lpdwPrintersReturned is NULL."));
  4168. return FALSE;
  4169. }
  4170. error_status_t ec;
  4171. DWORD dwBufferSize = 0;
  4172. *ppPrinterInfo = NULL;
  4173. *lpdwPrintersReturned = 0;
  4174. __try
  4175. {
  4176. ec = FAX_GetServicePrinters(FH_FAX_HANDLE(hFaxHandle),
  4177. (LPBYTE *)ppPrinterInfo,
  4178. &dwBufferSize,
  4179. lpdwPrintersReturned);
  4180. }
  4181. __except (EXCEPTION_EXECUTE_HANDLER)
  4182. {
  4183. //
  4184. // For some reason we got an exception.
  4185. //
  4186. ec = GetExceptionCode();
  4187. DebugPrintEx(DEBUG_ERR, _T("Exception on RPC call to FAX_GetServicePrinters. (ec: %ld)"), ec);
  4188. }
  4189. if (ERROR_SUCCESS != ec)
  4190. {
  4191. DumpRPCExtendedStatus();
  4192. SetLastError(ec);
  4193. return FALSE;
  4194. }
  4195. PFAX_PRINTER_INFOW pPrinter = (PFAX_PRINTER_INFOW) (*ppPrinterInfo);
  4196. for ( DWORD i = 0; i < (*lpdwPrintersReturned) ; i++ )
  4197. {
  4198. FixupStringPtrW( ppPrinterInfo, pPrinter[i].lptstrPrinterName);
  4199. FixupStringPtrW( ppPrinterInfo, pPrinter[i].lptstrDriverName);
  4200. FixupStringPtrW( ppPrinterInfo, pPrinter[i].lptstrServerName);
  4201. }
  4202. return TRUE;
  4203. }
  4204. #ifndef UNICODE
  4205. WINFAXAPI
  4206. BOOL
  4207. WINAPI
  4208. FaxGetServicePrintersX(
  4209. IN HANDLE hFaxHandle,
  4210. OUT PFAX_PRINTER_INFOW *pPrinterInfo,
  4211. OUT LPDWORD PrintersReturned
  4212. )
  4213. {
  4214. UNREFERENCED_PARAMETER (hFaxHandle);
  4215. UNREFERENCED_PARAMETER (pPrinterInfo);
  4216. UNREFERENCED_PARAMETER (PrintersReturned);
  4217. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  4218. return FALSE;
  4219. } // FaxGetServicePrintersX
  4220. #endif // #ifndef UNICODE
  4221. //********************************************
  4222. //* Manual answer support
  4223. //********************************************
  4224. BOOL
  4225. WINAPI
  4226. FaxAnswerCall(
  4227. IN HANDLE hFaxHandle,
  4228. IN CONST DWORD dwDeviceId
  4229. )
  4230. /*++
  4231. Routine Description:
  4232. Tells the server to answer specified call
  4233. Arguments:
  4234. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  4235. dwDeviceId - TAPI Permanent Line Id (from event notification)
  4236. Return Value:
  4237. TRUE - Success
  4238. FALSE - Failure, call GetLastError() for more error information.
  4239. --*/
  4240. {
  4241. error_status_t ec = ERROR_SUCCESS;
  4242. DEBUG_FUNCTION_NAME(TEXT("FaxAnswerCall"));
  4243. if (!ValidateFaxHandle(hFaxHandle, FHT_SERVICE))
  4244. {
  4245. SetLastError(ERROR_INVALID_HANDLE);
  4246. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() failed."));
  4247. return FALSE;
  4248. }
  4249. if (!IsLocalFaxConnection(hFaxHandle))
  4250. {
  4251. //
  4252. // Only local connections are allowed to do a FaxAnswerCall
  4253. //
  4254. DebugPrintEx(DEBUG_ERR, _T("Not a local fax connection"));
  4255. SetLastError(ERROR_INVALID_HANDLE);
  4256. return FALSE;
  4257. }
  4258. if (FAX_API_VERSION_1 > FH_SERVER_VER(hFaxHandle))
  4259. {
  4260. //
  4261. // Servers of API version 0 don't support FAX_AnswerCall
  4262. //
  4263. DebugPrintEx(DEBUG_ERR,
  4264. _T("Server version is %ld - doesn't support this call"),
  4265. FH_SERVER_VER(hFaxHandle));
  4266. SetLastError(FAX_ERR_VERSION_MISMATCH);
  4267. return FALSE;
  4268. }
  4269. __try
  4270. {
  4271. ec = FAX_AnswerCall (FH_FAX_HANDLE(hFaxHandle), dwDeviceId);
  4272. }
  4273. __except (EXCEPTION_EXECUTE_HANDLER)
  4274. {
  4275. //
  4276. // For some reason we got an exception.
  4277. //
  4278. ec = GetExceptionCode();
  4279. DebugPrintEx(
  4280. DEBUG_ERR,
  4281. TEXT("Exception on RPC call to FAX_AnswerCall (ec: %ld)"),
  4282. ec);
  4283. }
  4284. if (ERROR_SUCCESS != ec)
  4285. {
  4286. DumpRPCExtendedStatus();
  4287. DebugPrintEx(DEBUG_ERR, _T("FAX_AnswerCall failed. (ec: %ld)"), ec);
  4288. }
  4289. return (ERROR_SUCCESS == ec);
  4290. } // FaxAnswerCall
  4291. //********************************************
  4292. //* Ivalidate archive folder
  4293. //********************************************
  4294. WINFAXAPI
  4295. BOOL
  4296. WINAPI
  4297. FaxRefreshArchive (
  4298. IN HANDLE hFaxHandle,
  4299. IN FAX_ENUM_MESSAGE_FOLDER Folder
  4300. )
  4301. /*++
  4302. Routine Description:
  4303. Tells the server that the folder should be refreshed
  4304. Arguments:
  4305. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  4306. Folder - Archive folder ID
  4307. Return Value:
  4308. TRUE - Success
  4309. FALSE - Failure, call GetLastError() for more error information.
  4310. --*/
  4311. {
  4312. error_status_t ec = ERROR_SUCCESS;
  4313. DEBUG_FUNCTION_NAME(TEXT("FaxRefreshArchive"));
  4314. if (!ValidateFaxHandle(hFaxHandle, FHT_SERVICE))
  4315. {
  4316. SetLastError(ERROR_INVALID_HANDLE);
  4317. DebugPrintEx(DEBUG_ERR, _T("ValidateFaxHandle() failed."));
  4318. return FALSE;
  4319. }
  4320. if(Folder != FAX_MESSAGE_FOLDER_INBOX &&
  4321. Folder != FAX_MESSAGE_FOLDER_SENTITEMS)
  4322. {
  4323. SetLastError(ERROR_INVALID_PARAMETER);
  4324. DebugPrintEx(DEBUG_ERR, _T("Folder is invalid."));
  4325. return FALSE;
  4326. }
  4327. __try
  4328. {
  4329. ec = FAX_RefreshArchive (FH_FAX_HANDLE(hFaxHandle), Folder);
  4330. }
  4331. __except (EXCEPTION_EXECUTE_HANDLER)
  4332. {
  4333. //
  4334. // For some reason we got an exception.
  4335. //
  4336. ec = GetExceptionCode();
  4337. DebugPrintEx(
  4338. DEBUG_ERR,
  4339. TEXT("Exception on RPC call to FAX_RefreshArchive (ec: %ld)"),
  4340. ec);
  4341. }
  4342. if (ERROR_SUCCESS != ec)
  4343. {
  4344. DumpRPCExtendedStatus();
  4345. DebugPrintEx(DEBUG_ERR, _T("FAX_RefreshArchive failed. (ec: %ld)"), ec);
  4346. }
  4347. return (ERROR_SUCCESS == ec);
  4348. } // FaxRefreshArchive