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.

240 lines
5.3 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. #include "rasman.h"
  25. //
  26. // TAPI version
  27. //
  28. #define TAPIVERSION 0x00020000
  29. //
  30. // Global variables
  31. //
  32. HLINEAPP hlineAppG;
  33. DWORD dwDialingLocationErrorG;
  34. DWORD dwDialingLocationIdG;
  35. CRITICAL_SECTION csTapiG;
  36. HANDLE hTapiChangeG;
  37. extern DWORD g_dwCritSecFlags;
  38. //
  39. // External variables
  40. //
  41. extern HINSTANCE hinstDllG;
  42. extern IMPERSONATION_INFO ImpersonationInfoG;
  43. DWORD
  44. TapiGetDialingLocation(
  45. OUT LPDWORD lpdwLocationID
  46. )
  47. {
  48. DWORD dwErr, dwCurrentLocationID;
  49. LINETRANSLATECAPS caps;
  50. LINETRANSLATECAPS *pCaps;
  51. //
  52. // Get the dialing location from TAPI.
  53. //
  54. RtlZeroMemory(&caps, sizeof (LINETRANSLATECAPS));
  55. caps.dwTotalSize = sizeof (LINETRANSLATECAPS);
  56. dwErr = lineGetTranslateCaps(hlineAppG, TAPIVERSION, &caps);
  57. if (dwErr) {
  58. RASAUTO_TRACE1(
  59. "TapiGetDialingLocation: lineGetTranslateCaps failed (dwErr=%d)",
  60. dwErr);
  61. return dwErr;
  62. }
  63. pCaps = (LINETRANSLATECAPS *)LocalAlloc(LPTR, caps.dwNeededSize);
  64. if (pCaps == NULL) {
  65. RASAUTO_TRACE("TapiGetDialingLocation: LocalAlloc failed");
  66. return dwErr;
  67. }
  68. RtlZeroMemory(pCaps, sizeof (LINETRANSLATECAPS));
  69. pCaps->dwTotalSize = caps.dwNeededSize;
  70. dwErr = lineGetTranslateCaps(hlineAppG, TAPIVERSION, pCaps);
  71. if (dwErr) {
  72. RASAUTO_TRACE1(
  73. "TapiGetDialingLocation: lineTranslateCaps failed (dwErr=%d)",
  74. dwErr);
  75. LocalFree(pCaps);
  76. return dwErr;
  77. }
  78. dwCurrentLocationID = pCaps->dwCurrentLocationID;
  79. LocalFree(pCaps);
  80. RASAUTO_TRACE1(
  81. "TapiGetDialingLocation: current dialing location is %d",
  82. dwCurrentLocationID);
  83. *lpdwLocationID = dwCurrentLocationID;
  84. return dwErr;
  85. } // TapiGetDialingLocation
  86. DWORD
  87. TapiCurrentDialingLocation(
  88. OUT LPDWORD lpdwLocationID
  89. )
  90. {
  91. DWORD dwErr;
  92. EnterCriticalSection(&csTapiG);
  93. dwErr = dwDialingLocationErrorG;
  94. if (!dwErr)
  95. *lpdwLocationID = dwDialingLocationIdG;
  96. LeaveCriticalSection(&csTapiG);
  97. return dwErr;
  98. } // TapiCurrentDialingLocation
  99. VOID
  100. ProcessTapiChangeEvent(VOID)
  101. {
  102. DWORD dwErr;
  103. LINEMESSAGE msg;
  104. dwErr = lineGetMessage(hlineAppG, &msg, 0);
  105. if (dwErr) {
  106. RASAUTO_TRACE1(
  107. "ProcessTapiChangeEvent: lineGetMessage failed (dwErr=0x%x)",
  108. dwErr);
  109. return;
  110. }
  111. RASAUTO_TRACE2(
  112. "ProcessTapiChangeEvent: dwMessageID=%d, dwParam1=%d",
  113. msg.dwMessageID,
  114. msg.dwParam1);
  115. //
  116. // Reset TAPI dialing location.
  117. //
  118. if (msg.dwMessageID == LINE_LINEDEVSTATE &&
  119. msg.dwParam1 == LINEDEVSTATE_TRANSLATECHANGE)
  120. {
  121. EnterCriticalSection(&csTapiG);
  122. dwDialingLocationErrorG =
  123. TapiGetDialingLocation(&dwDialingLocationIdG);
  124. LeaveCriticalSection(&csTapiG);
  125. }
  126. } // ProcessTapiChangeEvent
  127. DWORD
  128. TapiInitialize(VOID)
  129. {
  130. DWORD dwErr, dwcDevices, dwAPIVersion, dwDisp;
  131. LINEINITIALIZEEXPARAMS lineParams;
  132. //
  133. // Create a mutex to serialize access
  134. // to the dialing location variable.
  135. //
  136. RasInitializeCriticalSection(&csTapiG, &dwErr);
  137. if(dwErr != ERROR_SUCCESS)
  138. {
  139. return dwErr;
  140. }
  141. g_dwCritSecFlags |= RASAUTO_CRITSEC_TAPI;
  142. //
  143. // Initialize TAPI.
  144. //
  145. dwAPIVersion = TAPIVERSION;
  146. RtlZeroMemory(&lineParams, sizeof (lineParams));
  147. lineParams.dwTotalSize = sizeof (lineParams);
  148. lineParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
  149. dwErr = lineInitializeEx(
  150. &hlineAppG,
  151. hinstDllG,
  152. NULL,
  153. TEXT("rasauto.dll"),
  154. &dwcDevices,
  155. &dwAPIVersion,
  156. &lineParams);
  157. if (dwErr) {
  158. RASAUTO_TRACE1(
  159. "TapiInitalize: lineInitializeEx failed (dwErr=0x%x)",
  160. dwErr);
  161. DeleteCriticalSection(&csTapiG);
  162. g_dwCritSecFlags &= ~(RASAUTO_CRITSEC_TAPI);
  163. return dwErr;
  164. }
  165. //
  166. // Save the event returned from TAPI that
  167. // will get signaled on state changes.
  168. //
  169. hTapiChangeG = lineParams.Handles.hEvent;
  170. //
  171. // Get the current dialing location.
  172. //
  173. dwDialingLocationErrorG = TapiGetDialingLocation(&dwDialingLocationIdG);
  174. RASAUTO_TRACE("TapiInitialize: initialization done");
  175. return 0;
  176. } // TapiInitialilze
  177. VOID
  178. TapiShutdown(VOID)
  179. {
  180. DWORD dwErr;
  181. //
  182. // Shutdown TAPI.
  183. //
  184. dwErr = lineShutdown(hlineAppG);
  185. if (dwErr) {
  186. RASAUTO_TRACE1(
  187. "TapiMessageLoopThread: lineShutdown failed (dwErr=%d)",
  188. dwErr);
  189. }
  190. if(g_dwCritSecFlags & RASAUTO_CRITSEC_TAPI)
  191. {
  192. DeleteCriticalSection(&csTapiG);
  193. g_dwCritSecFlags &= ~(RASAUTO_CRITSEC_TAPI);
  194. }
  195. RASAUTO_TRACE("TapiShutdown: shutting down");
  196. } // TapiShutdown
  197.