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.

220 lines
4.7 KiB

  1. /*++
  2. Copyright(c) 1995 Microsoft Corporation
  3. MODULE NAME
  4. tapiproc.c
  5. ABSTRACT
  6. TAPI utility routines
  7. AUTHOR
  8. Anthony Discolo (adiscolo) 12-Dec-1995
  9. REVISION HISTORY
  10. --*/
  11. #define UNICODE
  12. #define _UNICODE
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <stdlib.h>
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <npapi.h>
  20. #include <tapi.h>
  21. #include <debug.h>
  22. #include "imperson.h"
  23. #include "radebug.h"
  24. //
  25. // TAPI version
  26. //
  27. #define TAPIVERSION 0x00020000
  28. //
  29. // Global variables
  30. //
  31. HLINEAPP hlineAppG;
  32. DWORD dwDialingLocationErrorG;
  33. DWORD dwDialingLocationIdG;
  34. CRITICAL_SECTION csTapiG;
  35. HANDLE hTapiChangeG;
  36. //
  37. // External variables
  38. //
  39. extern HINSTANCE hinstDllG;
  40. extern IMPERSONATION_INFO ImpersonationInfoG;
  41. DWORD
  42. TapiGetDialingLocation(
  43. OUT LPDWORD lpdwLocationID
  44. )
  45. {
  46. DWORD dwErr, dwCurrentLocationID;
  47. LINETRANSLATECAPS caps;
  48. LINETRANSLATECAPS *pCaps;
  49. //
  50. // Get the dialing location from TAPI.
  51. //
  52. RtlZeroMemory(&caps, sizeof (LINETRANSLATECAPS));
  53. caps.dwTotalSize = sizeof (LINETRANSLATECAPS);
  54. dwErr = lineGetTranslateCaps(hlineAppG, TAPIVERSION, &caps);
  55. if (dwErr) {
  56. RASAUTO_TRACE1(
  57. "TapiGetDialingLocation: lineGetTranslateCaps failed (dwErr=%d)",
  58. dwErr);
  59. return dwErr;
  60. }
  61. pCaps = (LINETRANSLATECAPS *)LocalAlloc(LPTR, caps.dwNeededSize);
  62. if (pCaps == NULL) {
  63. RASAUTO_TRACE("TapiGetDialingLocation: LocalAlloc failed");
  64. return dwErr;
  65. }
  66. RtlZeroMemory(pCaps, sizeof (LINETRANSLATECAPS));
  67. pCaps->dwTotalSize = caps.dwNeededSize;
  68. dwErr = lineGetTranslateCaps(hlineAppG, TAPIVERSION, pCaps);
  69. if (dwErr) {
  70. RASAUTO_TRACE1(
  71. "TapiGetDialingLocation: lineTranslateCaps failed (dwErr=%d)",
  72. dwErr);
  73. LocalFree(pCaps);
  74. return dwErr;
  75. }
  76. dwCurrentLocationID = pCaps->dwCurrentLocationID;
  77. LocalFree(pCaps);
  78. RASAUTO_TRACE1(
  79. "TapiGetDialingLocation: current dialing location is %d",
  80. dwCurrentLocationID);
  81. *lpdwLocationID = dwCurrentLocationID;
  82. return dwErr;
  83. } // TapiGetDialingLocation
  84. DWORD
  85. TapiCurrentDialingLocation(
  86. OUT LPDWORD lpdwLocationID
  87. )
  88. {
  89. DWORD dwErr;
  90. EnterCriticalSection(&csTapiG);
  91. dwErr = dwDialingLocationErrorG;
  92. if (!dwErr)
  93. *lpdwLocationID = dwDialingLocationIdG;
  94. LeaveCriticalSection(&csTapiG);
  95. return dwErr;
  96. } // TapiCurrentDialingLocation
  97. VOID
  98. ProcessTapiChangeEvent(VOID)
  99. {
  100. DWORD dwErr;
  101. LINEMESSAGE msg;
  102. dwErr = lineGetMessage(hlineAppG, &msg, 0);
  103. if (dwErr) {
  104. RASAUTO_TRACE1(
  105. "ProcessTapiChangeEvent: lineGetMessage failed (dwErr=0x%x)",
  106. dwErr);
  107. return;
  108. }
  109. RASAUTO_TRACE2(
  110. "ProcessTapiChangeEvent: dwMessageID=%d, dwParam1=%d",
  111. msg.dwMessageID,
  112. msg.dwParam1);
  113. //
  114. // Reset TAPI dialing location.
  115. //
  116. if (msg.dwMessageID == LINE_LINEDEVSTATE &&
  117. msg.dwParam1 == LINEDEVSTATE_TRANSLATECHANGE)
  118. {
  119. EnterCriticalSection(&csTapiG);
  120. dwDialingLocationErrorG =
  121. TapiGetDialingLocation(&dwDialingLocationIdG);
  122. LeaveCriticalSection(&csTapiG);
  123. }
  124. } // ProcessTapiChangeEvent
  125. DWORD
  126. TapiInitialize(VOID)
  127. {
  128. DWORD dwErr, dwcDevices, dwAPIVersion, dwDisp;
  129. LINEINITIALIZEEXPARAMS lineParams;
  130. //
  131. // Create a mutex to serialize access
  132. // to the dialing location variable.
  133. //
  134. InitializeCriticalSection(&csTapiG);
  135. //
  136. // Initialize TAPI.
  137. //
  138. dwAPIVersion = TAPIVERSION;
  139. RtlZeroMemory(&lineParams, sizeof (lineParams));
  140. lineParams.dwTotalSize = sizeof (lineParams);
  141. lineParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
  142. dwErr = lineInitializeEx(
  143. &hlineAppG,
  144. hinstDllG,
  145. NULL,
  146. TEXT("rasauto.dll"),
  147. &dwcDevices,
  148. &dwAPIVersion,
  149. &lineParams);
  150. if (dwErr) {
  151. RASAUTO_TRACE1(
  152. "TapiInitalize: lineInitializeEx failed (dwErr=0x%x)",
  153. dwErr);
  154. return dwErr;
  155. }
  156. //
  157. // Save the event returned from TAPI that
  158. // will get signaled on state changes.
  159. //
  160. hTapiChangeG = lineParams.Handles.hEvent;
  161. //
  162. // Get the current dialing location.
  163. //
  164. dwDialingLocationErrorG = TapiGetDialingLocation(&dwDialingLocationIdG);
  165. RASAUTO_TRACE("TapiInitialize: initialization done");
  166. return 0;
  167. } // TapiInitialilze
  168. VOID
  169. TapiShutdown(VOID)
  170. {
  171. DWORD dwErr;
  172. //
  173. // Shutdown TAPI.
  174. //
  175. dwErr = lineShutdown(hlineAppG);
  176. if (dwErr) {
  177. RASAUTO_TRACE1(
  178. "TapiMessageLoopThread: lineShutdown failed (dwErr=%d)",
  179. dwErr);
  180. }
  181. DeleteCriticalSection(&csTapiG);
  182. RASAUTO_TRACE("TapiShutdown: shutting down");
  183. } // TapiShutdown
  184.