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.

1324 lines
34 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. event.c
  5. Abstract:
  6. Src module for tapi event filtering funcs
  7. Author:
  8. Xiaohai Zhang (xzhang) 24-Nov-1999
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "tapi.h"
  13. #include "tspi.h"
  14. #include "client.h"
  15. #include "loc_comn.h"
  16. #include "server.h"
  17. #include "private.h"
  18. #include "tapihndl.h"
  19. #include "utils.h"
  20. extern BOOL gbNTServer;
  21. //
  22. // GetSubMaskIndex
  23. // Description:
  24. // Get the index into the submask array in vairous TAPI server object
  25. // from the event mask, there should be one and only one bit set in
  26. // ulEventMask
  27. // Parameters:
  28. // ulEventMask : the mask whose submask index to be returned
  29. // Return Value:
  30. // The index of the message mask in ulEventMask
  31. //
  32. DWORD
  33. GetSubMaskIndex (ULONG64 ulEventMask)
  34. {
  35. DWORD dwSubMaskIndex;
  36. // Assert that there is one and only one bit set in ulEventMask
  37. ASSERT (ulEventMask !=0 && (ulEventMask & (ulEventMask - 1)) == 0);
  38. dwSubMaskIndex = 0;
  39. while (ulEventMask > 1)
  40. {
  41. ulEventMask >>= 1;
  42. ++dwSubMaskIndex;
  43. }
  44. return dwSubMaskIndex;
  45. }
  46. //
  47. // GetMsgMask
  48. // Description:
  49. // Utility function to get corresponding msg mask and its submask index
  50. // Parameters:
  51. // Msg : whose mask and submask index to be returned
  52. // pulMask : address to hold the returned mask
  53. // pdwSubMaskIndex : address to hold the returned submask index
  54. // Return Value:
  55. // TRUE if there exists a mask defined for the Msg, otherwise FALSE
  56. //
  57. BOOL
  58. GetMsgMask (DWORD Msg, ULONG64 * pulMask, DWORD *pdwSubMaskIndex)
  59. {
  60. ULONG64 ulMask;
  61. DWORD dwSubMaskIndex;
  62. if (NULL == pulMask ||
  63. NULL == pdwSubMaskIndex)
  64. {
  65. ASSERT (0);
  66. return FALSE;
  67. }
  68. switch (Msg)
  69. {
  70. case LINE_ADDRESSSTATE:
  71. ulMask = EM_LINE_ADDRESSSTATE;
  72. break;
  73. case LINE_LINEDEVSTATE:
  74. ulMask = EM_LINE_LINEDEVSTATE;
  75. break;
  76. case LINE_CALLINFO:
  77. ulMask = EM_LINE_CALLINFO;
  78. break;
  79. case LINE_CALLSTATE:
  80. ulMask = EM_LINE_CALLSTATE;
  81. break;
  82. case LINE_APPNEWCALL:
  83. ulMask = EM_LINE_APPNEWCALL;
  84. break;
  85. case LINE_CREATE:
  86. ulMask = EM_LINE_CREATE;
  87. break;
  88. case LINE_REMOVE:
  89. ulMask = EM_LINE_REMOVE;
  90. break;
  91. case LINE_CLOSE:
  92. ulMask = EM_LINE_CLOSE;
  93. break;
  94. // case LINE_PROXYREQUEST:
  95. // ulMask = EM_LINE_PROXYREQUEST;
  96. // break;
  97. case LINE_DEVSPECIFIC:
  98. ulMask = EM_LINE_DEVSPECIFIC;
  99. break;
  100. case LINE_DEVSPECIFICFEATURE:
  101. ulMask = EM_LINE_DEVSPECIFICFEATURE;
  102. break;
  103. case LINE_AGENTSTATUS:
  104. ulMask = EM_LINE_AGENTSTATUS;
  105. break;
  106. case LINE_AGENTSTATUSEX:
  107. ulMask = EM_LINE_AGENTSTATUSEX;
  108. break;
  109. case LINE_AGENTSPECIFIC:
  110. ulMask = EM_LINE_AGENTSPECIFIC;
  111. break;
  112. case LINE_AGENTSESSIONSTATUS:
  113. ulMask = EM_LINE_AGENTSESSIONSTATUS;
  114. break;
  115. case LINE_QUEUESTATUS:
  116. ulMask = EM_LINE_QUEUESTATUS;
  117. break;
  118. case LINE_GROUPSTATUS:
  119. ulMask = EM_LINE_GROUPSTATUS;
  120. break;
  121. // case LINE_PROXYSTATUS:
  122. // ulMask = EM_LINE_PROXYSTATUS;
  123. // break;
  124. case LINE_APPNEWCALLHUB:
  125. ulMask = EM_LINE_APPNEWCALLHUB;
  126. break;
  127. case LINE_CALLHUBCLOSE:
  128. ulMask = EM_LINE_CALLHUBCLOSE;
  129. break;
  130. case LINE_DEVSPECIFICEX:
  131. ulMask = EM_LINE_DEVSPECIFICEX;
  132. break;
  133. case LINE_QOSINFO:
  134. ulMask = EM_LINE_QOSINFO;
  135. break;
  136. case PHONE_CREATE:
  137. ulMask = EM_PHONE_CREATE;
  138. break;
  139. case PHONE_REMOVE:
  140. ulMask = EM_PHONE_REMOVE;
  141. break;
  142. case PHONE_CLOSE:
  143. ulMask = EM_PHONE_CLOSE;
  144. break;
  145. case PHONE_STATE:
  146. ulMask = EM_PHONE_STATE;
  147. break;
  148. case PHONE_DEVSPECIFIC:
  149. ulMask = EM_PHONE_DEVSPECIFIC;
  150. break;
  151. case PHONE_BUTTON:
  152. ulMask = EM_PHONE_BUTTONMODE;
  153. break;
  154. default:
  155. ulMask = 0;
  156. }
  157. if (ulMask != 0)
  158. {
  159. *pulMask = ulMask;
  160. *pdwSubMaskIndex = GetSubMaskIndex(ulMask);
  161. }
  162. return (ulMask ? TRUE : FALSE);
  163. }
  164. //
  165. // FMsgDisabled
  166. // Description:
  167. // Utility function used throughout tapisrv to check if a message
  168. // is allowed to be sent or not.
  169. // Parameters:
  170. // dwAPIVersion : the object API version
  171. // adwEventSubMasks: the object submasks array
  172. // Msg : the message to be checked
  173. // dwParam1 : the sub message of Msg to be checked
  174. // Return Value:
  175. // TRUE if the message should NOT be sent, otherwise FALSE
  176. //
  177. BOOL
  178. FMsgDisabled (
  179. DWORD dwAPIVersion,
  180. DWORD *adwEventSubMasks,
  181. DWORD Msg,
  182. DWORD dwParam1
  183. )
  184. {
  185. BOOL fRet;
  186. ULONG64 ulMsgMask;
  187. DWORD dwSubMaskIndex;
  188. if (dwAPIVersion <= TAPI_VERSION3_0)
  189. {
  190. LOG((TL_INFO, "FMsgDisbled: dwAPIVersion<= TAPI_VERSION3_0, msg will be enabled"));
  191. fRet = FALSE;
  192. goto ExitHere;
  193. }
  194. //
  195. // The message is allowed to be sent if
  196. // (1). No event mask defined for Msg, i.e LINE_REPLY
  197. // (2). Msg is enabled for all submasks adwEventSubMasks[index] = (-1)
  198. // (3). SubMask enabled: adwEventSubMask[index] & dwParam1 != 0
  199. //
  200. if (!GetMsgMask(Msg, &ulMsgMask, &dwSubMaskIndex) ||
  201. adwEventSubMasks[dwSubMaskIndex] == (-1) ||
  202. ((adwEventSubMasks[dwSubMaskIndex] & dwParam1) != 0))
  203. {
  204. fRet = FALSE;
  205. }
  206. else
  207. {
  208. fRet = TRUE;
  209. }
  210. ExitHere:
  211. LOG((TL_TRACE, "FMsgDisabled return %x", fRet));
  212. return (fRet);
  213. }
  214. //
  215. // SetEventMasksOrSubMasks
  216. // Description:
  217. // Utility function used to apply masks or submasks to a certain objects
  218. // submasks array.
  219. // Parameters:
  220. // fSubMask : this function is called for submasks
  221. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  222. // whose submasks is to be set
  223. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  224. // adwEventSubMasks: the submasks array from the object
  225. // Return Value:
  226. // Always succeed.
  227. //
  228. LONG
  229. SetEventMasksOrSubMasks (
  230. BOOL fSubMask,
  231. ULONG64 ulEventMasks,
  232. DWORD dwEventSubMasks,
  233. DWORD *adwTargetSubMasks
  234. )
  235. {
  236. ULONG64 ulMask = 1;
  237. LONG lResult = S_OK;
  238. DWORD dwIndex = 0;
  239. if (NULL == adwTargetSubMasks)
  240. {
  241. ASSERT (0);
  242. return LINEERR_INVALPOINTER;
  243. }
  244. if (fSubMask)
  245. {
  246. dwIndex = GetSubMaskIndex(ulEventMasks);
  247. adwTargetSubMasks[dwIndex] = dwEventSubMasks;
  248. }
  249. else
  250. {
  251. for (dwIndex = 0; dwIndex < EM_NUM_MASKS; ++dwIndex)
  252. {
  253. adwTargetSubMasks[dwIndex] = ((ulMask & ulEventMasks) ? (-1) : 0);
  254. ulMask <<= 1;
  255. }
  256. }
  257. return lResult;
  258. }
  259. //
  260. // SettCallClientEventMasks
  261. // Description:
  262. // Apply the masks or submasks on a call object.
  263. // Parameters:
  264. // ptCallClient : the call object to apply the masking
  265. // fSubMask : this function is called for submasks
  266. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  267. // whose submasks is to be set
  268. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  269. // Return Value:
  270. //
  271. LONG
  272. SettCallClientEventMasks (
  273. PTCALLCLIENT ptCallClient,
  274. BOOL fSubMask,
  275. ULONG64 ulEventMasks,
  276. DWORD dwEventSubMasks
  277. )
  278. {
  279. LONG lResult = S_OK;
  280. BOOL bLocked = TRUE;
  281. if (!WaitForExclusivetCallAccess (ptCallClient->ptCall, TCALL_KEY))
  282. {
  283. bLocked = FALSE;
  284. lResult = LINEERR_OPERATIONFAILED;
  285. goto ExitHere;
  286. }
  287. if (ptCallClient->ptLineClient->ptLineApp->dwAPIVersion <= TAPI_VERSION3_0)
  288. {
  289. goto ExitHere;
  290. }
  291. lResult = SetEventMasksOrSubMasks (
  292. fSubMask,
  293. ulEventMasks,
  294. dwEventSubMasks,
  295. ptCallClient->adwEventSubMasks
  296. );
  297. ExitHere:
  298. if (bLocked)
  299. {
  300. UNLOCKTCALL (ptCallClient->ptCall);
  301. }
  302. return lResult;
  303. }
  304. //
  305. // SettLineClientEventMasks
  306. // Description:
  307. // Apply the masks or submasks on a tLineClient object.
  308. // Parameters:
  309. // ptLineClient : the line object to apply the masking
  310. // fSubMask : this function is called for submasks
  311. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  312. // whose submasks is to be set
  313. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  314. // Return Value:
  315. //
  316. LONG
  317. SettLineClientEventMasks (
  318. PTLINECLIENT ptLineClient,
  319. BOOL fSubMask,
  320. ULONG64 ulEventMasks,
  321. DWORD dwEventSubMasks
  322. )
  323. {
  324. LONG lResult = S_OK;
  325. PTCALLCLIENT ptCallClient;
  326. LOCKTLINECLIENT (ptLineClient);
  327. if (ptLineClient->dwKey != TLINECLIENT_KEY)
  328. {
  329. lResult = LINEERR_OPERATIONFAILED;
  330. goto ExitHere;
  331. }
  332. if (ptLineClient->ptLineApp->dwAPIVersion <= \
  333. TAPI_VERSION3_0)
  334. {
  335. goto ExitHere;
  336. }
  337. lResult = SetEventMasksOrSubMasks (
  338. fSubMask,
  339. ulEventMasks,
  340. dwEventSubMasks,
  341. ptLineClient->adwEventSubMasks
  342. );
  343. if (lResult)
  344. {
  345. goto ExitHere;
  346. }
  347. ptCallClient = ptLineClient->ptCallClients;
  348. while (ptCallClient)
  349. {
  350. lResult = SettCallClientEventMasks (
  351. ptCallClient,
  352. fSubMask,
  353. ulEventMasks,
  354. dwEventSubMasks
  355. );
  356. if (lResult)
  357. {
  358. goto ExitHere;
  359. }
  360. ptCallClient = ptCallClient->pNextSametLineClient;
  361. }
  362. ExitHere:
  363. UNLOCKTLINECLIENT (ptLineClient);
  364. return lResult;
  365. }
  366. //
  367. // SettLineAppEventMasks
  368. // Description:
  369. // Apply the masks or submasks on a tLineApp object.
  370. // Parameters:
  371. // ptLineApp : the tLineApp object to apply the masking
  372. // fSubMask : this function is called for submasks
  373. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  374. // whose submasks is to be set
  375. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  376. // Return Value:
  377. //
  378. LONG
  379. SettLineAppEventMasks (
  380. PTLINEAPP ptLineApp,
  381. BOOL fSubMask,
  382. ULONG64 ulEventMasks,
  383. DWORD dwEventSubMasks
  384. )
  385. {
  386. PTLINECLIENT ptLineClient;
  387. LONG lResult = S_OK;
  388. LOCKTLINEAPP (ptLineApp);
  389. if (ptLineApp->dwKey != TLINEAPP_KEY)
  390. {
  391. lResult = LINEERR_OPERATIONFAILED;
  392. goto ExitHere;
  393. }
  394. if (ptLineApp->dwAPIVersion <= TAPI_VERSION3_0)
  395. {
  396. lResult = LINEERR_OPERATIONUNAVAIL;
  397. goto ExitHere;
  398. }
  399. lResult = SetEventMasksOrSubMasks (
  400. fSubMask,
  401. ulEventMasks,
  402. dwEventSubMasks,
  403. ptLineApp->adwEventSubMasks
  404. );
  405. if (lResult)
  406. {
  407. goto ExitHere;
  408. }
  409. ptLineClient = ptLineApp->ptLineClients;
  410. while (ptLineClient)
  411. {
  412. lResult = SettLineClientEventMasks (
  413. ptLineClient,
  414. fSubMask,
  415. ulEventMasks,
  416. dwEventSubMasks
  417. );
  418. if (lResult)
  419. {
  420. goto ExitHere;
  421. }
  422. ptLineClient = ptLineClient->pNextSametLineApp;
  423. }
  424. ExitHere:
  425. UNLOCKTLINEAPP (ptLineApp);
  426. return lResult;
  427. }
  428. //
  429. // SettPhoneClientEventMasks
  430. // Description:
  431. // Apply the masks or submasks on a tPhoneClient object.
  432. // Parameters:
  433. // ptPhoneClient : the tPhoneClient object to apply the masking
  434. // fSubMask : this function is called for submasks
  435. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  436. // whose submasks is to be set
  437. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  438. // Return Value:
  439. //
  440. LONG
  441. SettPhoneClientEventMasks (
  442. PTPHONECLIENT ptPhoneClient,
  443. BOOL fSubMask,
  444. ULONG64 ulEventMasks,
  445. DWORD dwEventSubMasks
  446. )
  447. {
  448. LONG lResult = S_OK;
  449. LOCKTPHONECLIENT (ptPhoneClient);
  450. if (ptPhoneClient->dwKey != TPHONECLIENT_KEY)
  451. {
  452. lResult = PHONEERR_OPERATIONFAILED;
  453. goto ExitHere;
  454. }
  455. if (ptPhoneClient->ptPhoneApp->dwAPIVersion <= TAPI_VERSION3_0)
  456. {
  457. goto ExitHere;
  458. }
  459. lResult = SetEventMasksOrSubMasks (
  460. fSubMask,
  461. ulEventMasks,
  462. dwEventSubMasks,
  463. ptPhoneClient->adwEventSubMasks
  464. );
  465. ExitHere:
  466. UNLOCKTPHONECLIENT (ptPhoneClient);
  467. return lResult;
  468. }
  469. //
  470. // SettPhoneAppEventMasks
  471. // Description:
  472. // Apply the masks or submasks on a tPhoneApp object.
  473. // Parameters:
  474. // ptPhoneApp : the tPhoneApp object to apply the masking
  475. // fSubMask : this function is called for submasks
  476. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  477. // whose submasks is to be set
  478. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  479. // Return Value:
  480. //
  481. LONG
  482. SettPhoneAppEventMasks (
  483. PTPHONEAPP ptPhoneApp,
  484. BOOL fSubMask,
  485. ULONG64 ulEventMasks,
  486. DWORD dwEventSubMasks
  487. )
  488. {
  489. LONG lResult = S_OK;
  490. PTPHONECLIENT ptPhoneClient;
  491. LOCKTPHONEAPP (ptPhoneApp);
  492. if (ptPhoneApp->dwKey != TPHONEAPP_KEY)
  493. {
  494. lResult = PHONEERR_OPERATIONFAILED;
  495. goto ExitHere;
  496. }
  497. if (ptPhoneApp->dwAPIVersion <= TAPI_VERSION3_0)
  498. {
  499. lResult = PHONEERR_OPERATIONUNAVAIL;
  500. goto ExitHere;
  501. }
  502. lResult = SetEventMasksOrSubMasks (
  503. fSubMask,
  504. ulEventMasks,
  505. dwEventSubMasks,
  506. ptPhoneApp->adwEventSubMasks
  507. );
  508. if (lResult)
  509. {
  510. goto ExitHere;
  511. }
  512. ptPhoneClient = ptPhoneApp->ptPhoneClients;
  513. while (ptPhoneClient)
  514. {
  515. lResult = SettPhoneClientEventMasks (
  516. ptPhoneClient,
  517. fSubMask,
  518. ulEventMasks,
  519. dwEventSubMasks
  520. );
  521. if (lResult)
  522. {
  523. goto ExitHere;
  524. }
  525. ptPhoneClient = ptPhoneClient->pNextSametPhoneApp;
  526. }
  527. ExitHere:
  528. UNLOCKTPHONEAPP (ptPhoneApp);
  529. return lResult;
  530. }
  531. //
  532. // SettClientEventMasks
  533. // Description:
  534. // Apply the masks or submasks client wide.
  535. // Parameters:
  536. // ptClient : the client object to apply the masking
  537. // fSubMask : this function is called for submasks
  538. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  539. // whose submasks is to be set
  540. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  541. // Return Value:
  542. //
  543. LONG
  544. SettClientEventMasks (
  545. PTCLIENT ptClient,
  546. BOOL fSubMask,
  547. ULONG64 ulEventMasks,
  548. DWORD dwEventSubMasks
  549. )
  550. {
  551. LONG lResult = S_OK;
  552. PTLINEAPP ptLineApp;
  553. PTPHONEAPP ptPhoneApp;
  554. BOOL fLocked = TRUE;
  555. if (!WaitForExclusiveClientAccess (ptClient))
  556. {
  557. lResult = LINEERR_OPERATIONFAILED;
  558. fLocked = FALSE;
  559. goto ExitHere;
  560. }
  561. lResult = SetEventMasksOrSubMasks (
  562. fSubMask,
  563. ulEventMasks,
  564. dwEventSubMasks,
  565. ptClient->adwEventSubMasks
  566. );
  567. if (lResult)
  568. {
  569. goto ExitHere;
  570. }
  571. ptLineApp = ptClient->ptLineApps;
  572. while (ptLineApp)
  573. {
  574. lResult = SettLineAppEventMasks (
  575. ptLineApp,
  576. fSubMask,
  577. ulEventMasks,
  578. dwEventSubMasks
  579. );
  580. if (lResult)
  581. {
  582. goto ExitHere;
  583. }
  584. ptLineApp = ptLineApp->pNext;
  585. }
  586. ptPhoneApp = ptClient->ptPhoneApps;
  587. while (ptPhoneApp)
  588. {
  589. lResult = SettPhoneAppEventMasks (
  590. ptPhoneApp,
  591. fSubMask,
  592. ulEventMasks,
  593. dwEventSubMasks
  594. );
  595. if (lResult)
  596. {
  597. goto ExitHere;
  598. }
  599. ptPhoneApp = ptPhoneApp->pNext;
  600. }
  601. ExitHere:
  602. if (fLocked)
  603. {
  604. UNLOCKTCLIENT (ptClient);
  605. }
  606. return lResult;
  607. }
  608. //
  609. // SettClientEventMasks
  610. // Description:
  611. // Apply the masks or submasks server wide.
  612. // Parameters:
  613. // fSubMask : this function is called for submasks
  614. // ulEventMasks : the masks to be set if fSubMask is true or the mask
  615. // whose submasks is to be set
  616. // dwEventSubMasks : the submasks to be set, ignored if fSubMask is FALSE
  617. // Return Value:
  618. //
  619. LONG
  620. SetGlobalEventMasks (
  621. BOOL fSubMask,
  622. ULONG64 ulEventMasks,
  623. DWORD dwEventSubMasks
  624. )
  625. {
  626. LONG lResult = S_OK;
  627. PTCLIENT ptClient;
  628. TapiEnterCriticalSection (&TapiGlobals.CritSec);
  629. ptClient = TapiGlobals.ptClients;
  630. while (ptClient)
  631. {
  632. lResult = SettClientEventMasks (
  633. ptClient,
  634. fSubMask,
  635. ulEventMasks,
  636. dwEventSubMasks
  637. );
  638. if (lResult)
  639. {
  640. goto ExitHere;
  641. }
  642. ptClient = ptClient->pNext;
  643. }
  644. ExitHere:
  645. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  646. return lResult;
  647. }
  648. //
  649. // TSetEventMasksOrSubMasks
  650. // Description:
  651. // The RPC function used for seting Masks/SubMasks on various different
  652. // types of objects
  653. // Parameters:
  654. // Return Value:
  655. //
  656. void
  657. WINAPI
  658. TSetEventMasksOrSubMasks (
  659. PTCLIENT ptClient,
  660. PTSETEVENTMASK_PARAMS pParams,
  661. DWORD dwParamsBufferSize,
  662. LPBYTE pDataBuf,
  663. LPDWORD pdwNumBytesReturned
  664. )
  665. {
  666. ULONG64 ulEventMasks;
  667. // Assemble the two DWORD into 64 bit masks
  668. ulEventMasks = pParams->dwHiMasks;
  669. ulEventMasks <<= 32;
  670. ulEventMasks |= pParams->dwLowMasks;
  671. // Mask sure we do not violate the permissible mask setting
  672. TapiEnterCriticalSection (&TapiGlobals.CritSec);
  673. if (ulEventMasks & (~TapiGlobals.ulPermMasks))
  674. {
  675. pParams->lResult = LINEERR_INVALPARAM;
  676. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  677. goto ExitHere;
  678. }
  679. // Call the corresponding function to apply masking on different
  680. // type of objects
  681. switch (pParams->dwObjType)
  682. {
  683. case TAPIOBJ_NULL:
  684. {
  685. pParams->lResult = (LONG) SettClientEventMasks (
  686. ptClient,
  687. pParams->fSubMask,
  688. ulEventMasks,
  689. pParams->dwEventSubMasks
  690. );
  691. }
  692. break;
  693. case TAPIOBJ_HLINEAPP:
  694. {
  695. PTLINEAPP ptLineApp;
  696. ptLineApp = ReferenceObject (
  697. ghHandleTable,
  698. pParams->hLineApp,
  699. TLINEAPP_KEY
  700. );
  701. if (ptLineApp)
  702. {
  703. pParams->lResult = (LONG) SettLineAppEventMasks (
  704. ptLineApp,
  705. pParams->fSubMask,
  706. ulEventMasks,
  707. pParams->dwEventSubMasks
  708. );
  709. DereferenceObject (
  710. ghHandleTable,
  711. pParams->hLineApp,
  712. 1
  713. );
  714. }
  715. else
  716. {
  717. pParams->lResult = LINEERR_INVALAPPHANDLE;
  718. }
  719. }
  720. break;
  721. case TAPIOBJ_HPHONEAPP:
  722. {
  723. PTPHONEAPP ptPhoneApp;
  724. ptPhoneApp = ReferenceObject (
  725. ghHandleTable,
  726. pParams->hPhoneApp,
  727. TPHONEAPP_KEY
  728. );
  729. if (ptPhoneApp)
  730. {
  731. pParams->lResult = (LONG) SettPhoneAppEventMasks (
  732. ptPhoneApp,
  733. pParams->fSubMask,
  734. ulEventMasks,
  735. pParams->dwEventSubMasks
  736. );
  737. DereferenceObject (
  738. ghHandleTable,
  739. pParams->hPhoneApp,
  740. 1
  741. );
  742. }
  743. else
  744. {
  745. pParams->lResult = PHONEERR_INVALAPPHANDLE;
  746. }
  747. }
  748. break;
  749. case TAPIOBJ_HLINE:
  750. {
  751. PTLINECLIENT ptLineClient;
  752. ptLineClient = ReferenceObject (
  753. ghHandleTable,
  754. pParams->hLine,
  755. TLINECLIENT_KEY
  756. );
  757. if (ptLineClient)
  758. {
  759. pParams->lResult = (LONG) SettLineClientEventMasks (
  760. ptLineClient,
  761. pParams->fSubMask,
  762. ulEventMasks,
  763. pParams->dwEventSubMasks
  764. );
  765. DereferenceObject (
  766. ghHandleTable,
  767. pParams->hLine,
  768. 1
  769. );
  770. }
  771. else
  772. {
  773. pParams->lResult = LINEERR_INVALLINEHANDLE;
  774. }
  775. }
  776. break;
  777. case TAPIOBJ_HCALL:
  778. {
  779. PTCALLCLIENT ptCallClient;
  780. ptCallClient = ReferenceObject (
  781. ghHandleTable,
  782. pParams->hCall,
  783. TCALLCLIENT_KEY
  784. );
  785. if (ptCallClient)
  786. {
  787. pParams->lResult = (LONG) SettCallClientEventMasks (
  788. ptCallClient,
  789. pParams->fSubMask,
  790. ulEventMasks,
  791. pParams->dwEventSubMasks
  792. );
  793. DereferenceObject (
  794. ghHandleTable,
  795. pParams->hCall,
  796. 1
  797. );
  798. }
  799. else
  800. {
  801. pParams->lResult = LINEERR_INVALCALLHANDLE;
  802. }
  803. }
  804. break;
  805. case TAPIOBJ_HPHONE:
  806. {
  807. PTPHONECLIENT ptPhoneClient;
  808. ptPhoneClient = ReferenceObject (
  809. ghHandleTable,
  810. pParams->hPhone,
  811. TPHONECLIENT_KEY
  812. );
  813. if (ptPhoneClient)
  814. {
  815. pParams->lResult = (LONG) SettPhoneClientEventMasks (
  816. ptPhoneClient,
  817. pParams->fSubMask,
  818. ulEventMasks,
  819. pParams->dwEventSubMasks
  820. );
  821. DereferenceObject (
  822. ghHandleTable,
  823. pParams->hPhone,
  824. 1
  825. );
  826. }
  827. else
  828. {
  829. pParams->lResult = PHONEERR_INVALPHONEHANDLE;
  830. }
  831. }
  832. break;
  833. default:
  834. pParams->lResult = LINEERR_OPERATIONFAILED;
  835. break;
  836. }
  837. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  838. ExitHere:
  839. *pdwNumBytesReturned = sizeof (TSETEVENTMASK_PARAMS);
  840. }
  841. //
  842. // GetEventsMasksOrSubMasks
  843. // Description:
  844. // Utility function used by TGetEventMasksOrSubMasks to retrieve
  845. // Masks/SubMasks from various Tapisrv objects
  846. // Parameters:
  847. // fSubMask Masks or SubMasks are to be retrieved
  848. // ulEventMasksIn Indicates which submask to get if fSubMask
  849. // pulEventMasksOut Hold the returned masks if(!fSubMask),
  850. // corresponding bit is set as long as at least
  851. // one submask bit is set
  852. // pdwEventSubMasksOut Hold the returned submask if(fSubMask)
  853. // adwEventSubMasks the submasks array to work on
  854. // Return Value:
  855. //
  856. LONG
  857. GetEventMasksOrSubMasks (
  858. BOOL fSubMask,
  859. ULONG64 ulEventMasksIn, // Needs to be set if fSubMask
  860. ULONG64 *pulEventMasksOut,
  861. DWORD *pdwEventSubMasksOut,
  862. DWORD *adwEventSubMasks
  863. )
  864. {
  865. DWORD dwIndex;
  866. ULONG64 ulMask;
  867. if (NULL == adwEventSubMasks ||
  868. NULL == pulEventMasksOut ||
  869. NULL == pdwEventSubMasksOut)
  870. {
  871. ASSERT (0);
  872. return LINEERR_INVALPOINTER;
  873. }
  874. if (fSubMask)
  875. {
  876. ASSERT (pdwEventSubMasksOut != NULL);
  877. ASSERT (ulEventMasksIn != 0 &&
  878. (ulEventMasksIn & (ulEventMasksIn - 1)) == 0);
  879. *pdwEventSubMasksOut =
  880. adwEventSubMasks[GetSubMaskIndex(ulEventMasksIn)];
  881. }
  882. else
  883. {
  884. ASSERT (pulEventMasksOut);
  885. ulMask = 1;
  886. *pulEventMasksOut = 0;
  887. for (dwIndex = 0; dwIndex < EM_NUM_MASKS; ++dwIndex)
  888. {
  889. if (adwEventSubMasks[dwIndex])
  890. {
  891. *pulEventMasksOut |= ulMask;
  892. }
  893. ulMask <<= 1;
  894. }
  895. }
  896. return S_OK;
  897. }
  898. //
  899. // TGetEventMasksOrSubMasks
  900. // Description:
  901. // The RPC function used for geting Masks/SubMasks on various different
  902. // types of objects
  903. // Parameters:
  904. // Return Value:
  905. //
  906. void
  907. WINAPI
  908. TGetEventMasksOrSubMasks (
  909. PTCLIENT ptClient,
  910. PTGETEVENTMASK_PARAMS pParams,
  911. DWORD dwParamsBufferSize,
  912. LPBYTE pDataBuf,
  913. LPDWORD pdwNumBytesReturned
  914. )
  915. {
  916. ULONG64 ulEventMasksIn;
  917. ULONG64 ulEventMasksOut;
  918. // Assember the 64 bit mask from the two DWORD
  919. if (pParams->fSubMask)
  920. {
  921. ulEventMasksIn = pParams->dwHiMasksIn;
  922. ulEventMasksIn <<= 32;
  923. ulEventMasksIn += pParams->dwLowMasksIn;
  924. }
  925. TapiEnterCriticalSection (&TapiGlobals.CritSec);
  926. // Retrieve the masking from various objects by calling
  927. // the corresponding functions
  928. switch (pParams->dwObjType)
  929. {
  930. case TAPIOBJ_NULL:
  931. {
  932. if (WaitForExclusiveClientAccess (ptClient))
  933. {
  934. pParams->lResult = (LONG) GetEventMasksOrSubMasks (
  935. pParams->fSubMask,
  936. ulEventMasksIn,
  937. &ulEventMasksOut,
  938. &pParams->dwEventSubMasks,
  939. ptClient->adwEventSubMasks
  940. );
  941. UNLOCKTCLIENT (ptClient);
  942. }
  943. else
  944. {
  945. pParams->lResult = LINEERR_INVALPARAM;
  946. }
  947. }
  948. break;
  949. case TAPIOBJ_HLINEAPP:
  950. {
  951. PTLINEAPP ptLineApp;
  952. ptLineApp = ReferenceObject (
  953. ghHandleTable,
  954. pParams->hLineApp,
  955. TLINEAPP_KEY
  956. );
  957. if (ptLineApp && ptLineApp->dwKey == TLINEAPP_KEY)
  958. {
  959. LOCKTLINEAPP (ptLineApp);
  960. pParams->lResult = GetEventMasksOrSubMasks (
  961. pParams->fSubMask,
  962. ulEventMasksIn,
  963. &ulEventMasksOut,
  964. &pParams->dwEventSubMasks,
  965. ptLineApp->adwEventSubMasks
  966. );
  967. UNLOCKTLINEAPP (ptLineApp);
  968. DereferenceObject (
  969. ghHandleTable,
  970. pParams->hLineApp,
  971. 1
  972. );
  973. }
  974. else
  975. {
  976. pParams->lResult = LINEERR_INVALAPPHANDLE;
  977. }
  978. }
  979. break;
  980. case TAPIOBJ_HPHONEAPP:
  981. {
  982. PTPHONEAPP ptPhoneApp;
  983. ptPhoneApp = ReferenceObject (
  984. ghHandleTable,
  985. pParams->hPhoneApp,
  986. TPHONEAPP_KEY
  987. );
  988. if (ptPhoneApp && ptPhoneApp->dwKey == TPHONEAPP_KEY)
  989. {
  990. LOCKTPHONEAPP (ptPhoneApp);
  991. pParams->lResult = GetEventMasksOrSubMasks (
  992. pParams->fSubMask,
  993. ulEventMasksIn,
  994. &ulEventMasksOut,
  995. &pParams->dwEventSubMasks,
  996. ptPhoneApp->adwEventSubMasks
  997. );
  998. UNLOCKTPHONEAPP (ptPhoneApp);
  999. DereferenceObject (
  1000. ghHandleTable,
  1001. pParams->hPhoneApp,
  1002. 1
  1003. );
  1004. }
  1005. else
  1006. {
  1007. pParams->lResult = PHONEERR_INVALAPPHANDLE;
  1008. }
  1009. }
  1010. break;
  1011. case TAPIOBJ_HLINE:
  1012. {
  1013. PTLINECLIENT ptLineClient;
  1014. ptLineClient = ReferenceObject (
  1015. ghHandleTable,
  1016. pParams->hLine,
  1017. TLINECLIENT_KEY
  1018. );
  1019. if (ptLineClient && ptLineClient->dwKey == TLINECLIENT_KEY)
  1020. {
  1021. LOCKTLINECLIENT (ptLineClient);
  1022. pParams->lResult = GetEventMasksOrSubMasks (
  1023. pParams->fSubMask,
  1024. ulEventMasksIn,
  1025. &ulEventMasksOut,
  1026. &pParams->dwEventSubMasks,
  1027. ptLineClient->adwEventSubMasks
  1028. );
  1029. UNLOCKTLINECLIENT (ptLineClient);
  1030. DereferenceObject (
  1031. ghHandleTable,
  1032. pParams->hLine,
  1033. 1
  1034. );
  1035. }
  1036. else
  1037. {
  1038. pParams->lResult = LINEERR_INVALLINEHANDLE;
  1039. }
  1040. }
  1041. break;
  1042. case TAPIOBJ_HCALL:
  1043. {
  1044. PTCALLCLIENT ptCallClient;
  1045. ptCallClient = ReferenceObject (
  1046. ghHandleTable,
  1047. pParams->hCall,
  1048. TCALLCLIENT_KEY
  1049. );
  1050. if (ptCallClient && ptCallClient->dwKey == TCALLCLIENT_KEY)
  1051. {
  1052. LOCKTLINECLIENT (ptCallClient);
  1053. pParams->lResult = GetEventMasksOrSubMasks (
  1054. pParams->fSubMask,
  1055. ulEventMasksIn,
  1056. &ulEventMasksOut,
  1057. &pParams->dwEventSubMasks,
  1058. ptCallClient->adwEventSubMasks
  1059. );
  1060. UNLOCKTLINECLIENT (ptCallClient);
  1061. DereferenceObject (
  1062. ghHandleTable,
  1063. pParams->hCall,
  1064. 1
  1065. );
  1066. }
  1067. else
  1068. {
  1069. pParams->lResult = LINEERR_INVALCALLHANDLE;
  1070. }
  1071. }
  1072. break;
  1073. case TAPIOBJ_HPHONE:
  1074. {
  1075. PTPHONECLIENT ptPhoneClient;
  1076. ptPhoneClient = ReferenceObject (
  1077. ghHandleTable,
  1078. pParams->hPhone,
  1079. TPHONECLIENT_KEY
  1080. );
  1081. if (ptPhoneClient && ptPhoneClient->dwKey == TPHONECLIENT_KEY)
  1082. {
  1083. LOCKTPHONECLIENT (ptPhoneClient);
  1084. pParams->lResult = GetEventMasksOrSubMasks (
  1085. pParams->fSubMask,
  1086. ulEventMasksIn,
  1087. &ulEventMasksOut,
  1088. &pParams->dwEventSubMasks,
  1089. ptPhoneClient->adwEventSubMasks
  1090. );
  1091. UNLOCKTPHONECLIENT (ptPhoneClient);
  1092. DereferenceObject (
  1093. ghHandleTable,
  1094. pParams->hPhone,
  1095. 1
  1096. );
  1097. }
  1098. else
  1099. {
  1100. pParams->lResult = PHONEERR_INVALPHONEHANDLE;
  1101. }
  1102. }
  1103. break;
  1104. default:
  1105. pParams->lResult = LINEERR_OPERATIONFAILED;
  1106. break;
  1107. }
  1108. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  1109. // Seperating the returned 64 bit masks into two DWORD for RPC purpose
  1110. if (pParams->lResult == 0 && !pParams->fSubMask)
  1111. {
  1112. pParams->dwLowMasksOut = (DWORD)(ulEventMasksOut & 0xffffffff);
  1113. pParams->dwHiMasksOut = (DWORD)(ulEventMasksOut >> 32);
  1114. }
  1115. *pdwNumBytesReturned = sizeof (TGETEVENTMASK_PARAMS);
  1116. }
  1117. //
  1118. // TSetPermissibleMasks
  1119. // Description:
  1120. // Set the global PermissibleMasks, this operation is only
  1121. // allowed for admins
  1122. // Parameters:
  1123. // Return Value:
  1124. //
  1125. void
  1126. WINAPI
  1127. TSetPermissibleMasks (
  1128. PTCLIENT ptClient,
  1129. PTSETPERMMASKS_PARAMS pParams,
  1130. DWORD dwParamsBufferSize,
  1131. LPBYTE pDataBuf,
  1132. LPDWORD pdwNumBytesReturned
  1133. )
  1134. {
  1135. BOOL bAdmin;
  1136. ULONG64 ulPermMasks;
  1137. // Check the Admin status
  1138. LOCKTCLIENT (ptClient);
  1139. bAdmin = IS_FLAG_SET(ptClient->dwFlags, PTCLIENT_FLAG_ADMINISTRATOR);
  1140. UNLOCKTCLIENT (ptClient);
  1141. // Allow the operation to go ahead if the caller is an Admin or
  1142. // this machine is not configured to function as a server
  1143. if (!(TapiGlobals.dwFlags & TAPIGLOBALS_SERVER) || bAdmin)
  1144. {
  1145. ulPermMasks = pParams->dwHiMasks;
  1146. ulPermMasks <<= 32;
  1147. ulPermMasks += pParams->dwLowMasks;
  1148. TapiEnterCriticalSection (&TapiGlobals.CritSec);
  1149. TapiGlobals.ulPermMasks = ulPermMasks & EM_ALL;
  1150. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  1151. pParams->lResult = (LONG) SetGlobalEventMasks (
  1152. FALSE,
  1153. ulPermMasks,
  1154. 0
  1155. );
  1156. }
  1157. else
  1158. {
  1159. pParams->lResult = TAPIERR_NOTADMIN;
  1160. }
  1161. *pdwNumBytesReturned = sizeof (TSETPERMMASKS_PARAMS);
  1162. return;
  1163. }
  1164. //
  1165. // TGetPermissibleMasks
  1166. // Description:
  1167. // Get the global PermissibleMasks
  1168. // Parameters:
  1169. // Return Value:
  1170. //
  1171. void
  1172. WINAPI
  1173. TGetPermissibleMasks (
  1174. PTCLIENT ptClient,
  1175. PTGETPERMMASKS_PARAMS pParams,
  1176. DWORD dwParamsBufferSize,
  1177. LPBYTE pDataBuf,
  1178. LPDWORD pdwNumBytesReturned
  1179. )
  1180. {
  1181. TapiEnterCriticalSection (&TapiGlobals.CritSec);
  1182. pParams->dwLowMasks = (DWORD)(TapiGlobals.ulPermMasks & 0xffffffff);
  1183. pParams->dwHiMasks = (DWORD)(TapiGlobals.ulPermMasks >> 32);
  1184. TapiLeaveCriticalSection (&TapiGlobals.CritSec);
  1185. *pdwNumBytesReturned = sizeof (TGETPERMMASKS_PARAMS);
  1186. }