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.

1746 lines
53 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. ERROR_OUT (("WHAT!!!"));
  734. break;
  735. case REASON_TOKEN_PURGED:
  736. case REASON_CHANNEL_PURGED:
  737. eAppletReason = APPLET_R_RESOURCE_PURGED;
  738. break;
  739. default:
  740. eAppletReason = APPLET_R_UNSPECIFIED;
  741. break;
  742. }
  743. return eAppletReason;
  744. }
  745. //////////////////////////////////////////////////
  746. //
  747. // CNmAppletObj
  748. //
  749. CNmAppletObj::CNmAppletObj(void)
  750. :
  751. m_cRef(0),
  752. m_pT120Applet(NULL),
  753. m_pT120AutoJoinReq(NULL),
  754. m_pNotify(NULL),
  755. m_nPendingConfID(0)
  756. {
  757. }
  758. CNmAppletObj::~CNmAppletObj(void)
  759. {
  760. ASSERT(0 == m_cRef);
  761. if (NULL != m_pT120Applet)
  762. {
  763. m_pT120Applet->ReleaseInterface();
  764. m_pT120Applet = NULL;
  765. }
  766. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  767. }
  768. HRESULT CNmAppletObj::Initialize(void)
  769. {
  770. T120Error rc = ::T120_CreateAppletSAP(&m_pT120Applet);
  771. if (T120_NO_ERROR == rc)
  772. {
  773. m_pT120Applet->Advise(T120AppletCallback, this);
  774. return S_OK;
  775. }
  776. return APPLET_E_NO_SERVICE;
  777. }
  778. //////////////////////////////////////////////////
  779. //
  780. // Auto Join @ CNmAppletObj
  781. //
  782. HRESULT CNmAppletObj::RegisterAutoJoin
  783. (
  784. AppletSessionRequest *pRequest
  785. )
  786. {
  787. if (NULL != m_pNotify)
  788. {
  789. if (NULL != m_pT120Applet)
  790. {
  791. if (NULL != pRequest)
  792. {
  793. if (NULL == m_pT120AutoJoinReq)
  794. {
  795. m_pT120AutoJoinReq = ::AllocateJoinSessionRequest(pRequest);
  796. if (NULL != m_pT120AutoJoinReq)
  797. {
  798. T120Error rc = m_pT120Applet->RegisterAutoJoin(m_pT120AutoJoinReq);
  799. ASSERT(T120_NO_ERROR == rc);
  800. if (T120_NO_ERROR == rc)
  801. {
  802. return S_OK;
  803. }
  804. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  805. m_pT120AutoJoinReq = NULL;
  806. return APPLET_E_SERVICE_FAIL;
  807. }
  808. return APPLET_E_INVALID_JOIN_REQUEST;
  809. }
  810. return APPLET_E_ALREADY_REGISTERED;
  811. }
  812. return E_POINTER;
  813. }
  814. return APPLET_E_NO_SERVICE;
  815. }
  816. return APPLET_E_NOT_ADVISED;
  817. }
  818. HRESULT CNmAppletObj::UnregisterAutoJoin(void)
  819. {
  820. if (NULL != m_pT120Applet)
  821. {
  822. if (NULL != m_pT120AutoJoinReq)
  823. {
  824. m_pT120Applet->UnregisterAutoJoin();
  825. ::FreeJoinSessionRequest(m_pT120AutoJoinReq);
  826. m_pT120AutoJoinReq = NULL;
  827. return S_OK;
  828. }
  829. return APPLET_E_NOT_REGISTERED;
  830. }
  831. return APPLET_E_NO_SERVICE;
  832. }
  833. //////////////////////////////////////////////////
  834. //
  835. // Session @ CNmAppletObj
  836. //
  837. HRESULT CNmAppletObj::CreateSession
  838. (
  839. IAppletSession **ppSession,
  840. AppletConfID nConfID
  841. )
  842. {
  843. if (NULL != m_pT120Applet)
  844. {
  845. if (NULL != ppSession)
  846. {
  847. *ppSession = NULL;
  848. if (nConfID)
  849. {
  850. IT120AppletSession *pT120Session = NULL;
  851. T120Error rc = m_pT120Applet->CreateSession(&pT120Session, nConfID);
  852. if (T120_NO_ERROR == rc)
  853. {
  854. *ppSession = (IAppletSession *) new CNmAppletSession(this, pT120Session);
  855. if (NULL != *ppSession)
  856. {
  857. return S_OK;
  858. }
  859. pT120Session->ReleaseInterface();
  860. return E_OUTOFMEMORY;
  861. }
  862. return APPLET_E_SERVICE_FAIL;
  863. }
  864. return APPLET_E_INVALID_CONFERENCE;
  865. }
  866. return E_POINTER;
  867. }
  868. return APPLET_E_NO_SERVICE;
  869. }
  870. //////////////////////////////////////////////////
  871. //
  872. // Notification @ CNmAppletObj
  873. //
  874. HRESULT CNmAppletObj::Advise
  875. (
  876. IAppletNotify *pNotify,
  877. DWORD *pdwCookie
  878. )
  879. {
  880. if (NULL != m_pT120Applet)
  881. {
  882. if (NULL == m_pNotify)
  883. {
  884. if (NULL != pNotify && NULL != pdwCookie)
  885. {
  886. pNotify->AddRef();
  887. m_pNotify = pNotify;
  888. m_pAppletObj = this;
  889. *pdwCookie = 1;
  890. if (m_nPendingConfID)
  891. {
  892. m_pNotify->PermitToJoinSessionIndication(m_nPendingConfID, TRUE);
  893. m_nPendingConfID = 0;
  894. }
  895. return S_OK;
  896. }
  897. return E_POINTER;
  898. }
  899. return APPLET_E_ALREADY_ADVISED;
  900. }
  901. return APPLET_E_NO_SERVICE;
  902. }
  903. HRESULT CNmAppletObj::UnAdvise
  904. (
  905. DWORD dwCookie
  906. )
  907. {
  908. if (NULL != m_pT120Applet)
  909. {
  910. if (NULL != m_pNotify)
  911. {
  912. if (dwCookie == 1 && m_pAppletObj == this)
  913. {
  914. m_pNotify->Release();
  915. m_pNotify = NULL;
  916. return S_OK;
  917. }
  918. return APPLET_E_INVALID_COOKIE;
  919. }
  920. return APPLET_E_NOT_ADVISED;
  921. }
  922. return APPLET_E_NO_SERVICE;
  923. }
  924. //////////////////////////////////////////////////
  925. //
  926. // T120 Applet @ CNmAppletObj
  927. //
  928. void CNmAppletObj::T120Callback
  929. (
  930. T120AppletMsg *pMsg
  931. )
  932. {
  933. HRESULT hrNotify;
  934. HRESULT hrResult;
  935. IAppletSession *pAppletSession;
  936. T120ChannelID *aChannelIDs;
  937. if (NULL != m_pNotify)
  938. {
  939. switch (pMsg->eMsgType)
  940. {
  941. case GCC_PERMIT_TO_ENROLL_INDICATION:
  942. ASSERT(0 == m_nPendingConfID);
  943. hrNotify = m_pNotify->PermitToJoinSessionIndication(
  944. pMsg->PermitToEnrollInd.nConfID,
  945. pMsg->PermitToEnrollInd.fPermissionGranted);
  946. ASSERT(SUCCEEDED(hrNotify));
  947. break;
  948. case T120_JOIN_SESSION_CONFIRM:
  949. hrResult = APPLET_E_SERVICE_FAIL;
  950. pAppletSession = NULL;
  951. aChannelIDs = NULL;
  952. if (T120_RESULT_SUCCESSFUL == pMsg->AutoJoinSessionInd.eResult &&
  953. T120_NO_ERROR == pMsg->AutoJoinSessionInd.eError)
  954. {
  955. hrResult = S_OK;
  956. if (pMsg->AutoJoinSessionInd.cResourceReqs)
  957. {
  958. aChannelIDs = new T120ChannelID[pMsg->AutoJoinSessionInd.cResourceReqs];
  959. if (NULL != aChannelIDs)
  960. {
  961. for (ULONG i = 0; i < pMsg->AutoJoinSessionInd.cResourceReqs; i++)
  962. {
  963. aChannelIDs[i] = pMsg->AutoJoinSessionInd.aResourceReqs[i].nChannelID;
  964. }
  965. }
  966. else
  967. {
  968. ASSERT(NULL != aChannelIDs);
  969. hrResult = E_OUTOFMEMORY;
  970. }
  971. }
  972. if (S_OK == hrResult)
  973. {
  974. ASSERT(NULL != pMsg->AutoJoinSessionInd.pIAppletSession);
  975. pAppletSession = new CNmAppletSession(this, pMsg->AutoJoinSessionInd.pIAppletSession, TRUE);
  976. ASSERT(NULL != pAppletSession);
  977. hrResult = (NULL != pAppletSession) ? S_OK : E_OUTOFMEMORY;
  978. }
  979. }
  980. if (S_OK == hrResult)
  981. {
  982. hrNotify = m_pNotify->AutoJoinSessionIndication(
  983. pAppletSession,
  984. hrResult,
  985. pMsg->AutoJoinSessionInd.uidMyself,
  986. pMsg->AutoJoinSessionInd.nidMyself,
  987. pMsg->AutoJoinSessionInd.sidMyself,
  988. pMsg->AutoJoinSessionInd.eidMyself,
  989. pMsg->AutoJoinSessionInd.cResourceReqs,
  990. aChannelIDs);
  991. ASSERT(SUCCEEDED(hrNotify));
  992. }
  993. else
  994. {
  995. hrNotify = m_pNotify->AutoJoinSessionIndication(NULL, hrResult, 0, 0, 0, 0, 0, NULL);
  996. ASSERT(SUCCEEDED(hrNotify));
  997. if (NULL != pMsg->AutoJoinSessionInd.pIAppletSession)
  998. {
  999. pMsg->AutoJoinSessionInd.pIAppletSession->ReleaseInterface();
  1000. }
  1001. }
  1002. delete [] aChannelIDs;
  1003. break;
  1004. } // switch
  1005. }
  1006. else
  1007. {
  1008. // free memory for unwanted message
  1009. if (T120_JOIN_SESSION_CONFIRM == pMsg->eMsgType &&
  1010. T120_RESULT_SUCCESSFUL == pMsg->AutoJoinSessionInd.eResult &&
  1011. T120_NO_ERROR == pMsg->AutoJoinSessionInd.eError)
  1012. {
  1013. if (NULL != pMsg->AutoJoinSessionInd.pIAppletSession)
  1014. {
  1015. pMsg->AutoJoinSessionInd.pIAppletSession->ReleaseInterface();
  1016. }
  1017. }
  1018. else
  1019. if (GCC_PERMIT_TO_ENROLL_INDICATION == pMsg->eMsgType)
  1020. {
  1021. if (pMsg->PermitToEnrollInd.fPermissionGranted)
  1022. {
  1023. m_nPendingConfID = pMsg->PermitToEnrollInd.nConfID;
  1024. }
  1025. else
  1026. {
  1027. if (m_nPendingConfID == pMsg->PermitToEnrollInd.nConfID)
  1028. {
  1029. m_nPendingConfID = 0;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. }
  1035. //////////////////////////////////////////////////
  1036. //
  1037. // Join Session Request
  1038. //
  1039. T120JoinSessionRequest * AllocateJoinSessionRequest
  1040. (
  1041. AppletSessionRequest *pAppletRequest
  1042. )
  1043. {
  1044. T120JoinSessionRequest *pT120One = new T120JoinSessionRequest;
  1045. if (NULL != pT120One)
  1046. {
  1047. ::ZeroMemory(pT120One, sizeof(*pT120One));
  1048. ULONG i;
  1049. pT120One->dwAttachmentFlags = ATTACHMENT_DISCONNECT_IN_DATA_LOSS;
  1050. if (! ::DuplicateSessionKey(&pT120One->SessionKey, (T120SessionKey *) &pAppletRequest->SessionKey))
  1051. {
  1052. goto MyError;
  1053. }
  1054. pT120One->fConductingCapable = FALSE;
  1055. pT120One->nStartupChannelType = pAppletRequest->nStartupChannelType;
  1056. if (::ConvertNonCollapsedCaps(&pT120One->apNonCollapsedCaps,
  1057. pAppletRequest->apNonCollapsedCaps,
  1058. pAppletRequest->cNonCollapsedCaps))
  1059. {
  1060. pT120One->cNonCollapsedCaps = pAppletRequest->cNonCollapsedCaps;
  1061. }
  1062. else
  1063. {
  1064. goto MyError;
  1065. }
  1066. if (::ConvertCollapsedCaps(&pT120One->apCollapsedCaps,
  1067. pAppletRequest->apCollapsedCaps,
  1068. pAppletRequest->cCollapsedCaps))
  1069. {
  1070. pT120One->cCollapsedCaps = pAppletRequest->cCollapsedCaps;
  1071. }
  1072. else
  1073. {
  1074. goto MyError;
  1075. }
  1076. if (0 != (pT120One->cStaticChannels = pAppletRequest->cStaticChannels))
  1077. {
  1078. pT120One->aStaticChannels = new T120ChannelID[pT120One->cStaticChannels];
  1079. if (NULL != pT120One->aStaticChannels)
  1080. {
  1081. ::CopyMemory(pT120One->aStaticChannels,
  1082. pAppletRequest->aStaticChannels,
  1083. pT120One->cStaticChannels * sizeof(T120ChannelID));
  1084. }
  1085. else
  1086. {
  1087. goto MyError;
  1088. }
  1089. }
  1090. if (0 != (pT120One->cResourceReqs = pAppletRequest->cDynamicChannels))
  1091. {
  1092. if (NULL != (pT120One->aResourceReqs = new T120ResourceRequest[pT120One->cResourceReqs]))
  1093. {
  1094. ::ZeroMemory(pT120One->aResourceReqs, pT120One->cResourceReqs * sizeof(T120ResourceRequest));
  1095. for (i = 0; i < pT120One->cResourceReqs; i++)
  1096. {
  1097. pT120One->aResourceReqs[i].eCommand = APPLET_JOIN_DYNAMIC_CHANNEL;
  1098. if (! ::DuplicateRegistryKey(&pT120One->aResourceReqs[i].RegKey,
  1099. (T120RegistryKey *) &pAppletRequest->aChannelRegistryKeys[i]))
  1100. {
  1101. goto MyError;
  1102. }
  1103. }
  1104. }
  1105. else
  1106. {
  1107. goto MyError;
  1108. }
  1109. }
  1110. return pT120One;
  1111. }
  1112. MyError:
  1113. ::FreeJoinSessionRequest(pT120One);
  1114. return NULL;
  1115. }
  1116. void FreeJoinSessionRequest
  1117. (
  1118. T120JoinSessionRequest *pT120One
  1119. )
  1120. {
  1121. if (NULL != pT120One)
  1122. {
  1123. ::FreeSessionKey(&pT120One->SessionKey);
  1124. ::FreeNonCollapsedCaps(pT120One->apNonCollapsedCaps, pT120One->cNonCollapsedCaps);
  1125. ::FreeCollapsedCaps(pT120One->apCollapsedCaps, pT120One->cCollapsedCaps);
  1126. if (pT120One->cStaticChannels)
  1127. {
  1128. delete [] pT120One->aStaticChannels;
  1129. }
  1130. if (pT120One->cResourceReqs)
  1131. {
  1132. for (ULONG i = 0; i < pT120One->cResourceReqs; i++)
  1133. {
  1134. ::FreeRegistryKey(&pT120One->aResourceReqs[i].RegKey);
  1135. }
  1136. delete [] pT120One->aResourceReqs;
  1137. }
  1138. delete pT120One;
  1139. }
  1140. }
  1141. BOOL ConvertCollapsedCaps(T120AppCap ***papDst, AppletCapability **apSrc, ULONG cItems)
  1142. {
  1143. if (cItems)
  1144. {
  1145. T120AppCap **arr_ptr;
  1146. ULONG cbTotalSize = cItems * (sizeof(T120AppCap*) + sizeof(T120AppCap));
  1147. if (NULL != (arr_ptr = (T120AppCap**) new BYTE[cbTotalSize]))
  1148. {
  1149. ::ZeroMemory(arr_ptr, cbTotalSize);
  1150. T120AppCap *arr_obj = (T120AppCap *) (arr_ptr + cItems);
  1151. for (ULONG i = 0; i < cItems; i++)
  1152. {
  1153. arr_ptr[i] = &arr_obj[i];
  1154. if (! ::DuplicateCollapsedCap(arr_ptr[i], (T120AppCap *) apSrc[i]))
  1155. {
  1156. ::FreeCollapsedCaps(arr_ptr, cItems);
  1157. return FALSE;
  1158. }
  1159. }
  1160. }
  1161. *papDst = arr_ptr;
  1162. return (NULL != arr_ptr);
  1163. }
  1164. *papDst = NULL;
  1165. return TRUE;
  1166. }
  1167. void FreeCollapsedCaps(T120AppCap **apDst, ULONG cItems)
  1168. {
  1169. if (cItems && NULL != apDst)
  1170. {
  1171. T120AppCap **arr_ptr = apDst;
  1172. T120AppCap *arr_obj = (T120AppCap *) (arr_ptr + cItems);
  1173. for (ULONG i = 0; i < cItems; i++)
  1174. {
  1175. ::FreeCollapsedCap(&arr_obj[i]);
  1176. }
  1177. delete [] (LPBYTE) arr_ptr;
  1178. }
  1179. }
  1180. BOOL DuplicateCollapsedCap(T120AppCap *pDst, T120AppCap *pSrc)
  1181. {
  1182. pDst->number_of_entities = pSrc->number_of_entities;
  1183. pDst->capability_class = pSrc->capability_class; // no memory allocation
  1184. return ::DuplicateCapID(&pDst->capability_id, &pSrc->capability_id);
  1185. }
  1186. void FreeCollapsedCap(T120AppCap *pDst)
  1187. {
  1188. ::FreeCapID(&pDst->capability_id);
  1189. }
  1190. BOOL DuplicateCapID(T120CapID *pDst, T120CapID *pSrc)
  1191. {
  1192. pDst->capability_id_type = pSrc->capability_id_type;
  1193. switch (pDst->capability_id_type)
  1194. {
  1195. case GCC_STANDARD_CAPABILITY:
  1196. pDst->standard_capability = pSrc->standard_capability;
  1197. return TRUE;
  1198. case GCC_NON_STANDARD_CAPABILITY:
  1199. return ::DuplicateObjectKey(&pDst->non_standard_capability, &pSrc->non_standard_capability);
  1200. }
  1201. return FALSE;
  1202. }
  1203. void FreeCapID(T120CapID *pDst)
  1204. {
  1205. switch (pDst->capability_id_type)
  1206. {
  1207. case GCC_NON_STANDARD_CAPABILITY:
  1208. ::FreeObjectKey(&pDst->non_standard_capability);
  1209. break;
  1210. }
  1211. }
  1212. BOOL ConvertNonCollapsedCaps(T120NonCollCap ***papDst, AppletCapability2 **apSrc, ULONG cItems)
  1213. {
  1214. if (cItems)
  1215. {
  1216. T120NonCollCap **arr_ptr;
  1217. ULONG cbTotalSize = cItems * (sizeof(T120NonCollCap*) + sizeof(T120NonCollCap));
  1218. if (NULL != (arr_ptr = (T120NonCollCap**) new BYTE[cbTotalSize]))
  1219. {
  1220. ::ZeroMemory(arr_ptr, cbTotalSize);
  1221. T120NonCollCap *arr_obj = (T120NonCollCap *) (arr_ptr + cItems);
  1222. for (ULONG i = 0; i < cItems; i++)
  1223. {
  1224. arr_ptr[i] = &arr_obj[i];
  1225. if (! ::DuplicateNonCollapsedCap(arr_ptr[i], (T120NonCollCap *) apSrc[i]))
  1226. {
  1227. ::FreeNonCollapsedCaps(arr_ptr, cItems);
  1228. return FALSE;
  1229. }
  1230. }
  1231. }
  1232. *papDst = arr_ptr;
  1233. return (NULL != arr_ptr);
  1234. }
  1235. *papDst = NULL;
  1236. return TRUE;
  1237. }
  1238. void FreeNonCollapsedCaps(T120NonCollCap **apDst, ULONG cItems)
  1239. {
  1240. if (cItems && NULL != apDst)
  1241. {
  1242. T120NonCollCap **arr_ptr = apDst;
  1243. T120NonCollCap *arr_obj = (T120NonCollCap *) (arr_ptr + cItems);
  1244. for (ULONG i = 0; i < cItems; i++)
  1245. {
  1246. ::FreeNonCollapsedCap(&arr_obj[i]);
  1247. }
  1248. delete [] (LPBYTE) arr_ptr;
  1249. }
  1250. }
  1251. BOOL DuplicateNonCollapsedCap(T120NonCollCap *pDst, T120NonCollCap *pSrc)
  1252. {
  1253. if (::DuplicateCapID(&pDst->capability_id, &pSrc->capability_id))
  1254. {
  1255. if (NULL == pSrc->application_data)
  1256. {
  1257. return TRUE;
  1258. }
  1259. if (NULL != (pDst->application_data = new OSTR))
  1260. {
  1261. return ::DuplicateOSTR(pDst->application_data, pSrc->application_data);
  1262. }
  1263. }
  1264. return FALSE;
  1265. }
  1266. void FreeNonCollapsedCap(T120NonCollCap *pDst)
  1267. {
  1268. ::FreeCapID(&pDst->capability_id);
  1269. if (NULL != pDst->application_data)
  1270. {
  1271. ::FreeOSTR(pDst->application_data);
  1272. delete pDst->application_data;
  1273. }
  1274. }
  1275. BOOL DuplicateRegistryKey(T120RegistryKey *pDst, T120RegistryKey *pSrc)
  1276. {
  1277. if (::DuplicateSessionKey(&pDst->session_key, &pSrc->session_key))
  1278. {
  1279. return ::DuplicateOSTR(&pDst->resource_id, &pSrc->resource_id);
  1280. }
  1281. return FALSE;
  1282. }
  1283. void FreeRegistryKey(T120RegistryKey *pDst)
  1284. {
  1285. ::FreeSessionKey(&pDst->session_key);
  1286. ::FreeOSTR(&pDst->resource_id);
  1287. }
  1288. BOOL DuplicateSessionKey(T120SessionKey *pDst, T120SessionKey *pSrc)
  1289. {
  1290. pDst->session_id = pSrc->session_id;
  1291. return ::DuplicateObjectKey(&pDst->application_protocol_key, &pSrc->application_protocol_key);
  1292. }
  1293. void FreeSessionKey(T120SessionKey *pDst)
  1294. {
  1295. ::FreeObjectKey(&pDst->application_protocol_key);
  1296. }
  1297. BOOL DuplicateObjectKey(T120ObjectKey *pDst, T120ObjectKey *pSrc)
  1298. {
  1299. pDst->key_type = pSrc->key_type;
  1300. switch (pDst->key_type)
  1301. {
  1302. case GCC_OBJECT_KEY:
  1303. pDst->object_id.long_string_length = pSrc->object_id.long_string_length;
  1304. if (pSrc->object_id.long_string_length && NULL != pSrc->object_id.long_string)
  1305. {
  1306. if (NULL != (pDst->object_id.long_string = new ULONG[pDst->object_id.long_string_length]))
  1307. {
  1308. ::CopyMemory(pDst->object_id.long_string,
  1309. pSrc->object_id.long_string,
  1310. pDst->object_id.long_string_length * sizeof(ULONG));
  1311. return TRUE;
  1312. }
  1313. }
  1314. break;
  1315. case GCC_H221_NONSTANDARD_KEY:
  1316. return ::DuplicateOSTR(&pDst->h221_non_standard_id, &pSrc->h221_non_standard_id);
  1317. }
  1318. return FALSE;
  1319. }
  1320. void FreeObjectKey(T120ObjectKey *pDst)
  1321. {
  1322. switch (pDst->key_type)
  1323. {
  1324. case GCC_OBJECT_KEY:
  1325. if (pDst->object_id.long_string_length)
  1326. {
  1327. delete [] pDst->object_id.long_string;
  1328. }
  1329. break;
  1330. case GCC_H221_NONSTANDARD_KEY:
  1331. ::FreeOSTR(&pDst->h221_non_standard_id);
  1332. break;
  1333. }
  1334. }
  1335. BOOL DuplicateOSTR(OSTR *pDst, OSTR *pSrc)
  1336. {
  1337. if (pSrc->length && NULL != pSrc->value)
  1338. {
  1339. pDst->length = pSrc->length;
  1340. if (NULL != (pDst->value = new BYTE[pDst->length]))
  1341. {
  1342. ::CopyMemory(pDst->value, pSrc->value, pDst->length);
  1343. return TRUE;
  1344. }
  1345. }
  1346. return FALSE;
  1347. }
  1348. void FreeOSTR(OSTR *pDst)
  1349. {
  1350. if (pDst->length)
  1351. {
  1352. delete [] pDst->value;
  1353. }
  1354. }
  1355. //////////////////////////////////////////////////
  1356. //
  1357. // Conversion
  1358. //
  1359. void AppletRegistryRequestToT120One
  1360. (
  1361. AppletRegistryRequest *pAppletRequest,
  1362. T120RegistryRequest *pT120One
  1363. )
  1364. {
  1365. pT120One->eCommand = pAppletRequest->eCommand;
  1366. pT120One->pRegistryKey = (T120RegistryKey *) &pAppletRequest->RegistryKey;
  1367. switch (pT120One->eCommand)
  1368. {
  1369. case APPLET_REGISTER_CHANNEL:
  1370. pT120One->nChannelID = pAppletRequest->nChannelID;
  1371. break;
  1372. case APPLET_SET_PARAMETER:
  1373. pT120One->Param.postrValue = (OSTR *) &pAppletRequest->ostrParamValue;
  1374. pT120One->Param.eModifyRights = pAppletRequest->eParamModifyRights;
  1375. break;
  1376. case APPLET_ALLOCATE_HANDLE:
  1377. pT120One->cHandles = pAppletRequest->cHandles;
  1378. break;
  1379. case APPLET_RETRIEVE_ENTRY:
  1380. case APPLET_DELETE_ENTRY:
  1381. case APPLET_ASSIGN_TOKEN:
  1382. case APPLET_MONITOR:
  1383. default:
  1384. break;
  1385. }
  1386. }
  1387. #ifdef _DEBUG
  1388. void CheckStructCompatible(void)
  1389. {
  1390. ASSERT(sizeof(AppletOctetString) == sizeof(OSTR));
  1391. ASSERT(FIELD_OFFSET(AppletOctetString, cbStrSize) == FIELD_OFFSET(OSTR, length));
  1392. ASSERT(FIELD_OFFSET(AppletOctetString, pbValue) == FIELD_OFFSET(OSTR, value));
  1393. ASSERT(sizeof(AppletLongString) == sizeof(T120LongString));
  1394. ASSERT(FIELD_OFFSET(AppletLongString, nStrLen) == FIELD_OFFSET(T120LongString, long_string_length));
  1395. ASSERT(FIELD_OFFSET(AppletLongString, pnValue) == FIELD_OFFSET(T120LongString, long_string));
  1396. ASSERT(sizeof(AppletObjectKey) == sizeof(T120ObjectKey));
  1397. ASSERT(FIELD_OFFSET(AppletObjectKey, eType) == FIELD_OFFSET(T120ObjectKey, key_type));
  1398. ASSERT(FIELD_OFFSET(AppletObjectKey, lstrObjectID) == FIELD_OFFSET(T120ObjectKey, object_id));
  1399. ASSERT(FIELD_OFFSET(AppletObjectKey, ostrH221NonStdID) == FIELD_OFFSET(T120ObjectKey, h221_non_standard_id));
  1400. ASSERT(sizeof(AppletSessionKey) == sizeof(T120SessionKey));
  1401. ASSERT(FIELD_OFFSET(AppletSessionKey, AppletProtocolKey) == FIELD_OFFSET(T120SessionKey, application_protocol_key));
  1402. ASSERT(FIELD_OFFSET(AppletSessionKey, nSessionID) == FIELD_OFFSET(T120SessionKey, session_id));
  1403. ASSERT(sizeof(AppletRegistryKey) == sizeof(T120RegistryKey));
  1404. ASSERT(FIELD_OFFSET(AppletRegistryKey, SessionKey) == FIELD_OFFSET(T120RegistryKey, session_key));
  1405. ASSERT(FIELD_OFFSET(AppletRegistryKey, ostrResourceID) == FIELD_OFFSET(T120RegistryKey, resource_id));
  1406. ASSERT(sizeof(AppletRegistryItem) == sizeof(T120RegistryItem));
  1407. ASSERT(FIELD_OFFSET(AppletRegistryItem, ItemType) == FIELD_OFFSET(T120RegistryItem, item_type));
  1408. ASSERT(FIELD_OFFSET(AppletRegistryItem, nChannelID) == FIELD_OFFSET(T120RegistryItem, channel_id));
  1409. ASSERT(FIELD_OFFSET(AppletRegistryItem, nTokenID) == FIELD_OFFSET(T120RegistryItem, token_id));
  1410. ASSERT(FIELD_OFFSET(AppletRegistryItem, ostrParamValue) == FIELD_OFFSET(T120RegistryItem, parameter));
  1411. ASSERT(sizeof(AppletRegistryEntryOwner) == sizeof(T120RegistryEntryOwner));
  1412. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, fEntryOwned) == FIELD_OFFSET(T120RegistryEntryOwner, entry_is_owned));
  1413. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, nOwnerNodeID) == FIELD_OFFSET(T120RegistryEntryOwner, owner_node_id));
  1414. ASSERT(FIELD_OFFSET(AppletRegistryEntryOwner, nOwnerEntityID) == FIELD_OFFSET(T120RegistryEntryOwner, owner_entity_id));
  1415. ASSERT(sizeof(AppletCapabilityID) == sizeof(T120CapID));
  1416. ASSERT(FIELD_OFFSET(AppletCapabilityID, eType) == FIELD_OFFSET(T120CapID, capability_id_type));
  1417. ASSERT(FIELD_OFFSET(AppletCapabilityID, nNonStdCap) == FIELD_OFFSET(T120CapID, non_standard_capability));
  1418. ASSERT(FIELD_OFFSET(AppletCapabilityID, nStdCap) == FIELD_OFFSET(T120CapID, standard_capability));
  1419. ASSERT(sizeof(AppletCapability) == sizeof(T120AppCap));
  1420. ASSERT(FIELD_OFFSET(AppletCapability, CapID) == FIELD_OFFSET(T120AppCap, capability_id));
  1421. ASSERT(FIELD_OFFSET(AppletCapability, CapClass) == FIELD_OFFSET(T120AppCap, capability_class));
  1422. ASSERT(FIELD_OFFSET(AppletCapability, cEntities) == FIELD_OFFSET(T120AppCap, number_of_entities));
  1423. ASSERT(sizeof(AppletCapability2) == sizeof(T120NonCollCap));
  1424. ASSERT(FIELD_OFFSET(AppletCapability2, CapID) == FIELD_OFFSET(T120NonCollCap, capability_id));
  1425. ASSERT(FIELD_OFFSET(AppletCapability2, pCapData) == FIELD_OFFSET(T120NonCollCap, application_data));
  1426. ASSERT(sizeof(AppletProtocolEntity) == sizeof(T120APE)); // array of structs vs array of pointers
  1427. ASSERT(FIELD_OFFSET(AppletProtocolEntity, SessionKey) == FIELD_OFFSET(T120APE, session_key));
  1428. ASSERT(FIELD_OFFSET(AppletProtocolEntity, eStartupChannelType) == FIELD_OFFSET(T120APE, startup_channel_type));
  1429. ASSERT(FIELD_OFFSET(AppletProtocolEntity, fMustBeInvoked) == FIELD_OFFSET(T120APE, must_be_invoked));
  1430. ASSERT(FIELD_OFFSET(AppletProtocolEntity, cExpectedCapabilities) == FIELD_OFFSET(T120APE, number_of_expected_capabilities));
  1431. ASSERT(FIELD_OFFSET(AppletProtocolEntity, apExpectedCapabilities) == FIELD_OFFSET(T120APE, expected_capabilities_list));
  1432. ASSERT(sizeof(AppletRecord) == sizeof(T120AppRecord)); // array of structs vs array of pointers
  1433. ASSERT(FIELD_OFFSET(AppletRecord, nNodeID) == FIELD_OFFSET(T120AppRecord, node_id));
  1434. ASSERT(FIELD_OFFSET(AppletRecord, nEntityID) == FIELD_OFFSET(T120AppRecord, entity_id));
  1435. ASSERT(FIELD_OFFSET(AppletRecord, fEnrolledActively) == FIELD_OFFSET(T120AppRecord, is_enrolled_actively));
  1436. ASSERT(FIELD_OFFSET(AppletRecord, fConductingCapable) == FIELD_OFFSET(T120AppRecord, is_conducting_capable));
  1437. ASSERT(FIELD_OFFSET(AppletRecord, eStartupChannelType) == FIELD_OFFSET(T120AppRecord, startup_channel_type));
  1438. ASSERT(FIELD_OFFSET(AppletRecord, nAppletUserID) == FIELD_OFFSET(T120AppRecord, application_user_id));
  1439. ASSERT(FIELD_OFFSET(AppletRecord, cCapabilities) == FIELD_OFFSET(T120AppRecord, number_of_non_collapsed_caps));
  1440. ASSERT(FIELD_OFFSET(AppletRecord, apCapabilities) == FIELD_OFFSET(T120AppRecord, non_collapsed_caps_list));
  1441. ASSERT(sizeof(AppletRoster) == sizeof(T120AppRoster)); // array of structs vs array of pointers
  1442. ASSERT(FIELD_OFFSET(AppletRoster, SessionKey) == FIELD_OFFSET(T120AppRoster, session_key));
  1443. ASSERT(FIELD_OFFSET(AppletRoster, fRosterChanged) == FIELD_OFFSET(T120AppRoster, application_roster_was_changed));
  1444. ASSERT(FIELD_OFFSET(AppletRoster, nInstanceNumber) == FIELD_OFFSET(T120AppRoster, instance_number));
  1445. ASSERT(FIELD_OFFSET(AppletRoster, fNodesAdded) == FIELD_OFFSET(T120AppRoster, nodes_were_added));
  1446. ASSERT(FIELD_OFFSET(AppletRoster, fNodesRemoved) == FIELD_OFFSET(T120AppRoster, nodes_were_removed));
  1447. ASSERT(FIELD_OFFSET(AppletRoster, fCapabilitiesChanged) == FIELD_OFFSET(T120AppRoster, capabilities_were_changed));
  1448. ASSERT(FIELD_OFFSET(AppletRoster, cRecords) == FIELD_OFFSET(T120AppRoster, number_of_records));
  1449. ASSERT(FIELD_OFFSET(AppletRoster, apAppletRecords) == FIELD_OFFSET(T120AppRoster, application_record_list));
  1450. ASSERT(FIELD_OFFSET(AppletRoster, cCapabilities) == FIELD_OFFSET(T120AppRoster, number_of_capabilities));
  1451. ASSERT(FIELD_OFFSET(AppletRoster, apCapabilities) == FIELD_OFFSET(T120AppRoster, capabilities_list));
  1452. ASSERT(sizeof(AppletChannelRequest) == sizeof(T120ChannelRequest));
  1453. ASSERT(FIELD_OFFSET(AppletChannelRequest, eCommand) == FIELD_OFFSET(T120ChannelRequest, eCommand));
  1454. ASSERT(FIELD_OFFSET(AppletChannelRequest, nChannelID) == FIELD_OFFSET(T120ChannelRequest, nChannelID));
  1455. ASSERT(FIELD_OFFSET(AppletChannelRequest, cUsers) == FIELD_OFFSET(T120ChannelRequest, cUsers));
  1456. ASSERT(FIELD_OFFSET(AppletChannelRequest, aUsers) == FIELD_OFFSET(T120ChannelRequest, aUsers));
  1457. ASSERT(sizeof(AppletTokenRequest) == sizeof(T120TokenRequest));
  1458. ASSERT(FIELD_OFFSET(AppletTokenRequest, eCommand) == FIELD_OFFSET(T120TokenRequest, eCommand));
  1459. ASSERT(FIELD_OFFSET(AppletTokenRequest, nTokenID) == FIELD_OFFSET(T120TokenRequest, nTokenID));
  1460. ASSERT(FIELD_OFFSET(AppletTokenRequest, uidGiveTo) == FIELD_OFFSET(T120TokenRequest, uidGiveTo));
  1461. ASSERT(FIELD_OFFSET(AppletTokenRequest, hrGiveResponse) == FIELD_OFFSET(T120TokenRequest, eGiveResponse));
  1462. }
  1463. #endif // _DEBUG
  1464.