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.

135 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tapiCountry.c
  5. Abstract:
  6. Utility functions for working with TAPI
  7. Environment:
  8. Server
  9. Revision History:
  10. 09/18/96 -davidx-
  11. Created it.
  12. 07/25/99 -v-sashab-
  13. Moved from fxsui
  14. --*/
  15. #include "faxsvc.h"
  16. #include "tapiCountry.h"
  17. //
  18. // Global variables used for accessing TAPI services
  19. //
  20. LPLINECOUNTRYLIST g_pLineCountryList;
  21. BOOL
  22. GetCountries(
  23. VOID
  24. )
  25. /*++
  26. Routine Description:
  27. Return a list of countries from TAPI
  28. Arguments:
  29. NONE
  30. Return Value:
  31. TRUE if successful, FALSE if there is an error
  32. NOTE:
  33. We cache the result of lineGetCountry here since it's incredibly slow.
  34. This function must be invoked inside a critical section since it updates
  35. globally shared information.
  36. --*/
  37. {
  38. #define INITIAL_SIZE_ALL_COUNTRY 22000
  39. DEBUG_FUNCTION_NAME(TEXT("GetCountries"));
  40. DWORD cbNeeded;
  41. LONG status;
  42. INT repeatCnt = 0;
  43. if (g_pLineCountryList == NULL) {
  44. //
  45. // Initial buffer size
  46. //
  47. cbNeeded = INITIAL_SIZE_ALL_COUNTRY;
  48. while (TRUE) {
  49. MemFree(g_pLineCountryList);
  50. g_pLineCountryList = NULL;
  51. if (! (g_pLineCountryList = (LPLINECOUNTRYLIST)MemAlloc(cbNeeded)))
  52. {
  53. DebugPrintEx(
  54. DEBUG_ERR,
  55. TEXT("Memory allocation failed"));
  56. break;
  57. }
  58. g_pLineCountryList->dwTotalSize = cbNeeded;
  59. status = lineGetCountry(0, MAX_TAPI_API_VER, g_pLineCountryList);
  60. if ((g_pLineCountryList->dwNeededSize > g_pLineCountryList->dwTotalSize) &&
  61. (status == NO_ERROR ||
  62. status == LINEERR_STRUCTURETOOSMALL ||
  63. status == LINEERR_NOMEM) &&
  64. (repeatCnt++ == 0))
  65. {
  66. cbNeeded = g_pLineCountryList->dwNeededSize + 1;
  67. DebugPrintEx(
  68. DEBUG_WRN,
  69. TEXT("LINECOUNTRYLIST size: %d"),cbNeeded);
  70. continue;
  71. }
  72. if (status != NO_ERROR) {
  73. DebugPrintEx(
  74. DEBUG_ERR,
  75. TEXT("lineGetCountry failed: %x"),status);
  76. MemFree(g_pLineCountryList);
  77. g_pLineCountryList = NULL;
  78. } else
  79. DebugPrintEx(DEBUG_MSG,TEXT("Number of countries: %d"), g_pLineCountryList->dwNumCountries);
  80. break;
  81. }
  82. }
  83. return g_pLineCountryList != NULL;
  84. }
  85. LPLINECOUNTRYLIST
  86. GetCountryList(
  87. )
  88. {
  89. DEBUG_FUNCTION_NAME(TEXT("GetCountryList"));
  90. return g_pLineCountryList;
  91. }