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.

400 lines
11 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. tapi.c
  5. Abstract:
  6. Src module for tapi server line funcs
  7. Author:
  8. Dan Knudson (DanKn) 01-Apr-1995
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "shellapi.h"
  13. #include "tapi.h"
  14. #include "tspi.h"
  15. #include "utils.h"
  16. #include "client.h"
  17. #include "server.h"
  18. #include "tapiperf.h"
  19. #include "tapy.h"
  20. extern TAPIGLOBALS TapiGlobals;
  21. extern CRITICAL_SECTION gPriorityListCritSec;
  22. extern PERFBLOCK PerfBlock;
  23. BOOL
  24. PASCAL
  25. NotifyHighestPriorityRequestRecipient(
  26. void
  27. );
  28. void
  29. WINAPI
  30. TGetLocationInfo(
  31. PTAPIGETLOCATIONINFO_PARAMS pParams,
  32. DWORD dwParamsBufferSize,
  33. LPBYTE pDataBuf,
  34. LPDWORD pdwNumBytesReturned
  35. )
  36. {
  37. //
  38. // This is currently implemented on the client side (should be moved
  39. // back to server side eventually)
  40. //
  41. }
  42. void
  43. WINAPI
  44. TRequestDrop(
  45. PTCLIENT ptClient,
  46. PTAPIREQUESTDROP_PARAMS pParams,
  47. DWORD dwParamsBufferSize,
  48. LPBYTE pDataBuf,
  49. LPDWORD pdwNumBytesReturned
  50. )
  51. {
  52. //
  53. // No media call/drop support right now, since the original
  54. // spec/implementation wasn't very good and made no provision for
  55. // retrieving media stream handle, etc
  56. //
  57. pParams->lResult = TAPIERR_REQUESTFAILED;
  58. }
  59. void
  60. WINAPI
  61. TRequestMakeCall(
  62. PTCLIENT ptClient,
  63. PTAPIREQUESTMAKECALL_PARAMS pParams,
  64. DWORD dwParamsBufferSize,
  65. LPBYTE pDataBuf,
  66. LPDWORD pdwNumBytesReturned
  67. )
  68. {
  69. BOOL bRequestMakeCallListEmpty;
  70. PTREQUESTMAKECALL pRequestMakeCall;
  71. //
  72. // Check to see if the hRequestMakeCall is non-0, because if so
  73. // tapi32.dll failed to exec a proxy app and it's alerting us that
  74. // we need to clean up this request (we'll just nuke 'em all for now)
  75. //
  76. if (pParams->hRequestMakeCallFailed)
  77. {
  78. PTREQUESTMAKECALL pRequestMakeCall, pNextRequestMakeCall;
  79. EnterCriticalSection (&gPriorityListCritSec);
  80. pRequestMakeCall = TapiGlobals.pRequestMakeCallList;
  81. while (pRequestMakeCall)
  82. {
  83. pNextRequestMakeCall = pRequestMakeCall->pNext;
  84. ServerFree (pRequestMakeCall);
  85. pRequestMakeCall = pNextRequestMakeCall;
  86. }
  87. TapiGlobals.pRequestMakeCallList =
  88. TapiGlobals.pRequestMakeCallListEnd = NULL;
  89. LeaveCriticalSection (&gPriorityListCritSec);
  90. LOG((TL_ERROR,
  91. "TRequestMakeCall: couldn't exec proxy, deleting requests"
  92. ));
  93. pParams->lResult = TAPIERR_NOREQUESTRECIPIENT;
  94. return;
  95. }
  96. //
  97. // Verify size/offset/string params given our input buffer/size
  98. //
  99. if (IsBadStringParam(
  100. dwParamsBufferSize,
  101. pDataBuf,
  102. pParams->dwDestAddressOffset
  103. ) ||
  104. ((pParams->dwAppNameOffset != TAPI_NO_DATA) &&
  105. IsBadStringParam(
  106. dwParamsBufferSize,
  107. pDataBuf,
  108. pParams->dwAppNameOffset
  109. )) ||
  110. ((pParams->dwCalledPartyOffset != TAPI_NO_DATA) &&
  111. IsBadStringParam(
  112. dwParamsBufferSize,
  113. pDataBuf,
  114. pParams->dwCalledPartyOffset
  115. )) ||
  116. ((pParams->dwCommentOffset != TAPI_NO_DATA) &&
  117. IsBadStringParam(
  118. dwParamsBufferSize,
  119. pDataBuf,
  120. pParams->dwCommentOffset
  121. )) ||
  122. (pParams->dwProxyListTotalSize > dwParamsBufferSize))
  123. {
  124. pParams->lResult = TAPIERR_REQUESTFAILED;
  125. return;
  126. }
  127. //
  128. // Alloc & init a request make call object
  129. //
  130. if (!(pRequestMakeCall = ServerAlloc (sizeof (TREQUESTMAKECALL))))
  131. {
  132. pParams->lResult = TAPIERR_REQUESTFAILED;
  133. return;
  134. }
  135. LOG((TL_INFO, "Request: 0x%p", pRequestMakeCall));
  136. wcsncpy(
  137. pRequestMakeCall->LineReqMakeCall.szDestAddress,
  138. (LPCWSTR) (pDataBuf + pParams->dwDestAddressOffset),
  139. TAPIMAXDESTADDRESSSIZE
  140. );
  141. pRequestMakeCall->LineReqMakeCall.szDestAddress[TAPIMAXDESTADDRESSSIZE-1] =
  142. '\0';
  143. LOG((TL_INFO, " DestAddress: [%ls]",
  144. pRequestMakeCall->LineReqMakeCall.szDestAddress));
  145. if (pParams->dwAppNameOffset != TAPI_NO_DATA)
  146. {
  147. wcsncpy(
  148. pRequestMakeCall->LineReqMakeCall.szAppName,
  149. (LPCWSTR) (pDataBuf + pParams->dwAppNameOffset),
  150. TAPIMAXAPPNAMESIZE
  151. );
  152. pRequestMakeCall->LineReqMakeCall.szAppName[TAPIMAXAPPNAMESIZE-1] =
  153. '\0';
  154. LOG((TL_INFO, " AppName: [%ls]",
  155. pRequestMakeCall->LineReqMakeCall.szAppName));
  156. }
  157. if (pParams->dwCalledPartyOffset != TAPI_NO_DATA)
  158. {
  159. wcsncpy(
  160. pRequestMakeCall->LineReqMakeCall.szCalledParty,
  161. (LPCWSTR) (pDataBuf + pParams->dwCalledPartyOffset),
  162. TAPIMAXCALLEDPARTYSIZE
  163. );
  164. pRequestMakeCall->LineReqMakeCall.szCalledParty[TAPIMAXCALLEDPARTYSIZE-1] =
  165. '\0';
  166. LOG((TL_INFO, " CalledParty: [%ls]",
  167. pRequestMakeCall->LineReqMakeCall.szCalledParty));
  168. }
  169. if (pParams->dwCommentOffset != TAPI_NO_DATA)
  170. {
  171. wcsncpy(
  172. pRequestMakeCall->LineReqMakeCall.szComment,
  173. (LPCWSTR) (pDataBuf + pParams->dwCommentOffset),
  174. TAPIMAXCOMMENTSIZE
  175. );
  176. pRequestMakeCall->LineReqMakeCall.szComment[TAPIMAXCOMMENTSIZE-1] =
  177. '\0';
  178. LOG((TL_INFO, " Comment: [%ls]",
  179. pRequestMakeCall->LineReqMakeCall.szComment));
  180. }
  181. //
  182. // Add object to end of global list
  183. //
  184. EnterCriticalSection (&gPriorityListCritSec);
  185. if (TapiGlobals.pRequestMakeCallListEnd)
  186. {
  187. TapiGlobals.pRequestMakeCallListEnd->pNext = pRequestMakeCall;
  188. bRequestMakeCallListEmpty = FALSE;
  189. }
  190. else
  191. {
  192. TapiGlobals.pRequestMakeCallList = pRequestMakeCall;
  193. bRequestMakeCallListEmpty = TRUE;
  194. }
  195. TapiGlobals.pRequestMakeCallListEnd = pRequestMakeCall;
  196. LeaveCriticalSection (&gPriorityListCritSec);
  197. {
  198. LPVARSTRING pProxyList = (LPVARSTRING) pDataBuf;
  199. pProxyList->dwTotalSize = pParams->dwProxyListTotalSize;
  200. pProxyList->dwNeededSize =
  201. pProxyList->dwUsedSize = sizeof (VARSTRING);
  202. pParams->hRequestMakeCallAttempted = 0;
  203. //
  204. // If the request list is currently empty then we need to notify the
  205. // highest priority request recipient that there's requests for it
  206. // to process. Otherwise, we can assume that we already sent this
  207. // msg and the app knows there's requests available for it to process.
  208. //
  209. if (bRequestMakeCallListEmpty)
  210. {
  211. if (TapiGlobals.pHighestPriorityRequestRecipient)
  212. {
  213. NotifyHighestPriorityRequestRecipient();
  214. }
  215. else
  216. {
  217. EnterCriticalSection (&gPriorityListCritSec);
  218. if (TapiGlobals.pszReqMakeCallPriList)
  219. {
  220. //
  221. // Copy the pri list to the buffer & pass it back to
  222. // the client side, so it can try to start the proxy
  223. // app (if it fails it'll call us back to free the
  224. // pRequestMakeCall)
  225. //
  226. pProxyList->dwNeededSize =
  227. pProxyList->dwUsedSize = pProxyList->dwTotalSize;
  228. pProxyList->dwStringSize =
  229. pParams->dwProxyListTotalSize - sizeof (VARSTRING);
  230. pProxyList->dwStringOffset = sizeof (VARSTRING);
  231. pParams->hRequestMakeCallAttempted = 1;
  232. wcsncpy(
  233. (PWSTR)(((LPBYTE) pProxyList) + pProxyList->dwStringOffset),
  234. TapiGlobals.pszReqMakeCallPriList + 1, // no init ','
  235. pProxyList->dwStringSize / sizeof(WCHAR)
  236. );
  237. }
  238. else
  239. {
  240. TapiGlobals.pRequestMakeCallList =
  241. TapiGlobals.pRequestMakeCallListEnd = NULL;
  242. ServerFree (pRequestMakeCall);
  243. pParams->lResult = TAPIERR_NOREQUESTRECIPIENT;
  244. }
  245. LeaveCriticalSection (&gPriorityListCritSec);
  246. }
  247. }
  248. if (pParams->lResult == 0)
  249. {
  250. pParams->dwProxyListOffset = 0;
  251. *pdwNumBytesReturned = sizeof (TAPI32_MSG) +
  252. pProxyList->dwUsedSize;
  253. }
  254. }
  255. //TRequestMakeCall_return:
  256. LOG((TL_TRACE,
  257. "TapiEpilogSync (tapiRequestMakeCall) exit, returning x%x",
  258. pParams->lResult
  259. ));
  260. }
  261. void
  262. WINAPI
  263. TRequestMediaCall(
  264. PTCLIENT ptClient,
  265. PTAPIREQUESTMEDIACALL_PARAMS pParams,
  266. DWORD dwParamsBufferSize,
  267. LPBYTE pDataBuf,
  268. LPDWORD pdwNumBytesReturned
  269. )
  270. {
  271. //
  272. // No media call/drop support right now, since the original
  273. // spec/implementation wasn't very good and made no provision for
  274. // retrieving media stream handle, etc
  275. //
  276. pParams->lResult = TAPIERR_REQUESTFAILED;
  277. }
  278. void
  279. WINAPI
  280. TPerformance(
  281. PTCLIENT ptClient,
  282. PTAPIPERFORMANCE_PARAMS pParams,
  283. DWORD dwParamsBufferSize,
  284. LPBYTE pDataBuf,
  285. LPDWORD pdwNumBytesReturned
  286. )
  287. {
  288. LOG((TL_TRACE, "PERF: In TPerformance"));
  289. //
  290. // Verify size/offset/string params given our input buffer/size
  291. //
  292. if (dwParamsBufferSize < sizeof (PERFBLOCK))
  293. {
  294. pParams->lResult = LINEERR_OPERATIONFAILED;
  295. return;
  296. }
  297. CopyMemory (pDataBuf, &PerfBlock, sizeof (PERFBLOCK));
  298. pParams->dwPerfOffset = 0;
  299. *pdwNumBytesReturned = sizeof(TAPI32_MSG) + sizeof(PERFBLOCK);
  300. }