Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1150 lines
26 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. print.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. BOOL
  15. WINAPI
  16. FaxGetConfigurationW(
  17. IN HANDLE FaxHandle,
  18. OUT PFAX_CONFIGURATIONW *FaxConfig
  19. )
  20. /*++
  21. Routine Description:
  22. Retrieves the FAX configuration from the FAX server.
  23. The SizeOfStruct in the FaxConfig argument MUST be
  24. set to a value=>= sizeof(FAX_CONFIGURATION).
  25. Arguments:
  26. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  27. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  28. Return Value:
  29. TRUE - Success
  30. FALSE - Failure, call GetLastError() for more error information.
  31. --*/
  32. {
  33. error_status_t ec;
  34. DWORD FaxConfigSize = 0;
  35. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  36. SetLastError(ERROR_INVALID_HANDLE);
  37. return FALSE;
  38. }
  39. if (!FaxConfig) {
  40. SetLastError( ERROR_INVALID_PARAMETER );
  41. return FALSE;
  42. }
  43. *FaxConfig = NULL;
  44. ec = FAX_GetConfiguration(
  45. FH_FAX_HANDLE(FaxHandle),
  46. (LPBYTE*)FaxConfig,
  47. &FaxConfigSize
  48. );
  49. if (ec) {
  50. SetLastError( ec );
  51. return FALSE;
  52. }
  53. FixupStringPtr( FaxConfig, (*FaxConfig)->ArchiveDirectory );
  54. FixupStringPtr( FaxConfig, (*FaxConfig)->InboundProfile );
  55. return TRUE;
  56. }
  57. BOOL
  58. WINAPI
  59. FaxGetConfigurationA(
  60. IN HANDLE FaxHandle,
  61. OUT PFAX_CONFIGURATIONA *FaxConfigA
  62. )
  63. /*++
  64. Routine Description:
  65. Retrieves the FAX configuration from the FAX server.
  66. The SizeOfStruct in the FaxConfig argument MUST be
  67. set to a value=>= sizeof(FAX_CONFIGURATION).
  68. Arguments:
  69. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  70. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  71. Return Value:
  72. TRUE - Success
  73. FALSE - Failure, call GetLastError() for more error information.
  74. --*/
  75. {
  76. if (!FaxGetConfigurationW(
  77. FaxHandle,
  78. (PFAX_CONFIGURATIONW*) FaxConfigA
  79. ))
  80. {
  81. return FALSE;
  82. }
  83. ConvertUnicodeStringInPlace( (LPWSTR) (*FaxConfigA)->ArchiveDirectory );
  84. ConvertUnicodeStringInPlace( (LPWSTR) (*FaxConfigA)->InboundProfile );
  85. return TRUE;
  86. }
  87. BOOL
  88. WINAPI
  89. FaxSetConfigurationW(
  90. IN HANDLE FaxHandle,
  91. IN const FAX_CONFIGURATIONW *FaxConfig
  92. )
  93. /*++
  94. Routine Description:
  95. Changes the FAX configuration on the FAX server.
  96. The SizeOfStruct in the FaxConfig argument MUST be
  97. set to a value == sizeof(FAX_CONFIGURATION).
  98. Arguments:
  99. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  100. FaxConfig - Pointer to a FAX_CONFIGURATION structure.
  101. Return Value:
  102. TRUE - Success
  103. FALSE - Failure, call GetLastError() for more error information.
  104. --*/
  105. {
  106. error_status_t ec;
  107. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  108. SetLastError(ERROR_INVALID_HANDLE);
  109. return FALSE;
  110. }
  111. if (!FaxConfig) {
  112. SetLastError(ERROR_INVALID_PARAMETER);
  113. return FALSE;
  114. }
  115. ec = FAX_SetConfiguration( FH_FAX_HANDLE(FaxHandle), FaxConfig );
  116. if (ec) {
  117. SetLastError( ec );
  118. return FALSE;
  119. }
  120. return TRUE;
  121. }
  122. BOOL
  123. WINAPI
  124. FaxSetConfigurationA(
  125. IN HANDLE FaxHandle,
  126. IN const FAX_CONFIGURATIONA *FaxConfig
  127. )
  128. {
  129. error_status_t ec;
  130. FAX_CONFIGURATIONW FaxConfigW;
  131. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  132. SetLastError(ERROR_INVALID_HANDLE);
  133. return FALSE;
  134. }
  135. if (!FaxConfig) {
  136. SetLastError(ERROR_INVALID_PARAMETER);
  137. return FALSE;
  138. }
  139. //
  140. // ansi structure is same size as unicode structure, so we can just copy it, then
  141. // cast the string pointers correctly
  142. //
  143. CopyMemory(&FaxConfigW,FaxConfig,sizeof(FAX_CONFIGURATIONA));
  144. if (FaxConfig->ArchiveDirectory) {
  145. FaxConfigW.ArchiveDirectory = AnsiStringToUnicodeString(FaxConfig->ArchiveDirectory);
  146. }
  147. if (FaxConfig->InboundProfile) {
  148. FaxConfigW.InboundProfile = AnsiStringToUnicodeString(FaxConfig->InboundProfile);
  149. }
  150. ec = FAX_SetConfiguration( FH_FAX_HANDLE(FaxHandle), (PFAX_CONFIGURATIONW)&FaxConfigW );
  151. if (FaxConfigW.ArchiveDirectory) {
  152. MemFree((PVOID)FaxConfigW.ArchiveDirectory);
  153. }
  154. if (FaxConfigW.InboundProfile) {
  155. MemFree((PVOID)FaxConfigW.InboundProfile);
  156. }
  157. if (ec != ERROR_SUCCESS) {
  158. SetLastError(ec);
  159. return FALSE;
  160. }
  161. return TRUE;
  162. }
  163. BOOL
  164. WINAPI
  165. FaxGetLoggingCategoriesA(
  166. IN HANDLE FaxHandle,
  167. OUT PFAX_LOG_CATEGORYA *Categories,
  168. OUT LPDWORD NumberCategories
  169. )
  170. {
  171. BOOL retval;
  172. DWORD i;
  173. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  174. SetLastError(ERROR_INVALID_HANDLE);
  175. return FALSE;
  176. }
  177. if (!Categories || !NumberCategories) {
  178. SetLastError(ERROR_INVALID_PARAMETER);
  179. return FALSE;
  180. }
  181. retval = FaxGetLoggingCategoriesW(FaxHandle,(PFAX_LOG_CATEGORYW *)Categories , NumberCategories);
  182. if (!retval) {
  183. return FALSE;
  184. }
  185. for (i=0; i<*NumberCategories; i++) {
  186. ConvertUnicodeStringInPlace( (LPWSTR)(*Categories)[i].Name );
  187. }
  188. return TRUE;
  189. }
  190. BOOL
  191. WINAPI
  192. FaxGetLoggingCategoriesW(
  193. IN HANDLE FaxHandle,
  194. OUT PFAX_LOG_CATEGORYW *Categories,
  195. OUT LPDWORD NumberCategories
  196. )
  197. {
  198. error_status_t ec;
  199. DWORD BufferSize = 0;
  200. DWORD i;
  201. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  202. SetLastError(ERROR_INVALID_HANDLE);
  203. return FALSE;
  204. }
  205. if (!Categories || !NumberCategories) {
  206. SetLastError(ERROR_INVALID_PARAMETER);
  207. return FALSE;
  208. }
  209. *Categories = NULL;
  210. *NumberCategories = 0;
  211. ec = FAX_GetLoggingCategories(
  212. FH_FAX_HANDLE(FaxHandle),
  213. (LPBYTE*)Categories,
  214. &BufferSize,
  215. NumberCategories
  216. );
  217. if (ec != ERROR_SUCCESS) {
  218. SetLastError(ec);
  219. return FALSE;
  220. }
  221. for (i=0; i<*NumberCategories; i++) {
  222. FixupStringPtr( Categories, (*Categories)[i].Name );
  223. }
  224. return TRUE;
  225. }
  226. BOOL
  227. WINAPI
  228. FaxSetLoggingCategoriesA(
  229. IN HANDLE FaxHandle,
  230. IN const FAX_LOG_CATEGORYA *Categories,
  231. IN DWORD NumberCategories
  232. )
  233. {
  234. DWORD i;
  235. PFAX_LOG_CATEGORYW CategoryW;
  236. BOOL retval;
  237. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  238. SetLastError(ERROR_INVALID_HANDLE);
  239. return FALSE;
  240. }
  241. if (!Categories || !NumberCategories) {
  242. SetLastError(ERROR_INVALID_PARAMETER);
  243. return FALSE;
  244. }
  245. CategoryW = MemAlloc( sizeof(FAX_LOG_CATEGORYW) * NumberCategories );
  246. if (!CategoryW) {
  247. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  248. return FALSE;
  249. }
  250. for (i = 0; i< NumberCategories; i++) {
  251. CategoryW[i].Category = Categories[i].Category;
  252. CategoryW[i].Level = Categories[i].Level;
  253. CategoryW[i].Name = (LPCWSTR) AnsiStringToUnicodeString(Categories[i].Name);
  254. if (!CategoryW[i].Name && Categories[i].Name) {
  255. goto error_exit;
  256. }
  257. }
  258. retval = FaxSetLoggingCategoriesW(FaxHandle, CategoryW, NumberCategories);
  259. for (i = 0; i< NumberCategories; i++) {
  260. if (CategoryW[i].Name) MemFree((LPBYTE)CategoryW[i].Name);
  261. }
  262. MemFree(CategoryW);
  263. return retval;
  264. error_exit:
  265. for (i = 0; i< NumberCategories; i++) {
  266. if (CategoryW[i].Name) MemFree((LPBYTE)CategoryW[i].Name);
  267. }
  268. MemFree(CategoryW);
  269. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  270. return FALSE;
  271. }
  272. BOOL
  273. WINAPI
  274. FaxSetLoggingCategoriesW(
  275. IN HANDLE FaxHandle,
  276. IN const FAX_LOG_CATEGORY *Categories,
  277. IN DWORD NumberCategories
  278. )
  279. {
  280. error_status_t ec;
  281. DWORD BufferSize;
  282. DWORD i;
  283. LPBYTE Buffer;
  284. ULONG_PTR Offset;
  285. PFAX_LOG_CATEGORY LogCat;
  286. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  287. SetLastError(ERROR_INVALID_HANDLE);
  288. return FALSE;
  289. }
  290. if (!Categories || !NumberCategories) {
  291. SetLastError(ERROR_INVALID_PARAMETER);
  292. return FALSE;
  293. }
  294. Offset = BufferSize = sizeof(FAX_LOG_CATEGORY) * NumberCategories;
  295. for (i=0; i<NumberCategories; i++) {
  296. BufferSize += StringSize( Categories[i].Name );
  297. }
  298. Buffer = (LPBYTE) MemAlloc( BufferSize );
  299. if (Buffer == NULL) {
  300. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  301. return FALSE;
  302. }
  303. LogCat = (PFAX_LOG_CATEGORY) Buffer;
  304. for (i=0; i<NumberCategories; i++) {
  305. LogCat[i].Category = Categories[i].Category;
  306. LogCat[i].Level = Categories[i].Level;
  307. StoreString(
  308. Categories[i].Name,
  309. (PULONG_PTR) &LogCat[i].Name,
  310. Buffer,
  311. &Offset
  312. );
  313. }
  314. ec = FAX_SetLoggingCategories(
  315. FH_FAX_HANDLE(FaxHandle),
  316. Buffer,
  317. BufferSize,
  318. NumberCategories
  319. );
  320. MemFree( Buffer );
  321. if (ec != ERROR_SUCCESS) {
  322. SetLastError(ec);
  323. return FALSE;
  324. }
  325. return TRUE;
  326. }
  327. BOOL
  328. WINAPI
  329. FaxGetTapiLocationsW(
  330. IN HANDLE FaxHandle,
  331. OUT PFAX_TAPI_LOCATION_INFOW *TapiLocationInfo
  332. )
  333. /*++
  334. Routine Description:
  335. Gets the tapi location information from the fax server.
  336. Arguments:
  337. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  338. LocationSize, - Size of the TapiLocationInfo buffer.
  339. TapiLocationInfo - Buffer to receive the data.
  340. BytesNeeded - Required size.
  341. Return Value:
  342. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  343. --*/
  344. {
  345. error_status_t ec;
  346. DWORD i;
  347. DWORD LocationSize = 0;
  348. if (!FaxHandle || !TapiLocationInfo) {
  349. SetLastError(ERROR_INVALID_PARAMETER);
  350. return FALSE;
  351. }
  352. ec = FAX_GetTapiLocations(
  353. FH_FAX_HANDLE(FaxHandle),
  354. (LPBYTE*) TapiLocationInfo,
  355. &LocationSize
  356. );
  357. if (ec) {
  358. SetLastError( ec );
  359. return FALSE;
  360. }
  361. (*TapiLocationInfo)->TapiLocations =
  362. (PFAX_TAPI_LOCATIONS) ((LPBYTE)*TapiLocationInfo + (ULONG_PTR)(*TapiLocationInfo)->TapiLocations);
  363. for (i=0; i<(*TapiLocationInfo)->NumLocations; i++) {
  364. if ((*TapiLocationInfo)->TapiLocations[i].LocationName) {
  365. (*TapiLocationInfo)->TapiLocations[i].LocationName =
  366. (LPWSTR) ((LPBYTE)*TapiLocationInfo + (ULONG_PTR)(*TapiLocationInfo)->TapiLocations[i].LocationName);
  367. }
  368. if ((*TapiLocationInfo)->TapiLocations[i].TollPrefixes) {
  369. (*TapiLocationInfo)->TapiLocations[i].TollPrefixes =
  370. (LPWSTR) ((LPBYTE)*TapiLocationInfo + (ULONG_PTR)(*TapiLocationInfo)->TapiLocations[i].TollPrefixes);
  371. }
  372. }
  373. return TRUE;
  374. }
  375. BOOL
  376. WINAPI
  377. FaxGetTapiLocationsA(
  378. IN HANDLE FaxHandle,
  379. OUT PFAX_TAPI_LOCATION_INFOA *TapiLocationInfo
  380. )
  381. /*++
  382. Routine Description:
  383. Gets the tapi location information from the fax server.
  384. Arguments:
  385. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  386. LocationSize, - Size of the TapiLocationInfo buffer.
  387. TapiLocationInfo - Buffer to receive the data.
  388. BytesNeeded - Required size.
  389. Return Value:
  390. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  391. --*/
  392. {
  393. DWORD i;
  394. if (!FaxGetTapiLocationsW( FaxHandle, (PFAX_TAPI_LOCATION_INFOW*) TapiLocationInfo )) {
  395. return FALSE;
  396. }
  397. for (i=0; i<(*TapiLocationInfo)->NumLocations; i++) {
  398. ConvertUnicodeStringInPlace( (LPWSTR) (*TapiLocationInfo)->TapiLocations[i].LocationName );
  399. ConvertUnicodeStringInPlace( (LPWSTR) (*TapiLocationInfo)->TapiLocations[i].TollPrefixes );
  400. }
  401. return TRUE;
  402. }
  403. BOOL
  404. WINAPI
  405. FaxSetTapiLocationsW(
  406. IN HANDLE FaxHandle,
  407. IN PFAX_TAPI_LOCATION_INFOW TapiLocationInfo
  408. )
  409. /*++
  410. Routine Description:
  411. Changes the tapi location information on the fax server.
  412. Arguments:
  413. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  414. TapiLocationInfo - Buffer containing the data.
  415. Return Value:
  416. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  417. --*/
  418. {
  419. error_status_t ec;
  420. PFAX_TAPI_LOCATION_INFOW Tmp;
  421. DWORD Size;
  422. DWORD i,j;
  423. ULONG_PTR Offset;
  424. LPWSTR p,s;
  425. //
  426. // do some parameter validation
  427. //
  428. if (!FaxHandle || !TapiLocationInfo) {
  429. SetLastError( ERROR_INVALID_PARAMETER );
  430. return FALSE;
  431. }
  432. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  433. if (TapiLocationInfo->TapiLocations[i].TollPrefixes) {
  434. s = (LPTSTR)TapiLocationInfo->TapiLocations[i].TollPrefixes;
  435. while( s && *s ) {
  436. p = wcschr( s, L',' );
  437. if (p) {
  438. *p = 0;
  439. }
  440. for (j=0; j<wcslen(s); j++) {
  441. if (!iswdigit(s[j])) {
  442. SetLastError( ERROR_INVALID_PARAMETER );
  443. return FALSE;
  444. }
  445. }
  446. j = _wtoi( s );
  447. if ((j < 200) || (j > 999)) {
  448. SetLastError( ERROR_INVALID_PARAMETER );
  449. return FALSE;
  450. }
  451. if (p) {
  452. *p = L',';
  453. s = p + 1;
  454. } else {
  455. s += wcslen( s );
  456. }
  457. }
  458. }
  459. }
  460. //
  461. // calculate the required size
  462. //
  463. Size = sizeof(FAX_TAPI_LOCATION_INFOW) + (TapiLocationInfo->NumLocations * sizeof(FAX_TAPI_LOCATIONSW));
  464. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  465. Size += StringSize( TapiLocationInfo->TapiLocations[i].TollPrefixes );
  466. Size += StringSize( TapiLocationInfo->TapiLocations[i].LocationName );
  467. }
  468. //
  469. // allocate the memory
  470. //
  471. Tmp = (PFAX_TAPI_LOCATION_INFOW) MemAlloc( Size );
  472. if (!Tmp) {
  473. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  474. return FALSE;
  475. }
  476. //
  477. // fill in the temporary FAX_TAPI_LOCATION_INFO structure
  478. //
  479. Tmp->CurrentLocationID = TapiLocationInfo->CurrentLocationID;
  480. Tmp->NumLocations = TapiLocationInfo->NumLocations;
  481. Offset = sizeof(FAX_TAPI_LOCATION_INFOW);
  482. Tmp->TapiLocations = (PFAX_TAPI_LOCATIONSW) ((LPBYTE)Tmp + Offset);
  483. Offset += (TapiLocationInfo->NumLocations * sizeof(FAX_TAPI_LOCATIONSW));
  484. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  485. Tmp->TapiLocations[i].PermanentLocationID = TapiLocationInfo->TapiLocations[i].PermanentLocationID;
  486. Tmp->TapiLocations[i].CountryCode = TapiLocationInfo->TapiLocations[i].CountryCode;
  487. Tmp->TapiLocations[i].AreaCode = TapiLocationInfo->TapiLocations[i].AreaCode;
  488. Tmp->TapiLocations[i].NumTollPrefixes = TapiLocationInfo->TapiLocations[i].NumTollPrefixes;
  489. StoreString(
  490. TapiLocationInfo->TapiLocations[i].LocationName,
  491. (PULONG_PTR) &Tmp->TapiLocations[i].LocationName,
  492. (LPBYTE) Tmp,
  493. &Offset
  494. );
  495. StoreString(
  496. TapiLocationInfo->TapiLocations[i].TollPrefixes,
  497. (PULONG_PTR) &Tmp->TapiLocations[i].TollPrefixes,
  498. (LPBYTE) Tmp,
  499. &Offset
  500. );
  501. }
  502. Tmp->TapiLocations = (PFAX_TAPI_LOCATIONSW) ((LPBYTE)Tmp->TapiLocations - (ULONG_PTR)Tmp);
  503. //
  504. // call the server to change the tapi locations
  505. //
  506. ec = FAX_SetTapiLocations(
  507. FH_FAX_HANDLE(FaxHandle),
  508. (LPBYTE) Tmp,
  509. Size
  510. );
  511. //
  512. // free the temporary FAX_TAPI_LOCATION_INFO structure
  513. //
  514. MemFree( Tmp );
  515. //
  516. // return
  517. //
  518. if (ec) {
  519. SetLastError( ec );
  520. return FALSE;
  521. }
  522. return TRUE;
  523. }
  524. BOOL
  525. WINAPI
  526. FaxSetTapiLocationsA(
  527. IN HANDLE FaxHandle,
  528. IN PFAX_TAPI_LOCATION_INFOA TapiLocationInfo
  529. )
  530. /*++
  531. Routine Description:
  532. Changes the tapi location information on the fax server.
  533. Arguments:
  534. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  535. TapiLocationInfo - Buffer containing the data.
  536. Return Value:
  537. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  538. --*/
  539. {
  540. error_status_t ec;
  541. PFAX_TAPI_LOCATION_INFOA Tmp;
  542. DWORD Size;
  543. DWORD i,j;
  544. ULONG_PTR Offset;
  545. LPSTR p,s;
  546. //
  547. // do some parameter validation
  548. //
  549. if (!FaxHandle || !TapiLocationInfo) {
  550. SetLastError( ERROR_INVALID_PARAMETER );
  551. return FALSE;
  552. }
  553. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  554. if (TapiLocationInfo->TapiLocations[i].TollPrefixes) {
  555. s = (LPSTR)TapiLocationInfo->TapiLocations[i].TollPrefixes;
  556. while( s && *s ) {
  557. p = strchr( s, ',' );
  558. if (p) {
  559. *p = 0;
  560. }
  561. for (j=0; j<strlen(s); j++) {
  562. if (!isdigit(s[j])) {
  563. SetLastError( ERROR_INVALID_PARAMETER );
  564. return FALSE;
  565. }
  566. }
  567. j = atoi( s );
  568. if ((j < 200) || (j > 999)) {
  569. SetLastError( ERROR_INVALID_PARAMETER );
  570. return FALSE;
  571. }
  572. if (p) {
  573. *p = ',';
  574. s = p + 1;
  575. } else {
  576. s += strlen( s );
  577. }
  578. }
  579. }
  580. }
  581. //
  582. // calculate the required size
  583. //
  584. Size = sizeof(FAX_TAPI_LOCATION_INFOA) + (TapiLocationInfo->NumLocations * sizeof(FAX_TAPI_LOCATIONSA));
  585. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  586. Size += ((strlen(TapiLocationInfo->TapiLocations[i].TollPrefixes) + 1) * sizeof(WCHAR));
  587. Size += ((strlen(TapiLocationInfo->TapiLocations[i].LocationName) + 1) * sizeof(WCHAR));
  588. }
  589. //
  590. // allocate the memory
  591. //
  592. Tmp = (PFAX_TAPI_LOCATION_INFOA) MemAlloc( Size );
  593. if (!Tmp) {
  594. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  595. return FALSE;
  596. }
  597. //
  598. // fill in the temporary FAX_TAPI_LOCATION_INFO structure
  599. //
  600. Tmp->CurrentLocationID = TapiLocationInfo->CurrentLocationID;
  601. Tmp->NumLocations = TapiLocationInfo->NumLocations;
  602. Offset = sizeof(FAX_TAPI_LOCATION_INFOA);
  603. Tmp->TapiLocations = (PFAX_TAPI_LOCATIONSA) ((LPBYTE)Tmp + Offset);
  604. Offset += (TapiLocationInfo->NumLocations * sizeof(FAX_TAPI_LOCATIONSA));
  605. for (i=0; i<TapiLocationInfo->NumLocations; i++) {
  606. Tmp->TapiLocations[i].PermanentLocationID = TapiLocationInfo->TapiLocations[i].PermanentLocationID;
  607. Tmp->TapiLocations[i].CountryCode = TapiLocationInfo->TapiLocations[i].CountryCode;
  608. Tmp->TapiLocations[i].AreaCode = TapiLocationInfo->TapiLocations[i].AreaCode;
  609. Tmp->TapiLocations[i].NumTollPrefixes = TapiLocationInfo->TapiLocations[i].NumTollPrefixes;
  610. StoreStringA(
  611. TapiLocationInfo->TapiLocations[i].LocationName,
  612. (PULONG_PTR) &Tmp->TapiLocations[i].LocationName,
  613. (LPBYTE) Tmp,
  614. &Offset
  615. );
  616. StoreStringA(
  617. TapiLocationInfo->TapiLocations[i].TollPrefixes,
  618. (PULONG_PTR) &Tmp->TapiLocations[i].TollPrefixes,
  619. (LPBYTE) Tmp,
  620. &Offset
  621. );
  622. }
  623. Tmp->TapiLocations = (PFAX_TAPI_LOCATIONSA) ((LPBYTE)Tmp->TapiLocations - (ULONG_PTR)Tmp);
  624. //
  625. // call the server to change the tapi locations
  626. //
  627. ec = FAX_SetTapiLocations(
  628. FH_FAX_HANDLE(FaxHandle),
  629. (LPBYTE) Tmp,
  630. Size
  631. );
  632. //
  633. // free the temporary FAX_TAPI_LOCATION_INFO structure
  634. //
  635. MemFree( Tmp );
  636. //
  637. // return
  638. //
  639. if (ec) {
  640. SetLastError( ec );
  641. return FALSE;
  642. }
  643. return TRUE;
  644. }
  645. BOOL
  646. WINAPI
  647. FaxGetMapiProfilesA(
  648. IN HANDLE FaxHandle,
  649. OUT LPBYTE *MapiProfiles
  650. )
  651. /*++
  652. Routine Description:
  653. Queries the server for the MAPI profiles.
  654. Arguments:
  655. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  656. MapiProfiles - Multi-SZ string containing all MAPI profiles
  657. ProfileSize - Size of the MapiProfiles array
  658. Return Value:
  659. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  660. --*/
  661. {
  662. error_status_t ec;
  663. DWORD ProfileSize = 0;
  664. if (!FaxHandle || !MapiProfiles) {
  665. SetLastError(ERROR_INVALID_PARAMETER);
  666. return FALSE;
  667. }
  668. ec = FAX_GetMapiProfiles(
  669. FH_FAX_HANDLE(FaxHandle),
  670. MapiProfiles,
  671. &ProfileSize
  672. );
  673. if (ec) {
  674. SetLastError(ec);
  675. return FALSE;
  676. }
  677. if (!ConvertUnicodeMultiSZInPlace( (LPWSTR) *MapiProfiles, ProfileSize )) {
  678. SetLastError(ERROR_NOT_ENOUGH_SERVER_MEMORY);
  679. return FALSE;
  680. }
  681. return TRUE;
  682. }
  683. BOOL
  684. WINAPI
  685. FaxGetMapiProfilesW(
  686. IN HANDLE FaxHandle,
  687. OUT LPBYTE *MapiProfiles
  688. )
  689. /*++
  690. Routine Description:
  691. Queries the server for the MAPI profiles.
  692. Arguments:
  693. FaxHandle - FAX handle obtained from FaxConnectFaxServer.
  694. MapiProfiles - Multi-SZ string containing all MAPI profiles
  695. ProfileSize - Size of the MapiProfiles array
  696. Return Value:
  697. ERROR_SUCCESS for success, otherwise a WIN32 error code.
  698. --*/
  699. {
  700. error_status_t ec;
  701. DWORD ProfileSize = 0;
  702. if (!FaxHandle || !MapiProfiles) {
  703. SetLastError(ERROR_INVALID_PARAMETER);
  704. return FALSE;
  705. }
  706. ec = FAX_GetMapiProfiles(
  707. FH_FAX_HANDLE(FaxHandle),
  708. MapiProfiles,
  709. &ProfileSize
  710. );
  711. if (ec) {
  712. SetLastError(ec);
  713. return FALSE;
  714. }
  715. return TRUE;
  716. }
  717. FaxEnumGlobalRoutingInfoW(
  718. IN HANDLE FaxHandle,
  719. OUT PFAX_GLOBAL_ROUTING_INFOW *RoutingInfoBuffer,
  720. OUT LPDWORD MethodsReturned
  721. )
  722. {
  723. PFAX_GLOBAL_ROUTING_INFOW FaxRoutingInfo = NULL;
  724. error_status_t ec;
  725. DWORD i;
  726. DWORD RoutingInfoBufferSize = 0;
  727. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  728. SetLastError(ERROR_INVALID_HANDLE);
  729. return FALSE;
  730. }
  731. if (!RoutingInfoBuffer || !MethodsReturned) {
  732. SetLastError(ERROR_INVALID_PARAMETER);
  733. return FALSE;
  734. }
  735. *RoutingInfoBuffer = NULL;
  736. ec = FAX_EnumGlobalRoutingInfo(
  737. FH_FAX_HANDLE(FaxHandle),
  738. (LPBYTE*)RoutingInfoBuffer,
  739. &RoutingInfoBufferSize,
  740. MethodsReturned
  741. );
  742. if (ec) {
  743. SetLastError( ec );
  744. return FALSE;
  745. }
  746. FaxRoutingInfo = (PFAX_GLOBAL_ROUTING_INFOW) *RoutingInfoBuffer;
  747. for (i=0; i<*MethodsReturned; i++) {
  748. FixupStringPtr( RoutingInfoBuffer, FaxRoutingInfo[i].Guid );
  749. FixupStringPtr( RoutingInfoBuffer, FaxRoutingInfo[i].FunctionName );
  750. FixupStringPtr( RoutingInfoBuffer, FaxRoutingInfo[i].FriendlyName );
  751. FixupStringPtr( RoutingInfoBuffer, FaxRoutingInfo[i].ExtensionImageName );
  752. FixupStringPtr( RoutingInfoBuffer, FaxRoutingInfo[i].ExtensionFriendlyName );
  753. }
  754. return TRUE;
  755. }
  756. BOOL
  757. WINAPI
  758. FaxEnumGlobalRoutingInfoA(
  759. IN HANDLE FaxHandle,
  760. OUT PFAX_GLOBAL_ROUTING_INFOA *RoutingInfoBuffer,
  761. OUT LPDWORD MethodsReturned
  762. )
  763. {
  764. PFAX_GLOBAL_ROUTING_INFOW FaxRoutingMethod = NULL;
  765. DWORD i;
  766. if (!FaxEnumGlobalRoutingInfoW(
  767. FaxHandle,
  768. (PFAX_GLOBAL_ROUTING_INFOW *)RoutingInfoBuffer,
  769. MethodsReturned
  770. ))
  771. {
  772. return FALSE;
  773. }
  774. FaxRoutingMethod = (PFAX_GLOBAL_ROUTING_INFOW) *RoutingInfoBuffer;
  775. for (i=0; i<*MethodsReturned; i++) {
  776. ConvertUnicodeStringInPlace( (LPWSTR)FaxRoutingMethod[i].Guid );
  777. ConvertUnicodeStringInPlace( (LPWSTR)FaxRoutingMethod[i].FunctionName );
  778. ConvertUnicodeStringInPlace( (LPWSTR)FaxRoutingMethod[i].FriendlyName );
  779. ConvertUnicodeStringInPlace( (LPWSTR)FaxRoutingMethod[i].ExtensionImageName );
  780. ConvertUnicodeStringInPlace( (LPWSTR)FaxRoutingMethod[i].ExtensionFriendlyName );
  781. }
  782. return TRUE;
  783. }
  784. BOOL
  785. WINAPI
  786. FaxSetGlobalRoutingInfoW(
  787. IN HANDLE FaxHandle,
  788. IN const FAX_GLOBAL_ROUTING_INFOW *RoutingInfo
  789. )
  790. {
  791. error_status_t ec;
  792. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  793. SetLastError(ERROR_INVALID_HANDLE);
  794. return FALSE;
  795. }
  796. if (!RoutingInfo) {
  797. SetLastError(ERROR_INVALID_PARAMETER);
  798. return FALSE;
  799. }
  800. if (RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOW)) {
  801. SetLastError(ERROR_INVALID_PARAMETER);
  802. }
  803. ec = FAX_SetGlobalRoutingInfo( FH_FAX_HANDLE(FaxHandle), RoutingInfo );
  804. if (ec) {
  805. SetLastError( ec );
  806. return FALSE;
  807. }
  808. return TRUE;
  809. }
  810. BOOL
  811. WINAPI
  812. FaxSetGlobalRoutingInfoA(
  813. IN HANDLE FaxHandle,
  814. IN const FAX_GLOBAL_ROUTING_INFOA *RoutingInfo
  815. )
  816. {
  817. BOOL Rval;
  818. FAX_GLOBAL_ROUTING_INFOW RoutingInfoW;
  819. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  820. SetLastError(ERROR_INVALID_HANDLE);
  821. return FALSE;
  822. }
  823. if (!RoutingInfo || RoutingInfo->SizeOfStruct != sizeof(FAX_GLOBAL_ROUTING_INFOA)) {
  824. SetLastError(ERROR_INVALID_PARAMETER);
  825. return FALSE;
  826. }
  827. RoutingInfoW.SizeOfStruct = sizeof(FAX_GLOBAL_ROUTING_INFOW);
  828. RoutingInfoW.Priority = RoutingInfo->Priority;
  829. RoutingInfoW.Guid = AnsiStringToUnicodeString( RoutingInfo->Guid );
  830. RoutingInfoW.FriendlyName = AnsiStringToUnicodeString( RoutingInfo->FriendlyName );
  831. RoutingInfoW.FunctionName = AnsiStringToUnicodeString( RoutingInfo->FunctionName );
  832. RoutingInfoW.ExtensionImageName = AnsiStringToUnicodeString( RoutingInfo->ExtensionImageName );
  833. RoutingInfoW.ExtensionFriendlyName = AnsiStringToUnicodeString( RoutingInfo->ExtensionFriendlyName );
  834. Rval = FaxSetGlobalRoutingInfoW( FaxHandle, &RoutingInfoW);
  835. if (RoutingInfoW.Guid) MemFree( (LPBYTE) RoutingInfoW.Guid ) ;
  836. if (RoutingInfoW.FriendlyName) MemFree( (LPBYTE) RoutingInfoW.FriendlyName ) ;
  837. if (RoutingInfoW.FunctionName) MemFree( (LPBYTE) RoutingInfoW.FunctionName ) ;
  838. if (RoutingInfoW.ExtensionImageName) MemFree( (LPBYTE) RoutingInfoW.ExtensionImageName ) ;
  839. if (RoutingInfoW.ExtensionFriendlyName) MemFree( (LPBYTE) RoutingInfoW.ExtensionFriendlyName ) ;
  840. return Rval;
  841. }
  842. BOOL
  843. WINAPI
  844. FaxAccessCheck(
  845. IN HANDLE FaxHandle,
  846. IN DWORD AccessMask
  847. )
  848. {
  849. BOOL fPermission = FALSE;
  850. error_status_t ec;
  851. if (!ValidateFaxHandle(FaxHandle,FHT_SERVICE)) {
  852. SetLastError( ERROR_INVALID_HANDLE );
  853. }
  854. ec = FAX_AccessCheck( FH_FAX_HANDLE( FaxHandle ), AccessMask, &fPermission );
  855. if (ec) {
  856. SetLastError( ec );
  857. } else {
  858. SetLastError( ERROR_SUCCESS ) ;
  859. }
  860. return fPermission;
  861. }