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.

1743 lines
51 KiB

  1. #include "precomp.h"
  2. #include "t120app.h"
  3. BOOL InitAppletSDK(void)
  4. {
  5. CheckStructCompatible();
  6. return TRUE;
  7. }
  8. void CleanupAppletSDK(void)
  9. {
  10. }
  11. void CALLBACK T120AppletSessionCallback
  12. (
  13. T120AppletSessionMsg *pMsg
  14. )
  15. {
  16. CNmAppletSession *pSession = (CNmAppletSession *) pMsg->pSessionContext;
  17. if (NULL != pSession)
  18. {
  19. pSession->T120Callback(pMsg);
  20. }
  21. }
  22. void CALLBACK T120AppletCallback
  23. (
  24. T120AppletMsg *pMsg
  25. )
  26. {
  27. CNmAppletObj *pApplet = (CNmAppletObj *) pMsg->pAppletContext;
  28. if (NULL != pApplet)
  29. {
  30. pApplet->T120Callback(pMsg);
  31. }
  32. }
  33. //////////////////////////////////////////////////
  34. //
  35. // CNmAppletSession
  36. //
  37. CNmAppletSession::CNmAppletSession
  38. (
  39. CNmAppletObj *pApplet,
  40. IT120AppletSession *pSession,
  41. BOOL fAutoJoin
  42. )
  43. :
  44. m_cRef(1),
  45. m_pApplet(pApplet),
  46. m_pT120SessReq(NULL),
  47. m_pT120Session(pSession),
  48. m_pNotify(NULL),
  49. m_fAutoJoin(fAutoJoin)
  50. {
  51. m_pApplet->AddRef();
  52. pSession->Advise(T120AppletSessionCallback, m_pApplet, this);
  53. }
  54. CNmAppletSession::~CNmAppletSession(void)
  55. {
  56. ASSERT(0 == m_cRef);
  57. m_pApplet->Release();
  58. if (NULL != m_pT120Session)
  59. {
  60. m_pT120Session->ReleaseInterface();
  61. m_pT120Session = NULL;
  62. }
  63. }
  64. //////////////////////////////////////////////////
  65. //
  66. // IUnknown @ CNmAppletSession
  67. //
  68. HRESULT CNmAppletSession::QueryInterface
  69. (
  70. REFIID riid,
  71. void **ppv
  72. )
  73. {
  74. if (NULL != ppv)
  75. {
  76. *ppv = NULL;
  77. if (riid == IID_IAppletSession || riid == IID_IUnknown)
  78. {
  79. *ppv = (IAppletSession *) this;
  80. AddRef();
  81. return S_OK;
  82. }
  83. return E_NOINTERFACE;
  84. }
  85. return E_POINTER;
  86. }
  87. ULONG CNmAppletSession::AddRef(void)
  88. {
  89. ::InterlockedIncrement(&m_cRef);
  90. return (ULONG) m_cRef;
  91. }
  92. ULONG CNmAppletSession::Release(void)
  93. {
  94. ASSERT(m_cRef > 0);
  95. if (::InterlockedDecrement(&m_cRef) == 0)
  96. {
  97. delete this;
  98. return 0;
  99. }
  100. return (ULONG) m_cRef;
  101. }
  102. //////////////////////////////////////////////////
  103. //
  104. // Basic Info @ CNmAppletSession
  105. //
  106. HRESULT CNmAppletSession::GetConfID
  107. (
  108. AppletConfID *pnConfID
  109. )
  110. {
  111. if (NULL != m_pT120Session)
  112. {
  113. *pnConfID = m_pT120Session->GetConfID();
  114. return S_OK;
  115. }
  116. return APPLET_E_NO_SERVICE;
  117. }
  118. HRESULT CNmAppletSession::IsThisNodeTopProvider
  119. (
  120. BOOL *pfTopProvider
  121. )
  122. {
  123. if (NULL != m_pT120Session)
  124. {
  125. *pfTopProvider = m_pT120Session->IsThisNodeTopProvider();
  126. return S_OK;
  127. }
  128. return APPLET_E_NO_SERVICE;
  129. }
  130. //////////////////////////////////////////////////
  131. //
  132. // Join Conference @ CNmAppletSession
  133. //
  134. HRESULT CNmAppletSession::Join
  135. (
  136. AppletSessionRequest *pRequest
  137. )
  138. {
  139. if (NULL != m_pNotify)
  140. {
  141. if (NULL != m_pT120Session)
  142. {
  143. if (NULL == m_pT120SessReq)
  144. {
  145. m_pT120SessReq = ::AllocateJoinSessionRequest(pRequest);
  146. if (NULL != m_pT120SessReq)
  147. {
  148. T120Error rc = m_pT120Session->Join(m_pT120SessReq);
  149. ASSERT(T120_NO_ERROR == rc);
  150. if (T120_NO_ERROR == rc)
  151. {
  152. return S_OK;
  153. }
  154. ::FreeJoinSessionRequest(m_pT120SessReq);
  155. m_pT120SessReq = NULL;
  156. return APPLET_E_SERVICE_FAIL;
  157. }
  158. return APPLET_E_INVALID_JOIN_REQUEST;
  159. }
  160. return APPLET_E_ALREADY_JOIN;
  161. }
  162. return APPLET_E_NO_SERVICE;
  163. }
  164. return APPLET_E_NOT_ADVISED;
  165. }
  166. HRESULT CNmAppletSession::Leave(void)
  167. {
  168. if (NULL != m_pT120Session)
  169. {
  170. if (m_fAutoJoin)
  171. {
  172. m_pT120Session->Leave();
  173. m_fAutoJoin = FALSE;
  174. return S_OK;
  175. }
  176. else
  177. if (NULL != m_pT120SessReq)
  178. {
  179. m_pT120Session->Leave();
  180. ::FreeJoinSessionRequest(m_pT120SessReq);
  181. m_pT120SessReq = NULL;
  182. return S_OK;
  183. }
  184. return APPLET_E_NOT_JOINED;
  185. }
  186. return APPLET_E_NO_SERVICE;
  187. }
  188. //////////////////////////////////////////////////
  189. //
  190. // Send Data @ CNmAppletSession
  191. //
  192. HRESULT CNmAppletSession::SendData
  193. (
  194. BOOL fUniformSend,
  195. AppletChannelID nChannelID,
  196. AppletPriority ePriority,
  197. ULONG cbBufSize,
  198. BYTE *pBuffer // size_is(cbBufSize)
  199. )
  200. {
  201. if (NULL != m_pT120Session)
  202. {
  203. if (cbBufSize && NULL != pBuffer)
  204. {
  205. T120Error rc = m_pT120Session->SendData(
  206. fUniformSend ? UNIFORM_SEND_DATA : NORMAL_SEND_DATA,
  207. nChannelID,
  208. ePriority,
  209. pBuffer,
  210. cbBufSize,
  211. APP_ALLOCATION);
  212. ASSERT(T120_NO_ERROR == rc);
  213. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  214. }
  215. return E_INVALIDARG;
  216. }
  217. return APPLET_E_NO_SERVICE;
  218. }
  219. //////////////////////////////////////////////////
  220. //
  221. // Invoke Applet @ CNmAppletSession
  222. //
  223. HRESULT CNmAppletSession::InvokeApplet
  224. (
  225. AppletRequestTag *pnReqTag,
  226. AppletProtocolEntity *pAPE,
  227. ULONG cNodes,
  228. AppletNodeID aNodeIDs[] // size_is(cNodes)
  229. )
  230. {
  231. if (NULL != m_pNotify)
  232. {
  233. if (NULL != m_pT120Session)
  234. {
  235. if (NULL != pAPE && NULL != pnReqTag)
  236. {
  237. // set up node list
  238. GCCSimpleNodeList NodeList;
  239. NodeList.cNodes = cNodes;
  240. NodeList.aNodeIDs = aNodeIDs;
  241. // set up ape list
  242. GCCAppProtEntityList APEList;
  243. APEList.cApes = 1;
  244. APEList.apApes = (T120APE **) &pAPE;
  245. T120Error rc = m_pT120Session->InvokeApplet(&APEList, &NodeList, pnReqTag);
  246. ASSERT(T120_NO_ERROR == rc);
  247. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  248. }
  249. return E_POINTER;
  250. }
  251. return APPLET_E_NO_SERVICE;
  252. }
  253. return APPLET_E_NOT_ADVISED;
  254. }
  255. //////////////////////////////////////////////////
  256. //
  257. // Inquiry @ CNmAppletSession
  258. //
  259. HRESULT CNmAppletSession::InquireRoster
  260. (
  261. AppletSessionKey *pSessionKey
  262. )
  263. {
  264. if (NULL != m_pNotify)
  265. {
  266. if (NULL != m_pT120Session)
  267. {
  268. T120Error rc = m_pT120Session->InquireRoster((T120SessionKey *) pSessionKey);
  269. ASSERT(T120_NO_ERROR == rc);
  270. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  271. }
  272. return APPLET_E_NO_SERVICE;
  273. }
  274. return APPLET_E_NOT_ADVISED;
  275. }
  276. //////////////////////////////////////////////////
  277. //
  278. // Registry Services @ CNmAppletSession
  279. //
  280. HRESULT CNmAppletSession::RegistryRequest
  281. (
  282. AppletRegistryRequest *pRequest
  283. )
  284. {
  285. if (NULL != m_pNotify)
  286. {
  287. if (NULL != m_pT120Session)
  288. {
  289. T120RegistryRequest reg_req;
  290. ::AppletRegistryRequestToT120One(pRequest, &reg_req);
  291. T120Error rc = m_pT120Session->RegistryRequest(&reg_req);
  292. ASSERT(T120_NO_ERROR == rc);
  293. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  294. }
  295. return APPLET_E_NO_SERVICE;
  296. }
  297. return APPLET_E_NOT_ADVISED;
  298. }
  299. //////////////////////////////////////////////////
  300. //
  301. // Channel Services @ CNmAppletSession
  302. //
  303. HRESULT CNmAppletSession::ChannelRequest
  304. (
  305. AppletChannelRequest *pRequest
  306. )
  307. {
  308. if (NULL != m_pNotify)
  309. {
  310. if (NULL != m_pT120Session)
  311. {
  312. T120Error rc = m_pT120Session->ChannelRequest((T120ChannelRequest *) pRequest);
  313. ASSERT(T120_NO_ERROR == rc);
  314. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  315. }
  316. return APPLET_E_NO_SERVICE;
  317. }
  318. return APPLET_E_NOT_ADVISED;
  319. }
  320. //////////////////////////////////////////////////
  321. //
  322. // Token Services @ CNmAppletSession
  323. //
  324. HRESULT CNmAppletSession::TokenRequest
  325. (
  326. AppletTokenRequest *pRequest
  327. )
  328. {
  329. if (NULL != m_pNotify)
  330. {
  331. if (NULL != m_pT120Session)
  332. {
  333. T120Error rc = m_pT120Session->TokenRequest((T120TokenRequest *) pRequest);
  334. ASSERT(T120_NO_ERROR == rc);
  335. return (T120_NO_ERROR == rc) ? S_OK : APPLET_E_SERVICE_FAIL;
  336. }
  337. return APPLET_E_NO_SERVICE;
  338. }
  339. return APPLET_E_NOT_ADVISED;
  340. }
  341. //////////////////////////////////////////////////
  342. //
  343. // Notification @ CNmAppletSession
  344. //
  345. HRESULT CNmAppletSession::Advise
  346. (
  347. IAppletSessionNotify *pNotify,
  348. DWORD *pdwCookie
  349. )
  350. {
  351. if (NULL != m_pT120Session)
  352. {
  353. if (NULL == m_pNotify)
  354. {
  355. if (NULL != pNotify && NULL != pdwCookie)
  356. {
  357. pNotify->AddRef();
  358. m_pNotify = pNotify;
  359. m_pSessionObj = this;
  360. *pdwCookie = 1;
  361. return S_OK;
  362. }
  363. return E_POINTER;
  364. }
  365. return APPLET_E_ALREADY_ADVISED;
  366. }
  367. return APPLET_E_NO_SERVICE;
  368. }
  369. HRESULT CNmAppletSession::UnAdvise
  370. (
  371. DWORD dwCookie
  372. )
  373. {
  374. if (NULL != m_pT120Session)
  375. {
  376. if (NULL != m_pNotify)
  377. {
  378. if (dwCookie == 1 && m_pSessionObj == this)
  379. {
  380. m_pNotify->Release();
  381. m_pNotify = NULL;
  382. return S_OK;
  383. }
  384. return APPLET_E_INVALID_COOKIE;
  385. }
  386. return APPLET_E_NOT_ADVISED;
  387. }
  388. return APPLET_E_NO_SERVICE;
  389. }
  390. //////////////////////////////////////////////////
  391. //
  392. // T120 Applet Session Callback @ CNmAppletSession
  393. //
  394. void CNmAppletSession::T120Callback
  395. (
  396. T120AppletSessionMsg *pMsg
  397. )
  398. {
  399. HRESULT hrNotify;
  400. HRESULT hrResult;
  401. IAppletSession *pAppletSession;
  402. T120ChannelID *aChannelIDs;
  403. AppletOctetString ostr;
  404. AppletRegistryCommand eRegistryCommand;
  405. AppletTokenCommand eTokenCommand;
  406. AppletRegistryItem RegItem;
  407. AppletRegistryItem *pRegItem;
  408. AppletRegistryEntryOwner EntryOwner;
  409. if (NULL != m_pNotify)
  410. {
  411. switch (pMsg->eMsgType)
  412. {
  413. //
  414. // Join Session
  415. //
  416. case T120_JOIN_SESSION_CONFIRM:
  417. hrResult = APPLET_E_SERVICE_FAIL;
  418. pAppletSession = NULL;
  419. aChannelIDs = NULL;
  420. if (T120_RESULT_SUCCESSFUL == pMsg->JoinSessionConfirm.eResult &&
  421. T120_NO_ERROR == pMsg->JoinSessionConfirm.eError)
  422. {
  423. hrResult = S_OK;
  424. if (pMsg->JoinSessionConfirm.cResourceReqs)
  425. {
  426. aChannelIDs = new T120ChannelID[pMsg->JoinSessionConfirm.cResourceReqs];
  427. if (NULL != aChannelIDs)
  428. {
  429. for (ULONG i = 0; i < pMsg->JoinSessionConfirm.cResourceReqs; i++)
  430. {
  431. aChannelIDs[i] = pMsg->JoinSessionConfirm.aResourceReqs[i].nChannelID;
  432. }
  433. }
  434. else
  435. {
  436. ASSERT(NULL != aChannelIDs);
  437. hrResult = E_OUTOFMEMORY;
  438. }
  439. }
  440. }
  441. if (S_OK == hrResult)
  442. {
  443. hrNotify = m_pNotify->JoinSessionConfirm(
  444. hrResult,
  445. pMsg->JoinSessionConfirm.uidMyself,
  446. pMsg->JoinSessionConfirm.nidMyself,
  447. pMsg->JoinSessionConfirm.sidMyself,
  448. pMsg->JoinSessionConfirm.eidMyself,
  449. pMsg->JoinSessionConfirm.cResourceReqs,
  450. aChannelIDs);
  451. ASSERT(SUCCEEDED(hrNotify));
  452. }
  453. else
  454. {
  455. hrNotify = m_pNotify->JoinSessionConfirm(hrResult, 0, 0, 0, 0, 0, NULL);
  456. ASSERT(SUCCEEDED(hrNotify));
  457. }
  458. delete [] aChannelIDs;
  459. break;
  460. //
  461. // Detach User
  462. //
  463. case MCS_DETACH_USER_INDICATION:
  464. hrNotify = m_pNotify->LeaveSessionIndication(::GetAppletReason(pMsg->DetachUserInd.eReason),
  465. pMsg->DetachUserInd.nUserID);
  466. ASSERT(SUCCEEDED(hrNotify));
  467. break;
  468. //
  469. // Send Data
  470. //
  471. case MCS_SEND_DATA_INDICATION:
  472. case MCS_UNIFORM_SEND_DATA_INDICATION:
  473. ostr.cbStrSize = pMsg->SendDataInd.user_data.length;
  474. ostr.pbValue = pMsg->SendDataInd.user_data.value;
  475. hrNotify = m_pNotify->SendDataIndication(MCS_UNIFORM_SEND_DATA_INDICATION == pMsg->eMsgType,
  476. pMsg->SendDataInd.initiator,
  477. pMsg->SendDataInd.channel_id,
  478. (AppletPriority) pMsg->SendDataInd.data_priority,
  479. ostr);
  480. ASSERT(SUCCEEDED(hrNotify));
  481. break;
  482. //
  483. // Roster
  484. //
  485. case GCC_APP_ROSTER_REPORT_INDICATION:
  486. hrNotify = m_pNotify->RosterReportIndication((ULONG) pMsg->AppRosterReportInd.cRosters,
  487. (AppletRoster **) pMsg->AppRosterReportInd.apAppRosters);
  488. ASSERT(SUCCEEDED(hrNotify));
  489. break;
  490. case GCC_APP_ROSTER_INQUIRE_CONFIRM:
  491. hrNotify = m_pNotify->InquireRosterConfirm(::GetHrResult(pMsg->AppRosterInquireConfirm.nResult),
  492. (ULONG) pMsg->AppRosterInquireConfirm.cRosters,
  493. (AppletRoster **) pMsg->AppRosterInquireConfirm.apAppRosters);
  494. ASSERT(SUCCEEDED(hrNotify));
  495. break;
  496. //
  497. // Applet Invoke
  498. //
  499. case GCC_APPLICATION_INVOKE_CONFIRM:
  500. hrNotify = m_pNotify->InvokeAppletConfirm(pMsg->AppInvokeConfirm.nReqTag,
  501. ::GetHrResult(pMsg->AppInvokeConfirm.nResult));
  502. ASSERT(SUCCEEDED(hrNotify));
  503. break;
  504. //
  505. // Registry
  506. //
  507. case GCC_REGISTER_CHANNEL_CONFIRM:
  508. eRegistryCommand = APPLET_REGISTER_CHANNEL;
  509. RegistryCommon_1:
  510. if (NULL != pMsg->RegistryConfirm.pRegItem)
  511. {
  512. pRegItem = (AppletRegistryItem *) pMsg->RegistryConfirm.pRegItem;
  513. }
  514. else
  515. {
  516. ::ZeroMemory(&RegItem, sizeof(RegItem));
  517. pRegItem = &RegItem;
  518. }
  519. hrNotify = m_pNotify->RegistryConfirm(eRegistryCommand,
  520. ::GetHrResult(pMsg->RegistryConfirm.nResult),
  521. (AppletRegistryKey *) pMsg->RegistryConfirm.pRegKey,
  522. pRegItem,
  523. (AppletRegistryEntryOwner *) &pMsg->RegistryConfirm.EntryOwner,
  524. pMsg->RegistryConfirm.eRights);
  525. ASSERT(SUCCEEDED(hrNotify));
  526. break;
  527. case GCC_ASSIGN_TOKEN_CONFIRM:
  528. eRegistryCommand = APPLET_ASSIGN_TOKEN;
  529. goto RegistryCommon_1;
  530. case GCC_SET_PARAMETER_CONFIRM:
  531. eRegistryCommand = APPLET_SET_PARAMETER;
  532. goto RegistryCommon_1;
  533. case GCC_RETRIEVE_ENTRY_CONFIRM:
  534. hrResult = ::GetHrResult(pMsg->RegistryConfirm.nResult);
  535. if (GCC_RESULT_SUCCESSFUL == pMsg->RegistryConfirm.nResult)
  536. {
  537. if (NULL != pMsg->RegistryConfirm.pRegItem)
  538. {
  539. pRegItem = (AppletRegistryItem *) pMsg->RegistryConfirm.pRegItem;
  540. }
  541. else
  542. {
  543. ::ZeroMemory(&RegItem, sizeof(RegItem));
  544. pRegItem = &RegItem;
  545. }
  546. hrNotify = m_pNotify->RegistryConfirm(APPLET_RETRIEVE_ENTRY,
  547. hrResult,
  548. (AppletRegistryKey *) pMsg->RegistryConfirm.pRegKey,
  549. pRegItem,
  550. (AppletRegistryEntryOwner *) &pMsg->RegistryConfirm.EntryOwner,
  551. pMsg->RegistryConfirm.eRights);
  552. ASSERT(SUCCEEDED(hrNotify));
  553. }
  554. else
  555. {
  556. ::ZeroMemory(&RegItem, sizeof(RegItem));
  557. ::ZeroMemory(&EntryOwner, sizeof(EntryOwner));
  558. hrNotify = m_pNotify->RegistryConfirm(APPLET_RETRIEVE_ENTRY,
  559. hrResult,
  560. (AppletRegistryKey *) pMsg->RegistryConfirm.pRegKey,
  561. &RegItem,
  562. &EntryOwner,
  563. APPLET_NO_MODIFICATION_RIGHTS_SPECIFIED);
  564. ASSERT(SUCCEEDED(hrNotify));
  565. }
  566. break;
  567. case GCC_DELETE_ENTRY_CONFIRM:
  568. hrResult = ::GetHrResult(pMsg->RegistryConfirm.nResult);
  569. if (GCC_RESULT_INDEX_ALREADY_OWNED == pMsg->RegistryConfirm.nResult)
  570. {
  571. if (NULL != pMsg->RegistryConfirm.pRegItem)
  572. {
  573. pRegItem = (AppletRegistryItem *) pMsg->RegistryConfirm.pRegItem;
  574. }
  575. else
  576. {
  577. ::ZeroMemory(&RegItem, sizeof(RegItem));
  578. pRegItem = &RegItem;
  579. }
  580. hrNotify = m_pNotify->RegistryConfirm(APPLET_DELETE_ENTRY,
  581. hrResult,
  582. (AppletRegistryKey *) pMsg->RegistryConfirm.pRegKey,
  583. pRegItem,
  584. (AppletRegistryEntryOwner *) &pMsg->RegistryConfirm.EntryOwner,
  585. pMsg->RegistryConfirm.eRights);
  586. ASSERT(SUCCEEDED(hrNotify));
  587. }
  588. else
  589. {
  590. ::ZeroMemory(&RegItem, sizeof(RegItem));
  591. ::ZeroMemory(&EntryOwner, sizeof(EntryOwner));
  592. hrNotify = m_pNotify->RegistryConfirm(APPLET_DELETE_ENTRY,
  593. hrResult,
  594. (AppletRegistryKey *) pMsg->RegistryConfirm.pRegKey,
  595. &RegItem,
  596. &EntryOwner,
  597. APPLET_NO_MODIFICATION_RIGHTS_SPECIFIED);
  598. ASSERT(SUCCEEDED(hrNotify));
  599. }
  600. break;
  601. case GCC_ALLOCATE_HANDLE_CONFIRM:
  602. hrNotify = m_pNotify->AllocateHandleConfirm(::GetHrResult(pMsg->RegAllocHandleConfirm.nResult),
  603. pMsg->RegAllocHandleConfirm.nFirstHandle,
  604. pMsg->RegAllocHandleConfirm.cHandles);
  605. ASSERT(SUCCEEDED(hrNotify));
  606. break;
  607. //
  608. // Channel
  609. //
  610. case MCS_CHANNEL_JOIN_CONFIRM:
  611. hrNotify = m_pNotify->ChannelConfirm(APPLET_JOIN_CHANNEL,
  612. ::GetHrResult(pMsg->ChannelConfirm.eResult),
  613. pMsg->ChannelConfirm.nChannelID);
  614. ASSERT(SUCCEEDED(hrNotify));
  615. break;
  616. case MCS_CHANNEL_CONVENE_CONFIRM:
  617. hrNotify = m_pNotify->ChannelConfirm(APPLET_CONVENE_CHANNEL,
  618. ::GetHrResult(pMsg->ChannelConfirm.eResult),
  619. pMsg->ChannelConfirm.nChannelID);
  620. ASSERT(SUCCEEDED(hrNotify));
  621. break;
  622. case MCS_CHANNEL_LEAVE_INDICATION:
  623. hrNotify = m_pNotify->ChannelIndication(APPLET_LEAVE_CHANNEL,
  624. pMsg->ChannelInd.nChannelID,
  625. ::GetAppletReason(pMsg->ChannelInd.eReason),
  626. 0);
  627. ASSERT(SUCCEEDED(hrNotify));
  628. break;
  629. case MCS_CHANNEL_DISBAND_INDICATION:
  630. hrNotify = m_pNotify->ChannelIndication(APPLET_DISBAND_CHANNEL,
  631. pMsg->ChannelInd.nChannelID,
  632. ::GetAppletReason(pMsg->ChannelInd.eReason),
  633. 0);
  634. ASSERT(SUCCEEDED(hrNotify));
  635. break;
  636. case MCS_CHANNEL_ADMIT_INDICATION:
  637. hrNotify = m_pNotify->ChannelIndication(APPLET_ADMIT_CHANNEL,
  638. pMsg->ChannelInd.nChannelID,
  639. APPLET_R_UNSPECIFIED,
  640. pMsg->ChannelInd.nManagerID);
  641. ASSERT(SUCCEEDED(hrNotify));
  642. break;
  643. case MCS_CHANNEL_EXPEL_INDICATION:
  644. hrNotify = m_pNotify->ChannelIndication(APPLET_EXPEL_CHANNEL,
  645. pMsg->ChannelInd.nChannelID,
  646. ::GetAppletReason(pMsg->ChannelInd.eReason),
  647. 0);
  648. ASSERT(SUCCEEDED(hrNotify));
  649. break;
  650. //
  651. // Token
  652. //
  653. case MCS_TOKEN_GRAB_CONFIRM:
  654. eTokenCommand = APPLET_GRAB_TOKEN;
  655. Token_Common_1:
  656. hrNotify = m_pNotify->TokenConfirm(eTokenCommand,
  657. ::GetHrResult(pMsg->TokenConfirm.eResult),
  658. pMsg->TokenConfirm.nTokenID);
  659. ASSERT(SUCCEEDED(hrNotify));
  660. break;
  661. case MCS_TOKEN_INHIBIT_CONFIRM:
  662. eTokenCommand = APPLET_INHIBIT_TOKEN;
  663. goto Token_Common_1;
  664. case MCS_TOKEN_GIVE_CONFIRM:
  665. eTokenCommand = APPLET_GIVE_TOKEN;
  666. goto Token_Common_1;
  667. case MCS_TOKEN_RELEASE_CONFIRM:
  668. eTokenCommand = APPLET_RELEASE_TOKEN;
  669. goto Token_Common_1;
  670. case MCS_TOKEN_TEST_CONFIRM:
  671. hrNotify = m_pNotify->TestTokenConfirm(pMsg->TokenConfirm.nTokenID,
  672. pMsg->TokenConfirm.eTokenStatus);
  673. ASSERT(SUCCEEDED(hrNotify));
  674. break;
  675. case MCS_TOKEN_GIVE_INDICATION:
  676. hrNotify = m_pNotify->TokenIndication(APPLET_GIVE_TOKEN,
  677. APPLET_R_UNSPECIFIED,
  678. pMsg->TokenInd.nTokenID,
  679. pMsg->TokenInd.nUserID);
  680. ASSERT(SUCCEEDED(hrNotify));
  681. break;
  682. case MCS_TOKEN_PLEASE_INDICATION:
  683. hrNotify = m_pNotify->TokenIndication(APPLET_PLEASE_TOKEN,
  684. APPLET_R_UNSPECIFIED,
  685. pMsg->TokenInd.nTokenID,
  686. pMsg->TokenInd.nUserID);
  687. ASSERT(SUCCEEDED(hrNotify));
  688. break;
  689. case MCS_TOKEN_RELEASE_INDICATION:
  690. hrNotify = m_pNotify->TokenIndication(APPLET_RELEASE_TOKEN,
  691. ::GetAppletReason(pMsg->TokenInd.eReason),
  692. pMsg->TokenInd.nTokenID,
  693. 0);
  694. ASSERT(SUCCEEDED(hrNotify));
  695. break;
  696. } // switch
  697. } // if
  698. }
  699. HRESULT GetHrResult(T120Result rc)
  700. {
  701. HRESULT hrResult;
  702. switch (rc)
  703. {
  704. case T120_RESULT_SUCCESSFUL:
  705. hrResult = S_OK;
  706. break;
  707. case GCC_RESULT_ENTRY_ALREADY_EXISTS:
  708. hrResult = APPLET_E_ENTRY_ALREADY_EXISTS;
  709. break;
  710. case GCC_RESULT_ENTRY_DOES_NOT_EXIST:
  711. hrResult = APPLET_E_ENTRY_DOES_NOT_EXIST;
  712. break;
  713. case GCC_RESULT_INDEX_ALREADY_OWNED:
  714. hrResult = APPLET_E_NOT_OWNER;
  715. break;
  716. default:
  717. hrResult = APPLET_E_SERVICE_FAIL;
  718. break;
  719. }
  720. return hrResult;
  721. }
  722. AppletReason GetAppletReason(T120Reason rc)
  723. {
  724. AppletReason eAppletReason;
  725. switch (rc)
  726. {
  727. case REASON_USER_REQUESTED:
  728. eAppletReason = APPLET_R_USER_REJECTED;
  729. break;
  730. case REASON_DOMAIN_DISCONNECTED:
  731. case REASON_PROVIDER_INITIATED:
  732. eAppletReason = APPLET_R_CONFERENCE_GONE;
  733. break;
  734. case REASON_TOKEN_PURGED:
  735. case REASON_CHANNEL_PURGED:
  736. eAppletReason = APPLET_R_RESOURCE_PURGED;
  737. break;
  738. default:
  739. eAppletReason = APPLET_R_UNSPECIFIED;
  740. break;
  741. }
  742. return eAppletReason;
  743. }
  744. //////////////////////////////////////////////////
  745. //
  746. // CNmAppletObj
  747. //
  748. CNmAppletObj::CNmAppletObj(void)
  749. :
  750. m_cRef(0),
  751. m_pT120Applet(NULL),
  752. m_pT120AutoJoinReq(NULL),
  753. m_pNotify(NULL),
  754. m_nPendingConfID(0)
  755. {
  756. }
  757. CNmAppletObj::~CNmAppletObj(void)
  758. {
  759. ASSERT(0 == m_cRef);
  760. if (NULL != m_pT120Applet)
  761. {
  762. m_pT120Applet->ReleaseInterface();
  763. m_pT120Applet = NULL;
  764. }
  765. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  766. }
  767. HRESULT CNmAppletObj::Initialize(void)
  768. {
  769. T120Error rc = ::T120_CreateAppletSAP(&m_pT120Applet);
  770. if (T120_NO_ERROR == rc)
  771. {
  772. m_pT120Applet->Advise(T120AppletCallback, this);
  773. return S_OK;
  774. }
  775. return APPLET_E_NO_SERVICE;
  776. }
  777. //////////////////////////////////////////////////
  778. //
  779. // Auto Join @ CNmAppletObj
  780. //
  781. HRESULT CNmAppletObj::RegisterAutoJoin
  782. (
  783. AppletSessionRequest *pRequest
  784. )
  785. {
  786. if (NULL != m_pNotify)
  787. {
  788. if (NULL != m_pT120Applet)
  789. {
  790. if (NULL != pRequest)
  791. {
  792. if (NULL == m_pT120AutoJoinReq)
  793. {
  794. m_pT120AutoJoinReq = ::AllocateJoinSessionRequest(pRequest);
  795. if (NULL != m_pT120AutoJoinReq)
  796. {
  797. T120Error rc = m_pT120Applet->RegisterAutoJoin(m_pT120AutoJoinReq);
  798. ASSERT(T120_NO_ERROR == rc);
  799. if (T120_NO_ERROR == rc)
  800. {
  801. return S_OK;
  802. }
  803. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  804. m_pT120AutoJoinReq = NULL;
  805. return APPLET_E_SERVICE_FAIL;
  806. }
  807. return APPLET_E_INVALID_JOIN_REQUEST;
  808. }
  809. return APPLET_E_ALREADY_REGISTERED;
  810. }
  811. return E_POINTER;
  812. }
  813. return APPLET_E_NO_SERVICE;
  814. }
  815. return APPLET_E_NOT_ADVISED;
  816. }
  817. HRESULT CNmAppletObj::UnregisterAutoJoin(void)
  818. {
  819. if (NULL != m_pT120Applet)
  820. {
  821. if (NULL != m_pT120AutoJoinReq)
  822. {
  823. m_pT120Applet->UnregisterAutoJoin();
  824. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  825. m_pT120AutoJoinReq = NULL;
  826. return S_OK;
  827. }
  828. return APPLET_E_NOT_REGISTERED;
  829. }
  830. return APPLET_E_NO_SERVICE;
  831. }
  832. //////////////////////////////////////////////////
  833. //
  834. // Session @ CNmAppletObj
  835. //
  836. HRESULT CNmAppletObj::CreateSession
  837. (
  838. IAppletSession **ppSession,
  839. AppletConfID nConfID
  840. )
  841. {
  842. if (NULL != m_pT120Applet)
  843. {
  844. if (NULL != ppSession)
  845. {
  846. *ppSession = NULL;
  847. if (nConfID)
  848. {
  849. IT120AppletSession *pT120Session = NULL;
  850. T120Error rc = m_pT120Applet->CreateSession(&pT120Session, nConfID);
  851. if (T120_NO_ERROR == rc)
  852. {
  853. *ppSession = (IAppletSession *) new CNmAppletSession(this, pT120Session);
  854. if (NULL != *ppSession)
  855. {
  856. return S_OK;
  857. }
  858. pT120Session->ReleaseInterface();
  859. return E_OUTOFMEMORY;
  860. }
  861. return APPLET_E_SERVICE_FAIL;
  862. }
  863. return APPLET_E_INVALID_CONFERENCE;
  864. }
  865. return E_POINTER;
  866. }
  867. return APPLET_E_NO_SERVICE;
  868. }
  869. //////////////////////////////////////////////////
  870. //
  871. // Notification @ CNmAppletObj
  872. //
  873. HRESULT CNmAppletObj::Advise
  874. (
  875. IAppletNotify *pNotify,
  876. DWORD *pdwCookie
  877. )
  878. {
  879. if (NULL != m_pT120Applet)
  880. {
  881. if (NULL == m_pNotify)
  882. {
  883. if (NULL != pNotify && NULL != pdwCookie)
  884. {
  885. pNotify->AddRef();
  886. m_pNotify = pNotify;
  887. m_pAppletObj = this;
  888. *pdwCookie = 1;
  889. if (m_nPendingConfID)
  890. {
  891. m_pNotify->PermitToJoinSessionIndication(m_nPendingConfID, TRUE);
  892. m_nPendingConfID = 0;
  893. }
  894. return S_OK;
  895. }
  896. return E_POINTER;
  897. }
  898. return APPLET_E_ALREADY_ADVISED;
  899. }
  900. return APPLET_E_NO_SERVICE;
  901. }
  902. HRESULT CNmAppletObj::UnAdvise
  903. (
  904. DWORD dwCookie
  905. )
  906. {
  907. if (NULL != m_pT120Applet)
  908. {
  909. if (NULL != m_pNotify)
  910. {
  911. if (dwCookie == 1 && m_pAppletObj == this)
  912. {
  913. m_pNotify->Release();
  914. m_pNotify = NULL;
  915. return S_OK;
  916. }
  917. return APPLET_E_INVALID_COOKIE;
  918. }
  919. return APPLET_E_NOT_ADVISED;
  920. }
  921. return APPLET_E_NO_SERVICE;
  922. }
  923. //////////////////////////////////////////////////
  924. //
  925. // T120 Applet @ CNmAppletObj
  926. //
  927. void CNmAppletObj::T120Callback
  928. (
  929. T120AppletMsg *pMsg
  930. )
  931. {
  932. HRESULT hrNotify;
  933. HRESULT hrResult;
  934. IAppletSession *pAppletSession;
  935. T120ChannelID *aChannelIDs;
  936. if (NULL != m_pNotify)
  937. {
  938. switch (pMsg->eMsgType)
  939. {
  940. case GCC_PERMIT_TO_ENROLL_INDICATION:
  941. ASSERT(0 == m_nPendingConfID);
  942. hrNotify = m_pNotify->PermitToJoinSessionIndication(
  943. pMsg->PermitToEnrollInd.nConfID,
  944. pMsg->PermitToEnrollInd.fPermissionGranted);
  945. ASSERT(SUCCEEDED(hrNotify));
  946. break;
  947. case T120_JOIN_SESSION_CONFIRM:
  948. hrResult = APPLET_E_SERVICE_FAIL;
  949. pAppletSession = NULL;
  950. aChannelIDs = NULL;
  951. if (T120_RESULT_SUCCESSFUL == pMsg->AutoJoinSessionInd.eResult &&
  952. T120_NO_ERROR == pMsg->AutoJoinSessionInd.eError)
  953. {
  954. hrResult = S_OK;
  955. if (pMsg->AutoJoinSessionInd.cResourceReqs)
  956. {
  957. aChannelIDs = new T120ChannelID[pMsg->AutoJoinSessionInd.cResourceReqs];
  958. if (NULL != aChannelIDs)
  959. {
  960. for (ULONG i = 0; i < pMsg->AutoJoinSessionInd.cResourceReqs; i++)
  961. {
  962. aChannelIDs[i] = pMsg->AutoJoinSessionInd.aResourceReqs[i].nChannelID;
  963. }
  964. }
  965. else
  966. {
  967. ASSERT(NULL != aChannelIDs);
  968. hrResult = E_OUTOFMEMORY;
  969. }
  970. }
  971. if (S_OK == hrResult)
  972. {
  973. ASSERT(NULL != pMsg->AutoJoinSessionInd.pIAppletSession);
  974. pAppletSession = new CNmAppletSession(this, pMsg->AutoJoinSessionInd.pIAppletSession, TRUE);
  975. ASSERT(NULL != pAppletSession);
  976. hrResult = (NULL != pAppletSession) ? S_OK : E_OUTOFMEMORY;
  977. }
  978. }
  979. if (S_OK == hrResult)
  980. {
  981. hrNotify = m_pNotify->AutoJoinSessionIndication(
  982. pAppletSession,
  983. hrResult,
  984. pMsg->AutoJoinSessionInd.uidMyself,
  985. pMsg->AutoJoinSessionInd.nidMyself,
  986. pMsg->AutoJoinSessionInd.sidMyself,
  987. pMsg->AutoJoinSessionInd.eidMyself,
  988. pMsg->AutoJoinSessionInd.cResourceReqs,
  989. aChannelIDs);
  990. ASSERT(SUCCEEDED(hrNotify));
  991. }
  992. else
  993. {
  994. hrNotify = m_pNotify->AutoJoinSessionIndication(NULL, hrResult, 0, 0, 0, 0, 0, NULL);
  995. ASSERT(SUCCEEDED(hrNotify));
  996. if (NULL != pMsg->AutoJoinSessionInd.pIAppletSession)
  997. {
  998. pMsg->AutoJoinSessionInd.pIAppletSession->ReleaseInterface();
  999. }
  1000. }
  1001. delete [] aChannelIDs;
  1002. break;
  1003. } // switch
  1004. }
  1005. else
  1006. {
  1007. // free memory for unwanted message
  1008. if (T120_JOIN_SESSION_CONFIRM == pMsg->eMsgType &&
  1009. T120_RESULT_SUCCESSFUL == pMsg->AutoJoinSessionInd.eResult &&
  1010. T120_NO_ERROR == pMsg->AutoJoinSessionInd.eError)
  1011. {
  1012. if (NULL != pMsg->AutoJoinSessionInd.pIAppletSession)
  1013. {
  1014. pMsg->AutoJoinSessionInd.pIAppletSession->ReleaseInterface();
  1015. }
  1016. }
  1017. else
  1018. if (GCC_PERMIT_TO_ENROLL_INDICATION == pMsg->eMsgType)
  1019. {
  1020. if (pMsg->PermitToEnrollInd.fPermissionGranted)
  1021. {
  1022. m_nPendingConfID = pMsg->PermitToEnrollInd.nConfID;
  1023. }
  1024. else
  1025. {
  1026. if (m_nPendingConfID == pMsg->PermitToEnrollInd.nConfID)
  1027. {
  1028. m_nPendingConfID = 0;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. }
  1034. //////////////////////////////////////////////////
  1035. //
  1036. // Join Session Request
  1037. //
  1038. T120JoinSessionRequest * AllocateJoinSessionRequest
  1039. (
  1040. AppletSessionRequest *pAppletRequest
  1041. )
  1042. {
  1043. T120JoinSessionRequest *pT120One = new T120JoinSessionRequest;
  1044. if (NULL != pT120One)
  1045. {
  1046. ::ZeroMemory(pT120One, sizeof(*pT120One));
  1047. ULONG i;
  1048. pT120One->dwAttachmentFlags = ATTACHMENT_DISCONNECT_IN_DATA_LOSS;
  1049. if (! ::DuplicateSessionKey(&pT120One->SessionKey, (T120SessionKey *) &pAppletRequest->SessionKey))
  1050. {
  1051. goto MyError;
  1052. }
  1053. pT120One->fConductingCapable = FALSE;
  1054. pT120One->nStartupChannelType = pAppletRequest->nStartupChannelType;
  1055. if (::ConvertNonCollapsedCaps(&pT120One->apNonCollapsedCaps,
  1056. pAppletRequest->apNonCollapsedCaps,
  1057. pAppletRequest->cNonCollapsedCaps))
  1058. {
  1059. pT120One->cNonCollapsedCaps = pAppletRequest->cNonCollapsedCaps;
  1060. }
  1061. else
  1062. {
  1063. goto MyError;
  1064. }
  1065. if (::ConvertCollapsedCaps(&pT120One->apCollapsedCaps,
  1066. pAppletRequest->apCollapsedCaps,
  1067. pAppletRequest->cCollapsedCaps))
  1068. {
  1069. pT120One->cCollapsedCaps = pAppletRequest->cCollapsedCaps;
  1070. }
  1071. else
  1072. {
  1073. goto MyError;
  1074. }
  1075. if (0 != (pT120One->cStaticChannels = pAppletRequest->cStaticChannels))
  1076. {
  1077. pT120One->aStaticChannels = new T120ChannelID[pT120One->cStaticChannels];
  1078. if (NULL != pT120One->aStaticChannels)
  1079. {
  1080. ::CopyMemory(pT120One->aStaticChannels,
  1081. pAppletRequest->aStaticChannels,
  1082. pT120One->cStaticChannels * sizeof(T120ChannelID));
  1083. }
  1084. else
  1085. {
  1086. goto MyError;
  1087. }
  1088. }
  1089. if (0 != (pT120One->cResourceReqs = pAppletRequest->cDynamicChannels))
  1090. {
  1091. if (NULL != (pT120One->aResourceReqs = new T120ResourceRequest[pT120One->cResourceReqs]))
  1092. {
  1093. ::ZeroMemory(pT120One->aResourceReqs, pT120One->cResourceReqs * sizeof(T120ResourceRequest));
  1094. for (i = 0; i < pT120One->cResourceReqs; i++)
  1095. {
  1096. pT120One->aResourceReqs[i].eCommand = APPLET_JOIN_DYNAMIC_CHANNEL;
  1097. if (! ::DuplicateRegistryKey(&pT120One->aResourceReqs[i].RegKey,
  1098. (T120RegistryKey *) &pAppletRequest->aChannelRegistryKeys[i]))
  1099. {
  1100. goto MyError;
  1101. }
  1102. }
  1103. }
  1104. else
  1105. {
  1106. goto MyError;
  1107. }
  1108. }
  1109. return pT120One;
  1110. }
  1111. MyError:
  1112. ::FreeJoinSessionRequest(pT120One);
  1113. return NULL;
  1114. }
  1115. void FreeJoinSessionRequest
  1116. (
  1117. T120JoinSessionRequest *pT120One
  1118. )
  1119. {
  1120. if (NULL != pT120One)
  1121. {
  1122. ::FreeSessionKey(&pT120One->SessionKey);
  1123. ::FreeNonCollapsedCaps(pT120One->apNonCollapsedCaps, pT120One->cNonCollapsedCaps);
  1124. ::FreeCollapsedCaps(pT120One->apCollapsedCaps, pT120One->cCollapsedCaps);
  1125. if (pT120One->cStaticChannels)
  1126. {
  1127. delete [] pT120One->aStaticChannels;
  1128. }
  1129. if (pT120One->cResourceReqs)
  1130. {
  1131. for (ULONG i = 0; i < pT120One->cResourceReqs; i++)
  1132. {
  1133. ::FreeRegistryKey(&pT120One->aResourceReqs[i].RegKey);
  1134. }
  1135. delete [] pT120One->aResourceReqs;
  1136. }
  1137. delete pT120One;
  1138. }
  1139. }
  1140. BOOL ConvertCollapsedCaps(T120AppCap ***papDst, AppletCapability **apSrc, ULONG cItems)
  1141. {
  1142. if (cItems)
  1143. {
  1144. T120AppCap **arr_ptr;
  1145. ULONG cbTotalSize = cItems * (sizeof(T120AppCap*) + sizeof(T120AppCap));
  1146. if (NULL != (arr_ptr = (T120AppCap**) new BYTE[cbTotalSize]))
  1147. {
  1148. ::ZeroMemory(arr_ptr, cbTotalSize);
  1149. T120AppCap *arr_obj = (T120AppCap *) (arr_ptr + cItems);
  1150. for (ULONG i = 0; i < cItems; i++)
  1151. {
  1152. arr_ptr[i] = &arr_obj[i];
  1153. if (! ::DuplicateCollapsedCap(arr_ptr[i], (T120AppCap *) apSrc[i]))
  1154. {
  1155. ::FreeCollapsedCaps(arr_ptr, cItems);
  1156. return FALSE;
  1157. }
  1158. }
  1159. }
  1160. *papDst = arr_ptr;
  1161. return (NULL != arr_ptr);
  1162. }
  1163. *papDst = NULL;
  1164. return TRUE;
  1165. }
  1166. void FreeCollapsedCaps(T120AppCap **apDst, ULONG cItems)
  1167. {
  1168. if (cItems && NULL != apDst)
  1169. {
  1170. T120AppCap **arr_ptr = apDst;
  1171. T120AppCap *arr_obj = (T120AppCap *) (arr_ptr + cItems);
  1172. for (ULONG i = 0; i < cItems; i++)
  1173. {
  1174. ::FreeCollapsedCap(&arr_obj[i]);
  1175. }
  1176. delete [] (LPBYTE) arr_ptr;
  1177. }
  1178. }
  1179. BOOL DuplicateCollapsedCap(T120AppCap *pDst, T120AppCap *pSrc)
  1180. {
  1181. pDst->number_of_entities = pSrc->number_of_entities;
  1182. pDst->capability_class = pSrc->capability_class; // no memory allocation
  1183. return ::DuplicateCapID(&pDst->capability_id, &pSrc->capability_id);
  1184. }
  1185. void FreeCollapsedCap(T120AppCap *pDst)
  1186. {
  1187. ::FreeCapID(&pDst->capability_id);
  1188. }
  1189. BOOL DuplicateCapID(T120CapID *pDst, T120CapID *pSrc)
  1190. {
  1191. pDst->capability_id_type = pSrc->capability_id_type;
  1192. switch (pDst->capability_id_type)
  1193. {
  1194. case GCC_STANDARD_CAPABILITY:
  1195. pDst->standard_capability = pSrc->standard_capability;
  1196. return TRUE;
  1197. case GCC_NON_STANDARD_CAPABILITY:
  1198. return ::DuplicateObjectKey(&pDst->non_standard_capability, &pSrc->non_standard_capability);
  1199. }
  1200. return FALSE;
  1201. }
  1202. void FreeCapID(T120CapID *pDst)
  1203. {
  1204. switch (pDst->capability_id_type)
  1205. {
  1206. case GCC_NON_STANDARD_CAPABILITY:
  1207. ::FreeObjectKey(&pDst->non_standard_capability);
  1208. break;
  1209. }
  1210. }
  1211. BOOL ConvertNonCollapsedCaps(T120NonCollCap ***papDst, AppletCapability2 **apSrc, ULONG cItems)
  1212. {
  1213. if (cItems)
  1214. {
  1215. T120NonCollCap **arr_ptr;
  1216. ULONG cbTotalSize = cItems * (sizeof(T120NonCollCap*) + sizeof(T120NonCollCap));
  1217. if (NULL != (arr_ptr = (T120NonCollCap**) new BYTE[cbTotalSize]))
  1218. {
  1219. ::ZeroMemory(arr_ptr, cbTotalSize);
  1220. T120NonCollCap *arr_obj = (T120NonCollCap *) (arr_ptr + cItems);
  1221. for (ULONG i = 0; i < cItems; i++)
  1222. {
  1223. arr_ptr[i] = &arr_obj[i];
  1224. if (! ::DuplicateNonCollapsedCap(arr_ptr[i], (T120NonCollCap *) apSrc[i]))
  1225. {
  1226. ::FreeNonCollapsedCaps(arr_ptr, cItems);
  1227. return FALSE;
  1228. }
  1229. }
  1230. }
  1231. *papDst = arr_ptr;
  1232. return (NULL != arr_ptr);
  1233. }
  1234. *papDst = NULL;
  1235. return TRUE;
  1236. }
  1237. void FreeNonCollapsedCaps(T120NonCollCap **apDst, ULONG cItems)
  1238. {
  1239. if (cItems && NULL != apDst)
  1240. {
  1241. T120NonCollCap **arr_ptr = apDst;
  1242. T120NonCollCap *arr_obj = (T120NonCollCap *) (arr_ptr + cItems);
  1243. for (ULONG i = 0; i < cItems; i++)
  1244. {
  1245. ::FreeNonCollapsedCap(&arr_obj[i]);
  1246. }
  1247. delete [] (LPBYTE) arr_ptr;
  1248. }
  1249. }
  1250. BOOL DuplicateNonCollapsedCap(T120NonCollCap *pDst, T120NonCollCap *pSrc)
  1251. {
  1252. if (::DuplicateCapID(&pDst->capability_id, &pSrc->capability_id))
  1253. {
  1254. if (NULL == pSrc->application_data)
  1255. {
  1256. return TRUE;
  1257. }
  1258. if (NULL != (pDst->application_data = new OSTR))
  1259. {
  1260. return ::DuplicateOSTR(pDst->application_data, pSrc->application_data);
  1261. }
  1262. }
  1263. return FALSE;
  1264. }
  1265. void FreeNonCollapsedCap(T120NonCollCap *pDst)
  1266. {
  1267. ::FreeCapID(&pDst->capability_id);
  1268. if (NULL != pDst->application_data)
  1269. {
  1270. ::FreeOSTR(pDst->application_data);
  1271. delete pDst->application_data;
  1272. }
  1273. }
  1274. BOOL DuplicateRegistryKey(T120RegistryKey *pDst, T120RegistryKey *pSrc)
  1275. {
  1276. if (::DuplicateSessionKey(&pDst->session_key, &pSrc->session_key))
  1277. {
  1278. return ::DuplicateOSTR(&pDst->resource_id, &pSrc->resource_id);
  1279. }
  1280. return FALSE;
  1281. }
  1282. void FreeRegistryKey(T120RegistryKey *pDst)
  1283. {
  1284. ::FreeSessionKey(&pDst->session_key);
  1285. ::FreeOSTR(&pDst->resource_id);
  1286. }
  1287. BOOL DuplicateSessionKey(T120SessionKey *pDst, T120SessionKey *pSrc)
  1288. {
  1289. pDst->session_id = pSrc->session_id;
  1290. return ::DuplicateObjectKey(&pDst->application_protocol_key, &pSrc->application_protocol_key);
  1291. }
  1292. void FreeSessionKey(T120SessionKey *pDst)
  1293. {
  1294. ::FreeObjectKey(&pDst->application_protocol_key);
  1295. }
  1296. BOOL DuplicateObjectKey(T120ObjectKey *pDst, T120ObjectKey *pSrc)
  1297. {
  1298. pDst->key_type = pSrc->key_type;
  1299. switch (pDst->key_type)
  1300. {
  1301. case GCC_OBJECT_KEY:
  1302. pDst->object_id.long_string_length = pSrc->object_id.long_string_length;
  1303. if (pSrc->object_id.long_string_length && NULL != pSrc->object_id.long_string)
  1304. {
  1305. if (NULL != (pDst->object_id.long_string = new ULONG[pDst->object_id.long_string_length]))
  1306. {
  1307. ::CopyMemory(pDst->object_id.long_string,
  1308. pSrc->object_id.long_string,
  1309. pDst->object_id.long_string_length * sizeof(ULONG));
  1310. return TRUE;
  1311. }
  1312. }
  1313. break;
  1314. case GCC_H221_NONSTANDARD_KEY:
  1315. return ::DuplicateOSTR(&pDst->h221_non_standard_id, &pSrc->h221_non_standard_id);
  1316. }
  1317. return FALSE;
  1318. }
  1319. void FreeObjectKey(T120ObjectKey *pDst)
  1320. {
  1321. switch (pDst->key_type)
  1322. {
  1323. case GCC_OBJECT_KEY:
  1324. if (pDst->object_id.long_string_length)
  1325. {
  1326. delete [] pDst->object_id.long_string;
  1327. }
  1328. break;
  1329. case GCC_H221_NONSTANDARD_KEY:
  1330. ::FreeOSTR(&pDst->h221_non_standard_id);
  1331. break;
  1332. }
  1333. }
  1334. BOOL DuplicateOSTR(OSTR *pDst, OSTR *pSrc)
  1335. {
  1336. if (pSrc->length && NULL != pSrc->value)
  1337. {
  1338. pDst->length = pSrc->length;
  1339. if (NULL != (pDst->value = new BYTE[pDst->length]))
  1340. {
  1341. ::CopyMemory(pDst->value, pSrc->value, pDst->length);
  1342. return TRUE;
  1343. }
  1344. }
  1345. return FALSE;
  1346. }
  1347. void FreeOSTR(OSTR *pDst)
  1348. {
  1349. if (pDst->length)
  1350. {
  1351. delete [] pDst->value;
  1352. }
  1353. }
  1354. //////////////////////////////////////////////////
  1355. //
  1356. // Conversion
  1357. //
  1358. void AppletRegistryRequestToT120One
  1359. (
  1360. AppletRegistryRequest *pAppletRequest,
  1361. T120RegistryRequest *pT120One
  1362. )
  1363. {
  1364. pT120One->eCommand = pAppletRequest->eCommand;
  1365. pT120One->pRegistryKey = (T120RegistryKey *) &pAppletRequest->RegistryKey;
  1366. switch (pT120One->eCommand)
  1367. {
  1368. case APPLET_REGISTER_CHANNEL:
  1369. pT120One->nChannelID = pAppletRequest->nChannelID;
  1370. break;
  1371. case APPLET_SET_PARAMETER:
  1372. pT120One->Param.postrValue = (OSTR *) &pAppletRequest->ostrParamValue;
  1373. pT120One->Param.eModifyRights = pAppletRequest->eParamModifyRights;
  1374. break;
  1375. case APPLET_ALLOCATE_HANDLE:
  1376. pT120One->cHandles = pAppletRequest->cHandles;
  1377. break;
  1378. case APPLET_RETRIEVE_ENTRY:
  1379. case APPLET_DELETE_ENTRY:
  1380. case APPLET_ASSIGN_TOKEN:
  1381. case APPLET_MONITOR:
  1382. default:
  1383. break;
  1384. }
  1385. }
  1386. #ifdef _DEBUG
  1387. void CheckStructCompatible(void)
  1388. {
  1389. ASSERT(sizeof(AppletOctetString) == sizeof(OSTR));
  1390. ASSERT(FIELD_OFFSET(AppletOctetString, cbStrSize) == FIELD_OFFSET(OSTR, length));
  1391. ASSERT(FIELD_OFFSET(AppletOctetString, pbValue) == FIELD_OFFSET(OSTR, value));
  1392. ASSERT(sizeof(AppletLongString) == sizeof(T120LongString));
  1393. ASSERT(FIELD_OFFSET(AppletLongString, nStrLen) == FIELD_OFFSET(T120LongString, long_string_length));
  1394. ASSERT(FIELD_OFFSET(AppletLongString, pnValue) == FIELD_OFFSET(T120LongString, long_string));
  1395. ASSERT(sizeof(AppletObjectKey) == sizeof(T120ObjectKey));
  1396. ASSERT(FIELD_OFFSET(AppletObjectKey, eType) == FIELD_OFFSET(T120ObjectKey, key_type));
  1397. ASSERT(FIELD_OFFSET(AppletObjectKey, lstrObjectID) == FIELD_OFFSET(T120ObjectKey, object_id));
  1398. ASSERT(FIELD_OFFSET(AppletObjectKey, ostrH221NonStdID) == FIELD_OFFSET(T120ObjectKey, h221_non_standard_id));
  1399. ASSERT(sizeof(AppletSessionKey) == sizeof(T120SessionKey));
  1400. ASSERT(FIELD_OFFSET(AppletSessionKey, AppletProtocolKey) == FIELD_OFFSET(T120SessionKey, application_protocol_key));
  1401. ASSERT(FIELD_OFFSET(AppletSessionKey, nSessionID) == FIELD_OFFSET(T120SessionKey, session_id));
  1402. ASSERT(sizeof(AppletRegistryKey) == sizeof(T120RegistryKey));
  1403. ASSERT(FIELD_OFFSET(AppletRegistryKey, SessionKey) == FIELD_OFFSET(T120RegistryKey, session_key));
  1404. ASSERT(FIELD_OFFSET(AppletRegistryKey, ostrResourceID) == FIELD_OFFSET(T120RegistryKey, resource_id));
  1405. ASSERT(sizeof(AppletRegistryItem) == sizeof(T120RegistryItem));
  1406. ASSERT(FIELD_OFFSET(AppletRegistryItem, ItemType) == FIELD_OFFSET(T120RegistryItem, item_type));
  1407. ASSERT(FIELD_OFFSET(AppletRegistryItem, nChannelID) == FIELD_OFFSET(T120RegistryItem, channel_id));
  1408. ASSERT(FIELD_OFFSET(AppletRegistryItem, nTokenID) == FIELD_OFFSET(T120RegistryItem, token_id));
  1409. ASSERT(FIELD_OFFSET(AppletRegistryItem, ostrParamValue) == FIELD_OFFSET(T120RegistryItem, parameter));
  1410. ASSERT(sizeof(AppletRegistryEntryOwner) == sizeof(T120RegistryEntryOwner));
  1411. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, fEntryOwned) == FIELD_OFFSET(T120RegistryEntryOwner, entry_is_owned));
  1412. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, nOwnerNodeID) == FIELD_OFFSET(T120RegistryEntryOwner, owner_node_id));
  1413. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, nOwnerEntityID) == FIELD_OFFSET(T120RegistryEntryOwner, owner_entity_id));
  1414. ASSERT(sizeof(AppletCapabilityID) == sizeof(T120CapID));
  1415. ASSERT(FIELD_OFFSET(AppletCapabilityID, eType) == FIELD_OFFSET(T120CapID, capability_id_type));
  1416. ASSERT(FIELD_OFFSET(AppletCapabilityID, nNonStdCap) == FIELD_OFFSET(T120CapID, non_standard_capability));
  1417. ASSERT(FIELD_OFFSET(AppletCapabilityID, nStdCap) == FIELD_OFFSET(T120CapID, standard_capability));
  1418. ASSERT(sizeof(AppletCapability) == sizeof(T120AppCap));
  1419. ASSERT(FIELD_OFFSET(AppletCapability, CapID) == FIELD_OFFSET(T120AppCap, capability_id));
  1420. ASSERT(FIELD_OFFSET(AppletCapability, CapClass) == FIELD_OFFSET(T120AppCap, capability_class));
  1421. ASSERT(FIELD_OFFSET(AppletCapability, cEntities) == FIELD_OFFSET(T120AppCap, number_of_entities));
  1422. ASSERT(sizeof(AppletCapability2) == sizeof(T120NonCollCap));
  1423. ASSERT(FIELD_OFFSET(AppletCapability2, CapID) == FIELD_OFFSET(T120NonCollCap, capability_id));
  1424. ASSERT(FIELD_OFFSET(AppletCapability2, pCapData) == FIELD_OFFSET(T120NonCollCap, application_data));
  1425. ASSERT(sizeof(AppletProtocolEntity) == sizeof(T120APE)); // array of structs vs array of pointers
  1426. ASSERT(FIELD_OFFSET(AppletProtocolEntity, SessionKey) == FIELD_OFFSET(T120APE, session_key));
  1427. ASSERT(FIELD_OFFSET(AppletProtocolEntity, eStartupChannelType) == FIELD_OFFSET(T120APE, startup_channel_type));
  1428. ASSERT(FIELD_OFFSET(AppletProtocolEntity, fMustBeInvoked) == FIELD_OFFSET(T120APE, must_be_invoked));
  1429. ASSERT(FIELD_OFFSET(AppletProtocolEntity, cExpectedCapabilities) == FIELD_OFFSET(T120APE, number_of_expected_capabilities));
  1430. ASSERT(FIELD_OFFSET(AppletProtocolEntity, apExpectedCapabilities) == FIELD_OFFSET(T120APE, expected_capabilities_list));
  1431. ASSERT(sizeof(AppletRecord) == sizeof(T120AppRecord)); // array of structs vs array of pointers
  1432. ASSERT(FIELD_OFFSET(AppletRecord, nNodeID) == FIELD_OFFSET(T120AppRecord, node_id));
  1433. ASSERT(FIELD_OFFSET(AppletRecord, nEntityID) == FIELD_OFFSET(T120AppRecord, entity_id));
  1434. ASSERT(FIELD_OFFSET(AppletRecord, fEnrolledActively) == FIELD_OFFSET(T120AppRecord, is_enrolled_actively));
  1435. ASSERT(FIELD_OFFSET(AppletRecord, fConductingCapable) == FIELD_OFFSET(T120AppRecord, is_conducting_capable));
  1436. ASSERT(FIELD_OFFSET(AppletRecord, eStartupChannelType) == FIELD_OFFSET(T120AppRecord, startup_channel_type));
  1437. ASSERT(FIELD_OFFSET(AppletRecord, nAppletUserID) == FIELD_OFFSET(T120AppRecord, application_user_id));
  1438. ASSERT(FIELD_OFFSET(AppletRecord, cCapabilities) == FIELD_OFFSET(T120AppRecord, number_of_non_collapsed_caps));
  1439. ASSERT(FIELD_OFFSET(AppletRecord, apCapabilities) == FIELD_OFFSET(T120AppRecord, non_collapsed_caps_list));
  1440. ASSERT(sizeof(AppletRoster) == sizeof(T120AppRoster)); // array of structs vs array of pointers
  1441. ASSERT(FIELD_OFFSET(AppletRoster, SessionKey) == FIELD_OFFSET(T120AppRoster, session_key));
  1442. ASSERT(FIELD_OFFSET(AppletRoster, fRosterChanged) == FIELD_OFFSET(T120AppRoster, application_roster_was_changed));
  1443. ASSERT(FIELD_OFFSET(AppletRoster, nInstanceNumber) == FIELD_OFFSET(T120AppRoster, instance_number));
  1444. ASSERT(FIELD_OFFSET(AppletRoster, fNodesAdded) == FIELD_OFFSET(T120AppRoster, nodes_were_added));
  1445. ASSERT(FIELD_OFFSET(AppletRoster, fNodesRemoved) == FIELD_OFFSET(T120AppRoster, nodes_were_removed));
  1446. ASSERT(FIELD_OFFSET(AppletRoster, fCapabilitiesChanged) == FIELD_OFFSET(T120AppRoster, capabilities_were_changed));
  1447. ASSERT(FIELD_OFFSET(AppletRoster, cRecords) == FIELD_OFFSET(T120AppRoster, number_of_records));
  1448. ASSERT(FIELD_OFFSET(AppletRoster, apAppletRecords) == FIELD_OFFSET(T120AppRoster, application_record_list));
  1449. ASSERT(FIELD_OFFSET(AppletRoster, cCapabilities) == FIELD_OFFSET(T120AppRoster, number_of_capabilities));
  1450. ASSERT(FIELD_OFFSET(AppletRoster, apCapabilities) == FIELD_OFFSET(T120AppRoster, capabilities_list));
  1451. ASSERT(sizeof(AppletChannelRequest) == sizeof(T120ChannelRequest));
  1452. ASSERT(FIELD_OFFSET(AppletChannelRequest, eCommand) == FIELD_OFFSET(T120ChannelRequest, eCommand));
  1453. ASSERT(FIELD_OFFSET(AppletChannelRequest, nChannelID) == FIELD_OFFSET(T120ChannelRequest, nChannelID));
  1454. ASSERT(FIELD_OFFSET(AppletChannelRequest, cUsers) == FIELD_OFFSET(T120ChannelRequest, cUsers));
  1455. ASSERT(FIELD_OFFSET(AppletChannelRequest, aUsers) == FIELD_OFFSET(T120ChannelRequest, aUsers));
  1456. ASSERT(sizeof(AppletTokenRequest) == sizeof(T120TokenRequest));
  1457. ASSERT(FIELD_OFFSET(AppletTokenRequest, eCommand) == FIELD_OFFSET(T120TokenRequest, eCommand));
  1458. ASSERT(FIELD_OFFSET(AppletTokenRequest, nTokenID) == FIELD_OFFSET(T120TokenRequest, nTokenID));
  1459. ASSERT(FIELD_OFFSET(AppletTokenRequest, uidGiveTo) == FIELD_OFFSET(T120TokenRequest, uidGiveTo));
  1460. ASSERT(FIELD_OFFSET(AppletTokenRequest, hrGiveResponse) == FIELD_OFFSET(T120TokenRequest, eGiveResponse));
  1461. }
  1462. #endif // _DEBUG
  1463.