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.

2803 lines
82 KiB

  1. /****************************************************************************
  2. *
  3. * $Archive: S:/STURGEON/SRC/CALLCONT/VCS/ccutils.c_v $
  4. *
  5. * INTEL Corporation Prorietary Information
  6. *
  7. * This listing is supplied under the terms of a license agreement
  8. * with INTEL Corporation and may not be copied nor disclosed except
  9. * in accordance with the terms of that agreement.
  10. *
  11. * Copyright (c) 1993-1994 Intel Corporation.
  12. *
  13. * $Revision: 1.107 $
  14. * $Date: 04 Mar 1997 17:34:44 $
  15. * $Author: MANDREWS $
  16. *
  17. * Deliverable:
  18. *
  19. * Abstract:
  20. *
  21. *
  22. * Notes:
  23. *
  24. ***************************************************************************/
  25. #include "precomp.h"
  26. #include "incommon.h"
  27. #include "callcont.h"
  28. #include "q931.h"
  29. #include "apierror.h"
  30. #include "ccmain.h"
  31. #include "chanman.h"
  32. #include "confman.h"
  33. #include "callman.h"
  34. #include "q931man.h"
  35. #include "userman.h"
  36. #include "ccutils.h"
  37. #include "linkapi.h"
  38. #include "h245man.h"
  39. extern CC_CONFERENCEID InvalidConferenceID;
  40. HANDLE ghCCLock = NULL;
  41. HRESULT InitializeCCLock(VOID)
  42. {
  43. ASSERT(ghCCLock == NULL);
  44. ghCCLock = CreateMutex(NULL, FALSE, NULL);
  45. if(ghCCLock == NULL)
  46. {
  47. return CC_INTERNAL_ERROR;
  48. }
  49. else
  50. {
  51. return CC_OK;
  52. }
  53. }
  54. VOID UnInitializeCCLock()
  55. {
  56. ASSERT(ghCCLock);
  57. if(ghCCLock)
  58. {
  59. CloseHandle(ghCCLock);
  60. }
  61. }
  62. VOID CCLOCK_AcquireLock()
  63. {
  64. DWORD dwStatus;
  65. ASSERT(ghCCLock);
  66. dwStatus = WaitForSingleObject(ghCCLock, INFINITE);
  67. if ((dwStatus != WAIT_OBJECT_0) && (dwStatus != WAIT_TIMEOUT))
  68. {
  69. ASSERT(0);
  70. }
  71. }
  72. VOID CCLOCK_RelinquishLock()
  73. {
  74. ASSERT(ghCCLock);
  75. ReleaseMutex(ghCCLock);
  76. }
  77. HRESULT InitializeLock( PLOCK pLock)
  78. {
  79. ASSERT(pLock != NULL);
  80. #ifdef _DEBUG
  81. InitializeCriticalSection(&pLock->LockInfoLock);
  82. pLock->wLockCount = 0;
  83. pLock->wNumQueuedThreads = 0;
  84. pLock->hOwningThread = 0;
  85. #endif
  86. pLock->Lock = CreateMutex(NULL, // security attributes
  87. FALSE, // initial owner
  88. NULL); // name
  89. if (pLock->Lock == NULL) {
  90. #ifdef _DEBUG
  91. DeleteCriticalSection(&pLock->LockInfoLock);
  92. #endif
  93. return CC_INTERNAL_ERROR;
  94. } else
  95. return CC_OK;
  96. }
  97. HRESULT DeleteLock( PLOCK pLock)
  98. {
  99. ASSERT(pLock != NULL);
  100. #ifdef _DEBUG
  101. DeleteCriticalSection(&pLock->LockInfoLock);
  102. #endif
  103. if (CloseHandle(pLock->Lock) == TRUE)
  104. return CC_OK;
  105. else
  106. return CC_INTERNAL_ERROR;
  107. }
  108. HRESULT AcquireLock( PLOCK pLock)
  109. {
  110. HRESULT status;
  111. ASSERT(pLock != NULL);
  112. status = AcquireTimedLock(pLock, INFINITE, NULL);
  113. return status;
  114. }
  115. HRESULT AcquireTimedLock( PLOCK pLock,
  116. DWORD dwTimeout,
  117. BOOL *pbTimedOut)
  118. {
  119. DWORD dwStatus;
  120. ASSERT(pLock != NULL);
  121. #ifdef _DEBUG
  122. EnterCriticalSection(&pLock->LockInfoLock);
  123. (pLock->wNumQueuedThreads)++;
  124. LeaveCriticalSection(&pLock->LockInfoLock);
  125. #endif
  126. dwStatus = WaitForSingleObject(pLock->Lock, dwTimeout);
  127. #ifdef _DEBUG
  128. EnterCriticalSection(&pLock->LockInfoLock);
  129. (pLock->wNumQueuedThreads)--;
  130. (pLock->wLockCount)++;
  131. pLock->hOwningThread = GetCurrentThread();
  132. LeaveCriticalSection(&pLock->LockInfoLock);
  133. #endif
  134. if ((dwStatus != WAIT_OBJECT_0) && (dwStatus != WAIT_TIMEOUT))
  135. return CC_INTERNAL_ERROR;
  136. if (dwStatus == WAIT_TIMEOUT) {
  137. if (pbTimedOut != NULL) {
  138. *pbTimedOut = TRUE;
  139. }
  140. } else {
  141. if (pbTimedOut != NULL) {
  142. *pbTimedOut = FALSE;
  143. }
  144. }
  145. return CC_OK;
  146. }
  147. HRESULT RelinquishLock( PLOCK pLock)
  148. {
  149. ASSERT(pLock != NULL);
  150. #ifdef _DEBUG
  151. EnterCriticalSection(&pLock->LockInfoLock);
  152. (pLock->wLockCount)--;
  153. if (pLock->wLockCount == 0)
  154. pLock->hOwningThread = 0;
  155. LeaveCriticalSection(&pLock->LockInfoLock);
  156. #endif
  157. if (ReleaseMutex(pLock->Lock) == TRUE)
  158. return CC_OK;
  159. else
  160. return CC_INTERNAL_ERROR;
  161. }
  162. HRESULT ValidateOctetString( PCC_OCTETSTRING pOctetString)
  163. {
  164. if (pOctetString == NULL)
  165. return CC_OK;
  166. if ((pOctetString->wOctetStringLength > 0) &&
  167. (pOctetString->pOctetString == NULL))
  168. return CC_BAD_PARAM;
  169. return CC_OK;
  170. }
  171. HRESULT CopyOctetString( PCC_OCTETSTRING *ppDest,
  172. PCC_OCTETSTRING pSource)
  173. {
  174. ASSERT(ppDest != NULL);
  175. if (pSource == NULL) {
  176. *ppDest = NULL;
  177. return CC_OK;
  178. }
  179. *ppDest = (PCC_OCTETSTRING)MemAlloc(sizeof(CC_OCTETSTRING));
  180. if (*ppDest == NULL)
  181. return CC_NO_MEMORY;
  182. (*ppDest)->wOctetStringLength = pSource->wOctetStringLength;
  183. if ((pSource->wOctetStringLength == 0) ||
  184. (pSource->pOctetString == NULL)) {
  185. pSource->wOctetStringLength = 0;
  186. (*ppDest)->pOctetString = NULL;
  187. } else {
  188. (*ppDest)->pOctetString = (BYTE *)MemAlloc(pSource->wOctetStringLength);
  189. if ((*ppDest)->pOctetString == NULL) {
  190. MemFree(*ppDest);
  191. *ppDest = NULL;
  192. return CC_NO_MEMORY;
  193. }
  194. memcpy((*ppDest)->pOctetString, pSource->pOctetString, pSource->wOctetStringLength);
  195. }
  196. return CC_OK;
  197. }
  198. HRESULT FreeOctetString( PCC_OCTETSTRING pOctetString)
  199. {
  200. if (pOctetString == NULL)
  201. return CC_OK;
  202. if ((pOctetString->wOctetStringLength > 0) &&
  203. (pOctetString->pOctetString != NULL))
  204. MemFree(pOctetString->pOctetString);
  205. MemFree(pOctetString);
  206. return CC_OK;
  207. }
  208. HRESULT CopySeparateStack( H245_ACCESS_T **ppDest,
  209. H245_ACCESS_T *pSource)
  210. {
  211. ASSERT(ppDest != NULL);
  212. if (pSource == NULL) {
  213. *ppDest = NULL;
  214. return CC_OK;
  215. }
  216. // We currently can't handle IP source route addresses,
  217. // since this address format contains embedded pointers
  218. // that cannot simply be copied
  219. if ((pSource->networkAddress.choice == localAreaAddress_chosen) &&
  220. (pSource->networkAddress.u.localAreaAddress.choice == unicastAddress_chosen) &&
  221. (pSource->networkAddress.u.localAreaAddress.u.unicastAddress.choice == iPSourceRouteAddress_chosen))
  222. return CC_NOT_IMPLEMENTED;
  223. *ppDest = (H245_ACCESS_T *)MemAlloc(sizeof(H245_ACCESS_T));
  224. if (*ppDest == NULL)
  225. return CC_NO_MEMORY;
  226. **ppDest = *pSource;
  227. return CC_OK;
  228. }
  229. HRESULT FreeSeparateStack( H245_ACCESS_T *pSeparateStack)
  230. {
  231. if (pSeparateStack == NULL)
  232. return CC_OK;
  233. MemFree(pSeparateStack);
  234. return CC_OK;
  235. }
  236. HRESULT ValidateNonStandardData( PCC_NONSTANDARDDATA pNonStandardData)
  237. {
  238. if (pNonStandardData == NULL)
  239. return CC_OK;
  240. return ValidateOctetString(&pNonStandardData->sData);
  241. }
  242. HRESULT CopyNonStandardData( PCC_NONSTANDARDDATA *ppDest,
  243. PCC_NONSTANDARDDATA pSource)
  244. {
  245. ASSERT(ppDest != NULL);
  246. if (pSource == NULL) {
  247. *ppDest = NULL;
  248. return CC_OK;
  249. }
  250. *ppDest = (PCC_NONSTANDARDDATA)MemAlloc(sizeof(CC_NONSTANDARDDATA));
  251. if (*ppDest == NULL)
  252. return CC_NO_MEMORY;
  253. **ppDest = *pSource;
  254. if ((pSource->sData.wOctetStringLength == 0) ||
  255. (pSource->sData.pOctetString == NULL)) {
  256. (*ppDest)->sData.wOctetStringLength = 0;
  257. (*ppDest)->sData.pOctetString = NULL;
  258. } else {
  259. (*ppDest)->sData.pOctetString = (BYTE *)MemAlloc(pSource->sData.wOctetStringLength);
  260. if ((*ppDest)->sData.pOctetString == NULL) {
  261. MemFree(*ppDest);
  262. return CC_NO_MEMORY;
  263. }
  264. memcpy((*ppDest)->sData.pOctetString,
  265. pSource->sData.pOctetString,
  266. pSource->sData.wOctetStringLength);
  267. }
  268. return CC_OK;
  269. }
  270. HRESULT FreeNonStandardData( PCC_NONSTANDARDDATA pNonStandardData)
  271. {
  272. if (pNonStandardData == NULL)
  273. return CC_OK;
  274. if ((pNonStandardData->sData.wOctetStringLength > 0) &&
  275. (pNonStandardData->sData.pOctetString != NULL))
  276. MemFree(pNonStandardData->sData.pOctetString);
  277. MemFree(pNonStandardData);
  278. return CC_OK;
  279. }
  280. HRESULT ValidateVendorInfo( PCC_VENDORINFO pVendorInfo)
  281. {
  282. HRESULT status;
  283. if (pVendorInfo == NULL)
  284. return CC_OK;
  285. status = ValidateOctetString(pVendorInfo->pProductNumber);
  286. if (status != CC_OK)
  287. return status;
  288. status = ValidateOctetString(pVendorInfo->pVersionNumber);
  289. return status;
  290. }
  291. HRESULT CopyVendorInfo( PCC_VENDORINFO *ppDest,
  292. PCC_VENDORINFO pSource)
  293. {
  294. HRESULT status;
  295. ASSERT(ppDest != NULL);
  296. if (pSource == NULL) {
  297. *ppDest = NULL;
  298. return CC_OK;
  299. }
  300. *ppDest = (PCC_VENDORINFO)MemAlloc(sizeof(CC_VENDORINFO));
  301. if (*ppDest == NULL)
  302. return CC_NO_MEMORY;
  303. **ppDest = *pSource;
  304. status = CopyOctetString(&(*ppDest)->pProductNumber, pSource->pProductNumber);
  305. if (status != CC_OK) {
  306. MemFree(*ppDest);
  307. return status;
  308. }
  309. status = CopyOctetString(&(*ppDest)->pVersionNumber, pSource->pVersionNumber);
  310. if (status != CC_OK) {
  311. FreeOctetString((*ppDest)->pProductNumber);
  312. MemFree(*ppDest);
  313. return status;
  314. }
  315. return CC_OK;
  316. }
  317. HRESULT FreeVendorInfo( PCC_VENDORINFO pVendorInfo)
  318. {
  319. if (pVendorInfo == NULL)
  320. return CC_OK;
  321. FreeOctetString(pVendorInfo->pProductNumber);
  322. FreeOctetString(pVendorInfo->pVersionNumber);
  323. MemFree(pVendorInfo);
  324. return CC_OK;
  325. }
  326. BOOL EqualConferenceIDs( PCC_CONFERENCEID pConferenceID1,
  327. PCC_CONFERENCEID pConferenceID2)
  328. {
  329. ASSERT(pConferenceID1 != NULL);
  330. ASSERT(pConferenceID2 != NULL);
  331. if (memcmp(pConferenceID1->buffer,
  332. pConferenceID2->buffer,
  333. sizeof(pConferenceID1->buffer)) == 0)
  334. return TRUE;
  335. else
  336. return FALSE;
  337. }
  338. BOOL EqualAddrs( PCC_ADDR pAddr1,
  339. PCC_ADDR pAddr2)
  340. {
  341. ASSERT(pAddr1 != NULL);
  342. ASSERT(pAddr2 != NULL);
  343. if (pAddr1->nAddrType != pAddr2->nAddrType)
  344. return FALSE;
  345. if (pAddr1->bMulticast != pAddr2->bMulticast)
  346. return FALSE;
  347. switch (pAddr1->nAddrType) {
  348. case CC_IP_DOMAIN_NAME:
  349. if ((pAddr1->Addr.IP_DomainName.wPort == pAddr2->Addr.IP_DomainName.wPort) &&
  350. (wcscmp(pAddr1->Addr.IP_DomainName.cAddr, pAddr2->Addr.IP_DomainName.cAddr) == 0))
  351. return TRUE;
  352. else
  353. return FALSE;
  354. case CC_IP_DOT:
  355. if ((pAddr1->Addr.IP_Dot.wPort == pAddr2->Addr.IP_Dot.wPort) &&
  356. (wcscmp(pAddr1->Addr.IP_Dot.cAddr, pAddr2->Addr.IP_Dot.cAddr) == 0))
  357. return TRUE;
  358. else
  359. return FALSE;
  360. case CC_IP_BINARY:
  361. if ((pAddr1->Addr.IP_Binary.wPort == pAddr2->Addr.IP_Binary.wPort) &&
  362. (pAddr1->Addr.IP_Binary.dwAddr == pAddr2->Addr.IP_Binary.dwAddr))
  363. return TRUE;
  364. else
  365. return FALSE;
  366. default:
  367. ASSERT(0);
  368. return FALSE;
  369. }
  370. }
  371. HRESULT ValidateTermCapList( PCC_TERMCAPLIST pTermCapList)
  372. {
  373. unsigned i, j;
  374. if (pTermCapList == NULL)
  375. return CC_OK;
  376. for (i = 0; i < pTermCapList->wLength; i++)
  377. if (pTermCapList->pTermCapArray[i] == NULL)
  378. return CC_BAD_PARAM;
  379. // make sure that all capability IDs are unique
  380. for (i = 0; i < pTermCapList->wLength; i++) {
  381. for (j = i + 1; j < pTermCapList->wLength; j++) {
  382. if (pTermCapList->pTermCapArray[i]->CapId == pTermCapList->pTermCapArray[j]->CapId)
  383. return CC_BAD_PARAM;
  384. }
  385. if ((pTermCapList->pTermCapArray[i]->CapId == H245_INVALID_CAPID) ||
  386. (pTermCapList->pTermCapArray[i]->CapId == 0))
  387. return CC_BAD_PARAM;
  388. }
  389. return CC_OK;
  390. }
  391. HRESULT ValidateTermCapDescriptors( PCC_TERMCAPDESCRIPTORS pTermCapDescriptors,
  392. PCC_TERMCAPLIST pTermCapList)
  393. {
  394. WORD i, j, k, l;
  395. H245_TOTCAPDESC_T *pTermCapDescriptor;
  396. H245_SIMCAP_T *pSimCaps;
  397. if (pTermCapDescriptors == NULL)
  398. return CC_OK;
  399. for (i = 0; i < pTermCapDescriptors->wLength; i++) {
  400. pTermCapDescriptor = pTermCapDescriptors->pTermCapDescriptorArray[i];
  401. if ((pTermCapDescriptor->CapDescId > 255) ||
  402. (pTermCapDescriptor->CapDesc.Length == 0) ||
  403. (pTermCapDescriptor->CapDesc.Length > H245_MAX_SIMCAPS))
  404. return CC_BAD_PARAM;
  405. for (j = i + 1; j < pTermCapDescriptors->wLength; j++) {
  406. if (pTermCapDescriptor->CapDescId ==
  407. pTermCapDescriptors->pTermCapDescriptorArray[j]->CapDescId) {
  408. return CC_BAD_PARAM;
  409. }
  410. }
  411. for (j = 0; j < pTermCapDescriptor->CapDesc.Length; j++) {
  412. pSimCaps = &(pTermCapDescriptor->CapDesc.SimCapArray[j]);
  413. if ((pSimCaps->Length == 0) ||
  414. (pSimCaps->Length > H245_MAX_ALTCAPS))
  415. return CC_BAD_PARAM;
  416. for (k = 0; k < pSimCaps->Length; k++) {
  417. for (l = 0; l < pTermCapList->wLength; l++) {
  418. if (pSimCaps->AltCaps[k] ==
  419. pTermCapList->pTermCapArray[l]->CapId)
  420. break;
  421. }
  422. if (l == pTermCapList->wLength)
  423. // the capability descriptor contains a capability ID
  424. // which is not present in the capability table
  425. return CC_BAD_PARAM;
  426. }
  427. }
  428. }
  429. return CC_OK;
  430. }
  431. HRESULT ValidateAddr( PCC_ADDR pAddr)
  432. {
  433. if (pAddr == NULL)
  434. return CC_OK;
  435. if ((pAddr->nAddrType != CC_IP_DOMAIN_NAME) &&
  436. (pAddr->nAddrType != CC_IP_DOT) &&
  437. (pAddr->nAddrType != CC_IP_BINARY))
  438. return CC_BAD_PARAM;
  439. return CC_OK;
  440. }
  441. HRESULT CopyAddr( PCC_ADDR *ppDest,
  442. PCC_ADDR pSource)
  443. {
  444. ASSERT(ppDest != NULL);
  445. if (pSource == NULL) {
  446. *ppDest = NULL;
  447. return CC_OK;
  448. }
  449. *ppDest = (PCC_ADDR)MemAlloc(sizeof(CC_ADDR));
  450. if (*ppDest == NULL)
  451. return CC_NO_MEMORY;
  452. **ppDest = *pSource;
  453. return CC_OK;
  454. }
  455. HRESULT FreeAddr( PCC_ADDR pAddr)
  456. {
  457. if (pAddr == NULL)
  458. return CC_OK;
  459. MemFree(pAddr);
  460. return CC_OK;
  461. }
  462. HRESULT SetQ931Port( PCC_ADDR pAddr)
  463. {
  464. if (pAddr == NULL)
  465. return CC_OK;
  466. switch (pAddr->nAddrType) {
  467. case CC_IP_DOMAIN_NAME:
  468. if (pAddr->Addr.IP_DomainName.wPort == 0)
  469. pAddr->Addr.IP_DomainName.wPort = CC_H323_HOST_CALL;
  470. return CC_OK;
  471. case CC_IP_DOT:
  472. if (pAddr->Addr.IP_Dot.wPort == 0)
  473. pAddr->Addr.IP_Dot.wPort = CC_H323_HOST_CALL;
  474. return CC_OK;
  475. case CC_IP_BINARY:
  476. if (pAddr->Addr.IP_Binary.wPort == 0)
  477. pAddr->Addr.IP_Binary.wPort = CC_H323_HOST_CALL;
  478. return CC_OK;
  479. }
  480. ASSERT(0);
  481. return CC_INTERNAL_ERROR;
  482. }
  483. HRESULT ValidateDisplay( PWSTR pszDisplay)
  484. {
  485. return CC_OK;
  486. }
  487. HRESULT CopyDisplay( PWSTR *ppDest,
  488. PWSTR pSource)
  489. {
  490. ASSERT(ppDest != NULL);
  491. if (pSource == NULL) {
  492. *ppDest = NULL;
  493. return CC_OK;
  494. }
  495. *ppDest = (WCHAR *)MemAlloc((wcslen(pSource)+1)*sizeof(WCHAR));
  496. if (*ppDest == NULL)
  497. return CC_NO_MEMORY;
  498. wcscpy(*ppDest, pSource);
  499. return CC_OK;
  500. }
  501. HRESULT FreeDisplay( PWSTR pszDisplay)
  502. {
  503. MemFree(pszDisplay);
  504. return CC_OK;
  505. }
  506. HRESULT ValidateTerminalID( PCC_OCTETSTRING pTerminalID)
  507. {
  508. return ValidateOctetString(pTerminalID);
  509. }
  510. HRESULT CopyTerminalID( PCC_OCTETSTRING *ppDest,
  511. PCC_OCTETSTRING pSource)
  512. {
  513. ASSERT(ppDest != NULL);
  514. return CopyOctetString(ppDest, pSource);
  515. }
  516. HRESULT FreeTerminalID( PCC_OCTETSTRING pTerminalID)
  517. {
  518. return FreeOctetString(pTerminalID);
  519. }
  520. HRESULT SetTerminalType( TRISTATE tsMultipointController,
  521. BYTE *pbTerminalType)
  522. {
  523. switch (tsMultipointController) {
  524. case TS_TRUE:
  525. *pbTerminalType = 240;
  526. break;
  527. case TS_UNKNOWN:
  528. *pbTerminalType = 70;
  529. break;
  530. case TS_FALSE:
  531. *pbTerminalType = 50;
  532. break;
  533. default:
  534. ASSERT(0);
  535. *pbTerminalType = 0;
  536. break;
  537. }
  538. return CC_OK;
  539. }
  540. HRESULT CopyH245TermCapList( PCC_TERMCAPLIST *ppDest,
  541. PCC_TERMCAPLIST pSource)
  542. {
  543. WORD i;
  544. HRESULT status;
  545. ASSERT(ppDest != NULL);
  546. if (pSource == NULL) {
  547. *ppDest = NULL;
  548. return CC_OK;
  549. }
  550. *ppDest = (PCC_TERMCAPLIST)MemAlloc(sizeof(CC_TERMCAPLIST));
  551. if (*ppDest == NULL)
  552. return CC_NO_MEMORY;
  553. (*ppDest)->wLength = pSource->wLength;
  554. (*ppDest)->pTermCapArray =
  555. (PPCC_TERMCAP)MemAlloc(sizeof(PCC_TERMCAP) * pSource->wLength);
  556. if ((*ppDest)->pTermCapArray == NULL) {
  557. (*ppDest)->wLength = 0;
  558. DestroyH245TermCapList(ppDest);
  559. return CC_NO_MEMORY;
  560. }
  561. for (i = 0; i < pSource->wLength; i++) {
  562. status = H245CopyCap(&((*ppDest)->pTermCapArray[i]), pSource->pTermCapArray[i]);
  563. if (status != H245_ERROR_OK) {
  564. (*ppDest)->wLength = i;
  565. DestroyH245TermCapList(ppDest);
  566. return status;
  567. }
  568. }
  569. return CC_OK;
  570. }
  571. HRESULT CopyH245TermCapDescriptors( PCC_TERMCAPDESCRIPTORS *ppDest,
  572. PCC_TERMCAPDESCRIPTORS pSource)
  573. {
  574. WORD i;
  575. HRESULT status;
  576. ASSERT(ppDest != NULL);
  577. if (pSource == NULL) {
  578. *ppDest = NULL;
  579. return CC_OK;
  580. }
  581. (*ppDest) = (PCC_TERMCAPDESCRIPTORS)MemAlloc(sizeof(CC_TERMCAPDESCRIPTORS));
  582. if (*ppDest == NULL)
  583. return CC_NO_MEMORY;
  584. (*ppDest)->wLength = pSource->wLength;
  585. (*ppDest)->pTermCapDescriptorArray = (H245_TOTCAPDESC_T **)MemAlloc(sizeof(H245_TOTCAPDESC_T *) *
  586. pSource->wLength);
  587. if ((*ppDest)->pTermCapDescriptorArray == NULL) {
  588. (*ppDest)->wLength = 0;
  589. DestroyH245TermCapDescriptors(ppDest);
  590. return CC_NO_MEMORY;
  591. }
  592. for (i = 0; i < pSource->wLength; i++) {
  593. status = H245CopyCapDescriptor(&((*ppDest)->pTermCapDescriptorArray[i]),
  594. pSource->pTermCapDescriptorArray[i]);
  595. if (status != H245_ERROR_OK) {
  596. (*ppDest)->wLength = i;
  597. DestroyH245TermCapDescriptors(ppDest);
  598. return status;
  599. }
  600. }
  601. return CC_OK;
  602. }
  603. HRESULT CreateH245DefaultTermCapDescriptors(
  604. PCC_TERMCAPDESCRIPTORS *ppDest,
  605. PCC_TERMCAPLIST pTermCapList)
  606. {
  607. H245_TOTCAPDESC_T TermCapDescriptor;
  608. WORD i;
  609. HRESULT status;
  610. ASSERT(ppDest != NULL);
  611. if (pTermCapList == NULL) {
  612. *ppDest = NULL;
  613. return CC_OK;
  614. }
  615. *ppDest = (PCC_TERMCAPDESCRIPTORS)MemAlloc(sizeof(CC_TERMCAPDESCRIPTORS));
  616. if (*ppDest == NULL)
  617. return CC_NO_MEMORY;
  618. if (pTermCapList->wLength == 0) {
  619. (*ppDest)->wLength = 0;
  620. (*ppDest)->pTermCapDescriptorArray = NULL;
  621. return CC_OK;
  622. }
  623. (*ppDest)->wLength = 1;
  624. (*ppDest)->pTermCapDescriptorArray = (H245_TOTCAPDESC_T **)MemAlloc(sizeof(H245_TOTCAPDESC_T *));
  625. if ((*ppDest)->pTermCapDescriptorArray == NULL) {
  626. (*ppDest)->wLength = 0;
  627. DestroyH245TermCapDescriptors(ppDest);
  628. return CC_NO_MEMORY;
  629. }
  630. TermCapDescriptor.CapDesc.Length = pTermCapList->wLength;
  631. TermCapDescriptor.CapDescId = 0;
  632. for (i = 0; i < pTermCapList->wLength; i++) {
  633. TermCapDescriptor.CapDesc.SimCapArray[i].Length = 1;
  634. TermCapDescriptor.CapDesc.SimCapArray[i].AltCaps[0] =
  635. pTermCapList->pTermCapArray[i]->CapId;
  636. }
  637. status = H245CopyCapDescriptor(&((*ppDest)->pTermCapDescriptorArray[0]),
  638. &TermCapDescriptor);
  639. if (status != H245_ERROR_OK) {
  640. (*ppDest)->wLength = 0;
  641. DestroyH245TermCapDescriptors(ppDest);
  642. return status;
  643. }
  644. return CC_OK;
  645. }
  646. HRESULT DestroyH245TermCap( PPCC_TERMCAP ppTermCap)
  647. {
  648. ASSERT(ppTermCap != NULL);
  649. if (*ppTermCap == NULL)
  650. return CC_OK;
  651. H245FreeCap(*ppTermCap);
  652. *ppTermCap = NULL;
  653. return CC_OK;
  654. }
  655. HRESULT UnregisterTermCapListFromH245(
  656. PCONFERENCE pConference,
  657. PCC_TERMCAPLIST pTermCapList)
  658. {
  659. WORD i, j;
  660. PCALL pCall;
  661. PCC_HCALL CallList;
  662. WORD wNumCalls;
  663. HRESULT status;
  664. HRESULT SaveStatus;
  665. ASSERT(pConference != NULL);
  666. if (pTermCapList == NULL)
  667. return CC_OK;
  668. EnumerateCallsInConference(&wNumCalls, &CallList, pConference, ESTABLISHED_CALL);
  669. SaveStatus = CC_OK;
  670. for (i = 0; i < pTermCapList->wLength; i++) {
  671. ASSERT(pTermCapList->pTermCapArray[i] != NULL);
  672. for (j = 0; j < wNumCalls; j++) {
  673. if (LockCall(CallList[j], &pCall) == CC_OK) {
  674. status = H245DelLocalCap(pCall->H245Instance,
  675. pTermCapList->pTermCapArray[i]->CapId);
  676. if (status != CC_OK)
  677. SaveStatus = status;
  678. UnlockCall(pCall);
  679. }
  680. }
  681. }
  682. if (CallList != NULL)
  683. MemFree(CallList);
  684. return SaveStatus;
  685. }
  686. HRESULT DestroyH245TermCapList( PCC_TERMCAPLIST *ppTermCapList)
  687. {
  688. WORD i;
  689. ASSERT(ppTermCapList != NULL);
  690. if (*ppTermCapList == NULL)
  691. return CC_OK;
  692. for (i = 0; i < (*ppTermCapList)->wLength; i++) {
  693. ASSERT((*ppTermCapList)->pTermCapArray[i] != NULL);
  694. H245FreeCap((*ppTermCapList)->pTermCapArray[i]);
  695. }
  696. if ((*ppTermCapList)->pTermCapArray != NULL)
  697. MemFree((*ppTermCapList)->pTermCapArray);
  698. MemFree(*ppTermCapList);
  699. *ppTermCapList = NULL;
  700. return CC_OK;
  701. }
  702. HRESULT UnregisterTermCapDescriptorsFromH245(
  703. PCONFERENCE pConference,
  704. PCC_TERMCAPDESCRIPTORS pTermCapDescriptors)
  705. {
  706. WORD i, j;
  707. PCALL pCall;
  708. PCC_HCALL CallList;
  709. WORD wNumCalls;
  710. HRESULT status;
  711. HRESULT SaveStatus;
  712. ASSERT(pConference != NULL);
  713. if (pTermCapDescriptors == NULL)
  714. return CC_OK;
  715. EnumerateCallsInConference(&wNumCalls, &CallList, pConference, ESTABLISHED_CALL);
  716. SaveStatus = CC_OK;
  717. for (i = 0; i < pTermCapDescriptors->wLength; i++) {
  718. ASSERT(pTermCapDescriptors->pTermCapDescriptorArray[i] != NULL);
  719. for (j = 0; j < wNumCalls; j++) {
  720. if (LockCall(CallList[j], &pCall) == CC_OK) {
  721. status = H245DelCapDescriptor(pCall->H245Instance,
  722. pTermCapDescriptors->pTermCapDescriptorArray[i]->CapDescId);
  723. if (status != CC_OK)
  724. SaveStatus = status;
  725. UnlockCall(pCall);
  726. }
  727. }
  728. }
  729. if (CallList != NULL)
  730. MemFree(CallList);
  731. return SaveStatus;
  732. }
  733. HRESULT DestroyH245TermCapDescriptors( PCC_TERMCAPDESCRIPTORS *ppTermCapDescriptors)
  734. {
  735. WORD i;
  736. ASSERT(ppTermCapDescriptors != NULL);
  737. if (*ppTermCapDescriptors == NULL)
  738. return CC_OK;
  739. for (i = 0; i < (*ppTermCapDescriptors)->wLength; i++) {
  740. ASSERT((*ppTermCapDescriptors)->pTermCapDescriptorArray[i] != NULL);
  741. H245FreeCapDescriptor((*ppTermCapDescriptors)->pTermCapDescriptorArray[i]);
  742. }
  743. if ((*ppTermCapDescriptors)->pTermCapDescriptorArray != NULL)
  744. MemFree((*ppTermCapDescriptors)->pTermCapDescriptorArray);
  745. MemFree(*ppTermCapDescriptors);
  746. *ppTermCapDescriptors = NULL;
  747. return CC_OK;
  748. }
  749. HRESULT HostToH245IPNetwork( BYTE *NetworkArray,
  750. DWORD dwAddr)
  751. {
  752. if (NetworkArray == NULL) {
  753. ASSERT(0);
  754. return CC_BAD_PARAM;
  755. }
  756. NetworkArray[0] = HIBYTE(HIWORD(dwAddr));
  757. NetworkArray[1] = LOBYTE(HIWORD(dwAddr));
  758. NetworkArray[2] = HIBYTE(LOWORD(dwAddr));
  759. NetworkArray[3] = LOBYTE(LOWORD(dwAddr));
  760. return CC_OK;
  761. }
  762. HRESULT H245IPNetworkToHost( DWORD *pdwAddr,
  763. BYTE *NetworkArray)
  764. {
  765. if ((pdwAddr == NULL) || (NetworkArray == NULL)) {
  766. ASSERT(0);
  767. return CC_BAD_PARAM;
  768. }
  769. *pdwAddr = NetworkArray[0] * 0x01000000 +
  770. NetworkArray[1] * 0x00010000 +
  771. NetworkArray[2] * 0x00000100 +
  772. NetworkArray[3] * 0x00000001;
  773. return CC_OK;
  774. }
  775. HRESULT ProcessRemoteHangup( CC_HCALL hCall,
  776. HQ931CALL hQ931Initiator,
  777. BYTE bHangupReason)
  778. {
  779. PCALL pCall;
  780. CC_HCONFERENCE hConference;
  781. PCONFERENCE pConference;
  782. HRESULT status;
  783. HQ931CALL hQ931Call;
  784. H245_INST_T H245Instance;
  785. PCHANNEL pChannel;
  786. WORD wNumChannels;
  787. PCC_HCHANNEL ChannelList;
  788. WORD i;
  789. WORD wNumCalls;
  790. PCC_HCALL CallList;
  791. PCALL pOldCall;
  792. CC_CONNECT_CALLBACK_PARAMS ConnectCallbackParams;
  793. CC_PEER_DROP_CALLBACK_PARAMS PeerDropCallbackParams;
  794. CC_PEER_CHANGE_CAP_CALLBACK_PARAMS PeerChangeCapCallbackParams;
  795. BOOL bConferenceTermCapsChanged;
  796. HRESULT CallbackStatus;
  797. if (hCall == CC_INVALID_HANDLE)
  798. return CC_BAD_PARAM;
  799. status = LockCallAndConference(hCall, &pCall, &pConference);
  800. if (status != CC_OK)
  801. return CC_BAD_PARAM;
  802. hConference = pCall->hConference;
  803. hQ931Call = pCall->hQ931Call;
  804. H245Instance = pCall->H245Instance;
  805. PeerDropCallbackParams.hCall = pCall->hCall;
  806. if (pCall->pPeerParticipantInfo == NULL) {
  807. PeerDropCallbackParams.TerminalLabel.bMCUNumber = 255;
  808. PeerDropCallbackParams.TerminalLabel.bTerminalNumber = 255;
  809. PeerDropCallbackParams.pPeerTerminalID = NULL;
  810. } else {
  811. PeerDropCallbackParams.TerminalLabel = pCall->pPeerParticipantInfo->ParticipantInfo.TerminalLabel;
  812. if (pCall->pPeerParticipantInfo->TerminalIDState == TERMINAL_ID_VALID)
  813. PeerDropCallbackParams.pPeerTerminalID = &pCall->pPeerParticipantInfo->ParticipantInfo.TerminalID;
  814. else
  815. PeerDropCallbackParams.pPeerTerminalID = NULL;
  816. }
  817. if ((pConference->ConferenceMode == MULTIPOINT_MODE) &&
  818. (pConference->tsMultipointController == TS_TRUE))
  819. CreateConferenceTermCaps(pConference, &bConferenceTermCapsChanged);
  820. else
  821. bConferenceTermCapsChanged = FALSE;
  822. // Remove all TX, RX and PROXY channels associated with this call
  823. EnumerateChannelsInConference(&wNumChannels,
  824. &ChannelList,
  825. pConference,
  826. TX_CHANNEL | RX_CHANNEL | PROXY_CHANNEL);
  827. for (i = 0; i < wNumChannels; i++) {
  828. if (LockChannel(ChannelList[i], &pChannel) == CC_OK) {
  829. if (pChannel->hCall == hCall)
  830. FreeChannel(pChannel);
  831. else
  832. UnlockChannel(pChannel);
  833. }
  834. }
  835. if (ChannelList != NULL)
  836. MemFree(ChannelList);
  837. switch (bHangupReason)
  838. {
  839. case CC_REJECT_NORMAL_CALL_CLEARING:
  840. CallbackStatus = CC_OK;
  841. break;
  842. case CC_REJECT_GATEKEEPER_TERMINATED:
  843. CallbackStatus = CC_GATEKEEPER_REFUSED;
  844. bHangupReason = CC_REJECT_NORMAL_CALL_CLEARING;
  845. break;
  846. default:
  847. CallbackStatus = CC_PEER_REJECT;
  848. } // switch
  849. if (pCall->CallType == THIRD_PARTY_INVITOR) {
  850. MarkCallForDeletion(pCall);
  851. ConnectCallbackParams.pNonStandardData = pCall->pPeerNonStandardData;
  852. ConnectCallbackParams.pszPeerDisplay = pCall->pszPeerDisplay;
  853. ConnectCallbackParams.bRejectReason = bHangupReason;
  854. ConnectCallbackParams.pTermCapList = pCall->pPeerH245TermCapList;
  855. ConnectCallbackParams.pH2250MuxCapability = pCall->pPeerH245H2250MuxCapability;
  856. ConnectCallbackParams.pTermCapDescriptors = pCall->pPeerH245TermCapDescriptors;
  857. ConnectCallbackParams.pLocalAddr = pCall->pQ931LocalConnectAddr;
  858. if (pCall->pQ931DestinationAddr == NULL)
  859. ConnectCallbackParams.pPeerAddr = pCall->pQ931PeerConnectAddr;
  860. else
  861. ConnectCallbackParams.pPeerAddr = pCall->pQ931DestinationAddr;
  862. ConnectCallbackParams.pVendorInfo = pCall->pPeerVendorInfo;
  863. ConnectCallbackParams.bMultipointConference = TRUE;
  864. ConnectCallbackParams.pConferenceID = &pConference->ConferenceID;
  865. ConnectCallbackParams.pMCAddress = pConference->pMultipointControllerAddr;
  866. ConnectCallbackParams.pAlternateAddress = NULL;
  867. ConnectCallbackParams.dwUserToken = pCall->dwUserToken;
  868. InvokeUserConferenceCallback(pConference,
  869. CC_CONNECT_INDICATION,
  870. CallbackStatus,
  871. &ConnectCallbackParams);
  872. // Need to validate the conference and call handles; the associated
  873. // objects may have been deleted during user callback on this thread
  874. if (ValidateConference(hConference) == CC_OK)
  875. UnlockConference(pConference);
  876. if (ValidateCallMarkedForDeletion(hCall) == CC_OK)
  877. FreeCall(pCall);
  878. Q931Hangup(hQ931Call, bHangupReason);
  879. return CC_OK;
  880. }
  881. if (pCall->CallType == THIRD_PARTY_INTERMEDIARY) {
  882. if ((hQ931Initiator == pCall->hQ931CallInvitor) &&
  883. (hQ931Initiator != CC_INVALID_HANDLE)) {
  884. pCall->hQ931CallInvitor = CC_INVALID_HANDLE;
  885. UnlockCall(pCall);
  886. UnlockConference(pConference);
  887. return CC_OK;
  888. } else {
  889. if (pCall->CallState != CALL_COMPLETE) {
  890. if (pCall->hQ931CallInvitor != CC_INVALID_HANDLE)
  891. Q931Hangup(pCall->hQ931CallInvitor, CC_REJECT_UNDEFINED_REASON);
  892. if (ValidateCall(hCall) == CC_OK)
  893. Q931Hangup(pCall->hQ931Call, bHangupReason);
  894. }
  895. }
  896. }
  897. if ((pConference->ConferenceMode == MULTIPOINT_MODE) &&
  898. (pConference->tsMultipointController == TS_TRUE)) {
  899. if (pCall->pPeerParticipantInfo != NULL) {
  900. EnumerateCallsInConference(&wNumCalls,
  901. &CallList,
  902. pConference,
  903. ESTABLISHED_CALL);
  904. for (i = 0; i < wNumCalls; i++) {
  905. if (CallList[i] != hCall) {
  906. if (LockCall(CallList[i], &pOldCall) == CC_OK) {
  907. if (pCall->pPeerParticipantInfo != NULL)
  908. H245ConferenceIndication(
  909. pOldCall->H245Instance,
  910. H245_IND_TERMINAL_LEFT, // Indication Type
  911. 0, // SBE number; ignored here
  912. pCall->pPeerParticipantInfo->ParticipantInfo.TerminalLabel.bMCUNumber, // MCU number
  913. pCall->pPeerParticipantInfo->ParticipantInfo.TerminalLabel.bTerminalNumber);
  914. if (bConferenceTermCapsChanged)
  915. // Send new term caps
  916. SendTermCaps(pOldCall, pConference);
  917. UnlockCall(pOldCall);
  918. }
  919. }
  920. }
  921. if (CallList != NULL)
  922. MemFree(CallList);
  923. }
  924. InvokeUserConferenceCallback(pConference,
  925. CC_PEER_DROP_INDICATION,
  926. CC_OK,
  927. &PeerDropCallbackParams);
  928. if (ValidateCall(hCall) == CC_OK)
  929. FreeCall(pCall);
  930. if (ValidateConference(hConference) == CC_OK) {
  931. if (bConferenceTermCapsChanged) {
  932. // Generate CC_PEER_CHANGE_CAP callback
  933. PeerChangeCapCallbackParams.pTermCapList =
  934. pConference->pConferenceTermCapList;
  935. PeerChangeCapCallbackParams.pH2250MuxCapability =
  936. pConference->pConferenceH245H2250MuxCapability;
  937. PeerChangeCapCallbackParams.pTermCapDescriptors =
  938. pConference->pConferenceTermCapDescriptors;
  939. InvokeUserConferenceCallback(pConference,
  940. CC_PEER_CHANGE_CAP_INDICATION,
  941. CC_OK,
  942. &PeerChangeCapCallbackParams);
  943. }
  944. }
  945. if (ValidateConference(hConference) == CC_OK) {
  946. if (pConference->bDeferredDelete) {
  947. ASSERT(pConference->LocalEndpointAttached == DETACHED);
  948. EnumerateCallsInConference(&wNumCalls, NULL, pConference, ALL_CALLS);
  949. if (wNumCalls == 0) {
  950. FreeConference(pConference);
  951. return CC_OK;
  952. }
  953. }
  954. UnlockConference(pConference);
  955. }
  956. return CC_OK;
  957. } else {
  958. status = EnumerateChannelsInConference(&wNumChannels,
  959. &ChannelList,
  960. pConference,
  961. ALL_CHANNELS);
  962. if (status == CC_OK) {
  963. // free all the channels
  964. for (i = 0; i < wNumChannels; i++) {
  965. if (LockChannel(ChannelList[i], &pChannel) == CC_OK)
  966. // Notice that since we're going to hangup, we don't need to
  967. // close any channels
  968. FreeChannel(pChannel);
  969. }
  970. if (ChannelList != NULL)
  971. MemFree(ChannelList);
  972. }
  973. if (H245Instance != H245_INVALID_ID)
  974. status = H245ShutDown(H245Instance);
  975. else
  976. status = H245_ERROR_OK;
  977. if (status == H245_ERROR_OK) {
  978. status = Q931Hangup(hQ931Call, CC_REJECT_NORMAL_CALL_CLEARING);
  979. // Q931Hangup may legitimately return CS_BAD_PARAM, because the Q.931 call object
  980. // may have been deleted at this point
  981. if (status == CS_BAD_PARAM)
  982. status = CC_OK;
  983. } else
  984. Q931Hangup(hQ931Call, CC_REJECT_UNDEFINED_REASON);
  985. if (pConference->bDeferredDelete) {
  986. ASSERT(pConference->LocalEndpointAttached == DETACHED);
  987. FreeConference(pConference);
  988. } else {
  989. ReInitializeConference(pConference);
  990. InvokeUserConferenceCallback(pConference,
  991. CC_CONFERENCE_TERMINATION_INDICATION,
  992. CallbackStatus,
  993. NULL);
  994. if (ValidateConference(hConference) == CC_OK)
  995. UnlockConference(pConference);
  996. }
  997. return CC_OK;
  998. }
  999. // We should never reach this point
  1000. ASSERT(0);
  1001. }
  1002. HRESULT DefaultSessionTableConstructor(
  1003. CC_HCONFERENCE hConference,
  1004. DWORD_PTR dwConferenceToken,
  1005. BOOL bCreate,
  1006. BOOL *pbSessionTableChanged,
  1007. WORD wListCount,
  1008. PCC_TERMCAPLIST pTermCapList[],
  1009. PCC_TERMCAPDESCRIPTORS pTermCapDescriptors[],
  1010. PCC_SESSIONTABLE *ppSessionTable)
  1011. {
  1012. WORD i;
  1013. HRESULT status;
  1014. PCONFERENCE pConference;
  1015. WORD wNumChannels;
  1016. PCC_HCHANNEL ChannelList;
  1017. PCHANNEL pChannel;
  1018. WORD wNumCalls;
  1019. PCC_HCALL CallList;
  1020. PCALL pCall;
  1021. BYTE bSessionID;
  1022. WORD wPort;
  1023. DWORD dwAddr;
  1024. WCHAR szSessionDescription[100];
  1025. WCHAR ss[10];
  1026. ASSERT(hConference != CC_INVALID_HANDLE);
  1027. ASSERT(ppSessionTable != NULL);
  1028. if (*ppSessionTable != NULL) {
  1029. for (i = 0; i < (*ppSessionTable)->wLength; i++) {
  1030. if ((*ppSessionTable)->SessionInfoArray[i].pTermCap != NULL)
  1031. H245FreeCap((*ppSessionTable)->SessionInfoArray[i].pTermCap);
  1032. FreeAddr((*ppSessionTable)->SessionInfoArray[i].pRTPAddr);
  1033. FreeAddr((*ppSessionTable)->SessionInfoArray[i].pRTCPAddr);
  1034. }
  1035. if ((*ppSessionTable)->SessionInfoArray != NULL)
  1036. MemFree((*ppSessionTable)->SessionInfoArray);
  1037. MemFree(*ppSessionTable);
  1038. *ppSessionTable = NULL;
  1039. }
  1040. if (bCreate == FALSE)
  1041. return CC_OK;
  1042. *ppSessionTable = NULL;
  1043. if (pbSessionTableChanged != NULL)
  1044. *pbSessionTableChanged = FALSE;
  1045. status = LockConference(hConference, &pConference);
  1046. if (status != CC_OK)
  1047. return status;
  1048. if ((pConference->ConferenceMode == UNCONNECTED_MODE) ||
  1049. (pConference->ConferenceMode == POINT_TO_POINT_MODE)) {
  1050. UnlockConference(pConference);
  1051. return CC_BAD_PARAM;
  1052. }
  1053. // pConference->ConferenceMode == MULTIPOINT_MODE
  1054. // Create one session entry for each open channel on this conference
  1055. bSessionID = 1;
  1056. wPort = 2050;
  1057. // Set dwAddr
  1058. EnumerateCallsInConference(&wNumCalls, &CallList, pConference, ESTABLISHED_CALL);
  1059. if (wNumCalls == 0) {
  1060. UnlockConference(pConference);
  1061. return CC_INTERNAL_ERROR;
  1062. }
  1063. status = LockCall(CallList[0], &pCall);
  1064. if (status != CC_OK) {
  1065. MemFree(CallList);
  1066. UnlockConference(pConference);
  1067. return status;
  1068. }
  1069. if (pCall->pQ931LocalConnectAddr == NULL) {
  1070. MemFree(CallList);
  1071. UnlockCall(pCall);
  1072. UnlockConference(pConference);
  1073. return CC_INTERNAL_ERROR;
  1074. }
  1075. if (pCall->pQ931LocalConnectAddr->nAddrType != CC_IP_BINARY) {
  1076. MemFree(CallList);
  1077. UnlockCall(pCall);
  1078. UnlockConference(pConference);
  1079. return CC_INTERNAL_ERROR;
  1080. }
  1081. // Construct dwAddr from one of the unicast Q.931 addresses by setting the high
  1082. // nibble of the Q.931 address to 0xE
  1083. dwAddr = (pCall->pQ931LocalConnectAddr->Addr.IP_Binary.dwAddr & 0xEFFFFFFF) | 0xE0000000;
  1084. UnlockCall(pCall);
  1085. MemFree(CallList);
  1086. EnumerateChannelsInConference(&wNumChannels, &ChannelList, pConference, TX_CHANNEL);
  1087. *ppSessionTable = (PCC_SESSIONTABLE)MemAlloc(sizeof(CC_SESSIONTABLE));
  1088. if (*ppSessionTable == NULL) {
  1089. MemFree(ChannelList);
  1090. UnlockConference(pConference);
  1091. return CC_NO_MEMORY;
  1092. }
  1093. (*ppSessionTable)->wLength = wNumChannels;
  1094. if (wNumChannels == 0)
  1095. (*ppSessionTable)->SessionInfoArray = NULL;
  1096. else {
  1097. (*ppSessionTable)->SessionInfoArray =
  1098. (PCC_SESSIONINFO)MemAlloc(sizeof(CC_SESSIONINFO) * wNumChannels);
  1099. if ((*ppSessionTable)->SessionInfoArray == NULL) {
  1100. MemFree(ChannelList);
  1101. UnlockConference(pConference);
  1102. (*ppSessionTable)->wLength = 0;
  1103. DefaultSessionTableConstructor(
  1104. hConference,
  1105. dwConferenceToken,
  1106. FALSE, // bCreate,
  1107. NULL, // pbSessionTableChanged,
  1108. 0, // wListCount,
  1109. NULL, // pTermCapList[],
  1110. NULL, // pTermCapDescriptors[],
  1111. ppSessionTable);
  1112. return CC_NO_MEMORY;
  1113. }
  1114. for (i = 0; i < wNumChannels; i++) {
  1115. (*ppSessionTable)->SessionInfoArray[i].bSessionID = bSessionID++;
  1116. (*ppSessionTable)->SessionInfoArray[i].bAssociatedSessionID = 0;
  1117. wcscpy(szSessionDescription, L"Session ");
  1118. _itow((int)(*ppSessionTable)->SessionInfoArray[i].bSessionID,
  1119. ss, 10);
  1120. wcscat(szSessionDescription, ss);
  1121. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.wOctetStringLength =
  1122. (WORD)((wcslen(szSessionDescription)+1)*sizeof(WCHAR));
  1123. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString =
  1124. (BYTE *)MemAlloc((*ppSessionTable)->SessionInfoArray[i].SessionDescription.wOctetStringLength);
  1125. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString == NULL) {
  1126. MemFree(ChannelList);
  1127. UnlockConference(pConference);
  1128. (*ppSessionTable)->wLength = i;
  1129. DefaultSessionTableConstructor(
  1130. hConference,
  1131. dwConferenceToken,
  1132. FALSE, // bCreate,
  1133. NULL, // pbSessionTableChanged,
  1134. 0, // wListCount,
  1135. NULL, // pTermCapList[],
  1136. NULL, // pTermCapDescriptors[],
  1137. ppSessionTable);
  1138. return CC_NO_MEMORY;
  1139. }
  1140. memcpy((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString,
  1141. szSessionDescription,
  1142. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.wOctetStringLength);
  1143. status = LockChannel(ChannelList[i], &pChannel);
  1144. if (status != CC_OK) {
  1145. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  1146. MemFree(ChannelList);
  1147. UnlockConference(pConference);
  1148. (*ppSessionTable)->wLength = i;
  1149. DefaultSessionTableConstructor(
  1150. hConference,
  1151. dwConferenceToken,
  1152. FALSE, // bCreate,
  1153. NULL, // pbSessionTableChanged,
  1154. 0, // wListCount,
  1155. NULL, // pTermCapList[],
  1156. NULL, // pTermCapDescriptors[],
  1157. ppSessionTable);
  1158. return CC_NO_MEMORY;
  1159. }
  1160. status = H245CopyCap(&(*ppSessionTable)->SessionInfoArray[i].pTermCap,
  1161. pChannel->pTxH245TermCap);
  1162. UnlockChannel(pChannel);
  1163. if (status != H245_ERROR_OK) {
  1164. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  1165. MemFree(ChannelList);
  1166. UnlockConference(pConference);
  1167. (*ppSessionTable)->wLength = i;
  1168. DefaultSessionTableConstructor(
  1169. hConference,
  1170. dwConferenceToken,
  1171. FALSE, // bCreate,
  1172. NULL, // pbSessionTableChanged,
  1173. 0, // wListCount,
  1174. NULL, // pTermCapList[],
  1175. NULL, // pTermCapDescriptors[],
  1176. ppSessionTable);
  1177. return status;
  1178. }
  1179. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr =
  1180. (PCC_ADDR)MemAlloc(sizeof(CC_ADDR));
  1181. if ((*ppSessionTable)->SessionInfoArray[i].pRTPAddr == NULL) {
  1182. H245FreeCap((*ppSessionTable)->SessionInfoArray[i].pTermCap);
  1183. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  1184. MemFree(ChannelList);
  1185. UnlockConference(pConference);
  1186. (*ppSessionTable)->wLength = i;
  1187. DefaultSessionTableConstructor(
  1188. hConference,
  1189. dwConferenceToken,
  1190. FALSE, // bCreate,
  1191. NULL, // pbSessionTableChanged,
  1192. 0, // wListCount,
  1193. NULL, // pTermCapList[],
  1194. NULL, // pTermCapDescriptors[],
  1195. ppSessionTable);
  1196. return CC_NO_MEMORY;
  1197. }
  1198. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->nAddrType = CC_IP_BINARY;
  1199. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->bMulticast = TRUE;
  1200. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.wPort = wPort++;
  1201. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.dwAddr = dwAddr;
  1202. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr =
  1203. (PCC_ADDR)MemAlloc(sizeof(CC_ADDR));
  1204. if ((*ppSessionTable)->SessionInfoArray[i].pRTCPAddr == NULL) {
  1205. H245FreeCap((*ppSessionTable)->SessionInfoArray[i].pTermCap);
  1206. FreeAddr((*ppSessionTable)->SessionInfoArray[i].pRTPAddr);
  1207. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  1208. MemFree(ChannelList);
  1209. UnlockConference(pConference);
  1210. (*ppSessionTable)->wLength = i;
  1211. DefaultSessionTableConstructor(
  1212. hConference,
  1213. dwConferenceToken,
  1214. FALSE, // bCreate,
  1215. NULL, // pbSessionTableChanged,
  1216. 0, // wListCount,
  1217. NULL, // pTermCapList[],
  1218. NULL, // pTermCapDescriptors[],
  1219. ppSessionTable);
  1220. return CC_NO_MEMORY;
  1221. }
  1222. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->nAddrType = CC_IP_BINARY;
  1223. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->bMulticast = TRUE;
  1224. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.wPort = wPort++;
  1225. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.dwAddr = dwAddr;
  1226. }
  1227. }
  1228. MemFree(ChannelList);
  1229. UnlockConference(pConference);
  1230. if (pbSessionTableChanged != NULL)
  1231. *pbSessionTableChanged = TRUE;
  1232. return CC_OK;
  1233. }
  1234. HRESULT DefaultTermCapConstructor( CC_HCONFERENCE hConference,
  1235. DWORD_PTR dwConferenceToken,
  1236. BOOL bCreate,
  1237. BOOL *pbTermCapsChanged,
  1238. WORD wListCount,
  1239. PCC_TERMCAPLIST pInTermCapList[],
  1240. PCC_TERMCAPDESCRIPTORS pInTermCapDescriptors[],
  1241. PCC_TERMCAPLIST *ppOutTermCapList,
  1242. PCC_TERMCAPDESCRIPTORS *ppOutTermCapDescriptors)
  1243. {
  1244. HRESULT status;
  1245. PCONFERENCE pConference;
  1246. WORD wNumChannels;
  1247. PCC_HCHANNEL ChannelList;
  1248. WORD i;
  1249. PCHANNEL pChannel;
  1250. ASSERT(hConference != CC_INVALID_HANDLE);
  1251. ASSERT(ppOutTermCapList != NULL);
  1252. ASSERT(ppOutTermCapDescriptors != NULL);
  1253. if (*ppOutTermCapList != NULL) {
  1254. DestroyH245TermCapList(ppOutTermCapList);
  1255. *ppOutTermCapList = NULL;
  1256. }
  1257. if (*ppOutTermCapDescriptors != NULL) {
  1258. DestroyH245TermCapDescriptors(ppOutTermCapDescriptors);
  1259. *ppOutTermCapDescriptors = NULL;
  1260. }
  1261. if (bCreate == FALSE)
  1262. return CC_OK;
  1263. *ppOutTermCapList = NULL;
  1264. *ppOutTermCapDescriptors = NULL;
  1265. if (pbTermCapsChanged != NULL)
  1266. *pbTermCapsChanged = FALSE;
  1267. status = LockConference(hConference, &pConference);
  1268. if (status != CC_OK)
  1269. return status;
  1270. if (pConference->LocalEndpointAttached == NEVER_ATTACHED) {
  1271. // Copy the local term caps to the conference term caps
  1272. status = CopyH245TermCapList(ppOutTermCapList, pConference->pLocalH245TermCapList);
  1273. if (status != CC_OK) {
  1274. UnlockConference(pConference);
  1275. return CC_NO_MEMORY;
  1276. }
  1277. // Copy the local term cap descriptors to the conference term cap descriptors
  1278. status = CopyH245TermCapDescriptors(ppOutTermCapDescriptors, pConference->pLocalH245TermCapDescriptors);
  1279. if (status != CC_OK) {
  1280. UnlockConference(pConference);
  1281. return CC_NO_MEMORY;
  1282. }
  1283. } else { // pConference->LocalEndpointAttached != NEVER_ATTACHED
  1284. // Create one term cap entry for each open channel on this conference
  1285. EnumerateChannelsInConference(&wNumChannels, &ChannelList, pConference, TX_CHANNEL);
  1286. *ppOutTermCapList = (PCC_TERMCAPLIST)MemAlloc(sizeof(CC_TERMCAPLIST));
  1287. if (*ppOutTermCapList == NULL) {
  1288. MemFree(ChannelList);
  1289. UnlockConference(pConference);
  1290. return CC_NO_MEMORY;
  1291. }
  1292. (*ppOutTermCapList)->wLength = wNumChannels;
  1293. if (wNumChannels == 0)
  1294. (*ppOutTermCapList)->pTermCapArray = NULL;
  1295. else {
  1296. (*ppOutTermCapList)->pTermCapArray =
  1297. (PPCC_TERMCAP)MemAlloc(sizeof(PCC_TERMCAP) * wNumChannels);
  1298. if ((*ppOutTermCapList)->pTermCapArray == NULL) {
  1299. MemFree(ChannelList);
  1300. UnlockConference(pConference);
  1301. (*ppOutTermCapList)->wLength = 0;
  1302. DefaultTermCapConstructor(
  1303. hConference,
  1304. dwConferenceToken,
  1305. FALSE, // bCreate
  1306. NULL, // pbTermCapsChanged
  1307. 0, // wListCount
  1308. NULL, // pInTermCapList[]
  1309. NULL, // pInTermCapDescriptors[]
  1310. ppOutTermCapList,
  1311. ppOutTermCapDescriptors);
  1312. return CC_NO_MEMORY;
  1313. }
  1314. for (i = 0; i < wNumChannels; i++) {
  1315. status = LockChannel(ChannelList[i], &pChannel);
  1316. if (status != CC_OK) {
  1317. MemFree(ChannelList);
  1318. UnlockConference(pConference);
  1319. (*ppOutTermCapList)->wLength = i;
  1320. DefaultTermCapConstructor(
  1321. hConference,
  1322. dwConferenceToken,
  1323. FALSE, // bCreate
  1324. NULL, // pbTermCapsChanged
  1325. 0, // wListCount
  1326. NULL, // pInTermCapList[]
  1327. NULL, // pInTermCapDescriptors[]
  1328. ppOutTermCapList,
  1329. ppOutTermCapDescriptors);
  1330. return CC_NO_MEMORY;
  1331. }
  1332. status = H245CopyCap(&((*ppOutTermCapList)->pTermCapArray[i]),
  1333. pChannel->pTxH245TermCap);
  1334. UnlockChannel(pChannel);
  1335. if (status != H245_ERROR_OK) {
  1336. MemFree(ChannelList);
  1337. UnlockConference(pConference);
  1338. (*ppOutTermCapList)->wLength = i;
  1339. DefaultTermCapConstructor(
  1340. hConference,
  1341. dwConferenceToken,
  1342. FALSE, // bCreate
  1343. NULL, // pbTermCapsChanged
  1344. 0, // wListCount
  1345. NULL, // pInTermCapList[]
  1346. NULL, // pInTermCapDescriptors[]
  1347. ppOutTermCapList,
  1348. ppOutTermCapDescriptors);
  1349. return status;
  1350. }
  1351. (*ppOutTermCapList)->pTermCapArray[i]->Dir = H245_CAPDIR_LCLRXTX;
  1352. (*ppOutTermCapList)->pTermCapArray[i]->CapId = (WORD)(i+1);
  1353. }
  1354. }
  1355. MemFree(ChannelList);
  1356. UnlockConference(pConference);
  1357. // create a new descriptor list
  1358. status = CreateH245DefaultTermCapDescriptors(ppOutTermCapDescriptors,
  1359. *ppOutTermCapList);
  1360. if (status != CC_OK) {
  1361. DefaultTermCapConstructor(
  1362. hConference,
  1363. dwConferenceToken,
  1364. FALSE, // bCreate
  1365. NULL, // pbTermCapsChanged
  1366. 0, // wListCount
  1367. NULL, // pInTermCapList[]
  1368. NULL, // pInTermCapDescriptors[]
  1369. ppOutTermCapList,
  1370. ppOutTermCapDescriptors);
  1371. return CC_NO_MEMORY;
  1372. }
  1373. } // pConference->LocalEndpointAttached != NEVER_ATTACHED
  1374. if (pbTermCapsChanged != NULL)
  1375. *pbTermCapsChanged = TRUE;
  1376. return CC_OK;
  1377. }
  1378. HRESULT AcceptCall( PCALL pCall,
  1379. PCONFERENCE pConference)
  1380. {
  1381. HRESULT status;
  1382. CC_HCALL hCall;
  1383. CC_HCONFERENCE hConference;
  1384. HQ931CALL hQ931Call;
  1385. CC_CONFERENCEID ConferenceID;
  1386. BYTE bTerminalType;
  1387. CC_ADDR H245Addr;
  1388. H245_INST_T H245Instance;
  1389. PCC_VENDORINFO pVendorInfo;
  1390. PCC_NONSTANDARDDATA pNonStandardData;
  1391. PWSTR pszDisplay;
  1392. CC_ENDPOINTTYPE DestinationEndpointType;
  1393. TRISTATE tsMultipointController;
  1394. DWORD dwLinkLayerPhysicalId;
  1395. ASSERT(pCall != NULL);
  1396. ASSERT(pConference != NULL);
  1397. hCall = pCall->hCall;
  1398. hConference = pConference->hConference;
  1399. hQ931Call = pCall->hQ931Call;
  1400. ConferenceID = pCall->ConferenceID;
  1401. pCall->hConference = pConference->hConference;
  1402. status = CopyNonStandardData(&pNonStandardData, pCall->pLocalNonStandardData);
  1403. if (status != CC_OK) {
  1404. UnlockConference(pConference);
  1405. FreeCall(pCall);
  1406. Q931RejectCall(hQ931Call, // Q931 call handle
  1407. CC_REJECT_UNDEFINED_REASON, // reject reason
  1408. &ConferenceID,
  1409. NULL, // alternate address
  1410. pNonStandardData); // non-standard data
  1411. return status;
  1412. }
  1413. status = CopyVendorInfo(&pVendorInfo, pConference->pVendorInfo);
  1414. if (status != CC_OK) {
  1415. UnlockConference(pConference);
  1416. FreeCall(pCall);
  1417. Q931RejectCall(hQ931Call, // Q931 call handle
  1418. CC_REJECT_UNDEFINED_REASON, // reject reason
  1419. &ConferenceID,
  1420. NULL, // alternate address
  1421. pNonStandardData); // non-standard data
  1422. FreeNonStandardData(pNonStandardData);
  1423. return status;
  1424. }
  1425. status = CopyDisplay(&pszDisplay, pCall->pszLocalDisplay);
  1426. if (status != CC_OK) {
  1427. UnlockConference(pConference);
  1428. FreeCall(pCall);
  1429. Q931RejectCall(hQ931Call, // Q931 call handle
  1430. CC_REJECT_UNDEFINED_REASON, // reject reason
  1431. &ConferenceID,
  1432. NULL, // alternate address
  1433. pNonStandardData); // non-standard data
  1434. FreeNonStandardData(pNonStandardData);
  1435. FreeVendorInfo(pVendorInfo);
  1436. return status;
  1437. }
  1438. status = MakeH245PhysicalID(&pCall->dwH245PhysicalID);
  1439. if (status != CC_OK) {
  1440. UnlockConference(pConference);
  1441. FreeCall(pCall);
  1442. Q931RejectCall(hQ931Call, // Q931 call handle
  1443. CC_REJECT_UNDEFINED_REASON, // reject reason
  1444. &ConferenceID,
  1445. NULL, // alternate address
  1446. pNonStandardData); // non-standard data
  1447. FreeNonStandardData(pNonStandardData);
  1448. FreeVendorInfo(pVendorInfo);
  1449. FreeDisplay(pszDisplay);
  1450. return status;
  1451. }
  1452. if (pCall->bCallerIsMC) {
  1453. ASSERT(pConference->tsMultipointController != TS_TRUE);
  1454. ASSERT(pConference->bMultipointCapable == TRUE);
  1455. tsMultipointController = TS_FALSE;
  1456. } else
  1457. tsMultipointController = pConference->tsMultipointController;
  1458. //MULTITHREAD
  1459. //Use a tmp ID so we don't clobber the chosen H245Id.
  1460. // H245Id=>
  1461. // <= linkLayerId
  1462. dwLinkLayerPhysicalId = INVALID_PHYS_ID;
  1463. SetTerminalType(tsMultipointController, &bTerminalType);
  1464. pCall->H245Instance = H245Init(H245_CONF_H323, // configuration
  1465. pCall->dwH245PhysicalID, // H245 physical ID
  1466. &dwLinkLayerPhysicalId, // the link layer ID is returned
  1467. hCall, // dwPreserved
  1468. (H245_CONF_IND_CALLBACK_T)H245Callback, // callback
  1469. bTerminalType);
  1470. if (pCall->H245Instance == H245_INVALID_ID) {
  1471. // H245 initialization failure
  1472. UnlockConference(pConference);
  1473. FreeCall(pCall);
  1474. Q931RejectCall(hQ931Call, // Q931 call handle
  1475. CC_REJECT_UNDEFINED_REASON, // reject reason
  1476. &ConferenceID,
  1477. NULL, // alternate address
  1478. pNonStandardData); // non-standard data
  1479. FreeNonStandardData(pNonStandardData);
  1480. FreeVendorInfo(pVendorInfo);
  1481. FreeDisplay(pszDisplay);
  1482. return CC_INTERNAL_ERROR;
  1483. }
  1484. H245Instance = pCall->H245Instance;
  1485. // Set the H.245 TCP/IP address to the same IP address on which
  1486. // the Q.931 connection was made; this ensures that if the host
  1487. // is multi-homed, the H.245 will be made on the same IP address
  1488. // as the Q.931 connection. Set the initial H.245 port to zero,
  1489. // so that it will be dynamically determined.
  1490. ASSERT(pCall->pQ931LocalConnectAddr != NULL);
  1491. H245Addr = *pCall->pQ931LocalConnectAddr;
  1492. switch (pCall->pQ931LocalConnectAddr->nAddrType) {
  1493. case CC_IP_DOMAIN_NAME:
  1494. H245Addr.Addr.IP_DomainName.wPort = 0;
  1495. break;
  1496. case CC_IP_DOT:
  1497. H245Addr.Addr.IP_Dot.wPort = 0;
  1498. break;
  1499. case CC_IP_BINARY:
  1500. H245Addr.Addr.IP_Binary.wPort = 0;
  1501. break;
  1502. default:
  1503. ASSERT(0);
  1504. UnlockConference(pConference);
  1505. FreeCall(pCall);
  1506. H245ShutDown(H245Instance);
  1507. Q931RejectCall(hQ931Call, // Q931 call handle
  1508. CC_REJECT_UNDEFINED_REASON, // reject reason
  1509. &ConferenceID,
  1510. NULL, // alternate address
  1511. pNonStandardData); // non-standard data
  1512. FreeNonStandardData(pNonStandardData);
  1513. FreeVendorInfo(pVendorInfo);
  1514. FreeDisplay(pszDisplay);
  1515. return CC_INTERNAL_ERROR;
  1516. }
  1517. status = linkLayerListen(&dwLinkLayerPhysicalId,
  1518. H245Instance,
  1519. &H245Addr,
  1520. NULL);
  1521. if (status != NOERROR) {
  1522. UnlockConference(pConference);
  1523. FreeCall(pCall);
  1524. H245ShutDown(H245Instance);
  1525. Q931RejectCall(hQ931Call, // Q931 call handle
  1526. CC_REJECT_UNDEFINED_REASON, // reject reason
  1527. &ConferenceID,
  1528. NULL, // alternate address
  1529. pNonStandardData); // non-standard data
  1530. FreeNonStandardData(pNonStandardData);
  1531. FreeVendorInfo(pVendorInfo);
  1532. FreeDisplay(pszDisplay);
  1533. return status;
  1534. }
  1535. UnlockConference(pConference);
  1536. UnlockCall(pCall);
  1537. DestinationEndpointType.pVendorInfo = pVendorInfo;
  1538. DestinationEndpointType.bIsTerminal = TRUE;
  1539. DestinationEndpointType.bIsGateway = FALSE;
  1540. status = Q931AcceptCall(hQ931Call,
  1541. pszDisplay,
  1542. pNonStandardData, // non-standard data
  1543. &DestinationEndpointType,
  1544. &H245Addr, // H245 address
  1545. hCall); // user token
  1546. FreeNonStandardData(pNonStandardData);
  1547. FreeVendorInfo(pVendorInfo);
  1548. FreeDisplay(pszDisplay);
  1549. if (status != CS_OK) {
  1550. if (LockCall(hCall, &pCall) == CC_OK)
  1551. FreeCall(pCall);
  1552. H245ShutDown(H245Instance);
  1553. return status;
  1554. }
  1555. status = LockCallAndConference(hCall, &pCall, &pConference);
  1556. if (status != CC_OK) {
  1557. if (LockCall(hCall, &pCall) == CC_OK)
  1558. FreeCall(pCall);
  1559. H245ShutDown(H245Instance);
  1560. Q931Hangup(hQ931Call, CC_REJECT_UNDEFINED_REASON);
  1561. return status;
  1562. }
  1563. pCall->CallState = TERMCAP;
  1564. pConference->ConferenceID = pCall->ConferenceID;
  1565. status = AddPlacedCallToConference(pCall, pConference);
  1566. if (status != CC_OK) {
  1567. UnlockConference(pConference);
  1568. FreeCall(pCall);
  1569. H245ShutDown(H245Instance);
  1570. Q931Hangup(hQ931Call, CC_REJECT_UNDEFINED_REASON);
  1571. return status;
  1572. }
  1573. status = SendTermCaps(pCall, pConference);
  1574. if (status != CC_OK) {
  1575. UnlockConference(pConference);
  1576. FreeCall(pCall);
  1577. H245ShutDown(H245Instance);
  1578. Q931Hangup(hQ931Call, CC_REJECT_UNDEFINED_REASON);
  1579. return status;
  1580. }
  1581. pCall->OutgoingTermCapState = AWAITING_ACK;
  1582. if (pCall->MasterSlaveState == MASTER_SLAVE_NOT_STARTED) {
  1583. status = H245InitMasterSlave(H245Instance,
  1584. H245Instance); // returned as dwTransId in the callback
  1585. if (status != H245_ERROR_OK) {
  1586. UnlockConference(pConference);
  1587. FreeCall(pCall);
  1588. H245ShutDown(H245Instance);
  1589. Q931Hangup(hQ931Call, CC_REJECT_UNDEFINED_REASON);
  1590. return status;
  1591. }
  1592. pCall->MasterSlaveState = MASTER_SLAVE_IN_PROGRESS;
  1593. }
  1594. if (pCall->bCallerIsMC) {
  1595. pConference->tsMultipointController = TS_FALSE;
  1596. pConference->ConferenceMode = MULTIPOINT_MODE;
  1597. }
  1598. UnlockConference(pConference);
  1599. UnlockCall(pCall);
  1600. return CC_OK;
  1601. }
  1602. HRESULT PlaceCall( PCALL pCall,
  1603. PCONFERENCE pConference)
  1604. {
  1605. CC_HCALL hCall;
  1606. HRESULT status;
  1607. WORD wGoal;
  1608. HQ931CALL hQ931Call;
  1609. PCC_ALIASNAMES pCallerAliasNames;
  1610. PCC_ALIASNAMES pCalleeAliasNames;
  1611. PCC_ALIASNAMES pCalleeExtraAliasNames;
  1612. PCC_ALIASITEM pCalleeExtension;
  1613. PCC_VENDORINFO pVendorInfo;
  1614. PWSTR pszDisplay;
  1615. PCC_NONSTANDARDDATA pNonStandardData;
  1616. WORD wNumCalls;
  1617. PCC_ADDR pConnectAddr;
  1618. PCC_ADDR pDestinationAddr;
  1619. CC_ADDR SourceAddr;
  1620. CC_ENDPOINTTYPE SourceEndpointType;
  1621. BOOL bCallerIsMC;
  1622. WORD wCallType;
  1623. ASSERT(pCall != NULL);
  1624. hCall = pCall->hCall;
  1625. if (pCall->CallState == ENQUEUED) {
  1626. // Enqueue the call on the conference object and HResultLeaveCallControl.
  1627. // There will be exactly one placed call for this conference,
  1628. // which is in the process of being placed. If this call placement
  1629. // completes successfully, all enqueued calls will then be placed.
  1630. // If this call placement fails or is terminated, one enqueued call
  1631. // will be placed
  1632. status = AddEnqueuedCallToConference(pCall, pConference);
  1633. return status;
  1634. }
  1635. // CallState == PLACED
  1636. EnumerateCallsInConference(&wNumCalls,
  1637. NULL,
  1638. pConference,
  1639. PLACED_CALL | ESTABLISHED_CALL);
  1640. if (EqualConferenceIDs(&pConference->ConferenceID, &InvalidConferenceID))
  1641. wGoal = CSG_CREATE;
  1642. else if ((wNumCalls == 0) && (pConference->tsMultipointController != TS_TRUE))
  1643. wGoal = CSG_JOIN;
  1644. else
  1645. wGoal = CSG_INVITE;
  1646. status = AddPlacedCallToConference(pCall, pConference);
  1647. if (status != CC_OK)
  1648. return status;
  1649. status = CopyAddr(&pConnectAddr, pCall->pQ931PeerConnectAddr);
  1650. if (status != CC_OK)
  1651. return status;
  1652. status = CopyAddr(&pDestinationAddr, pCall->pQ931DestinationAddr);
  1653. if (status != CC_OK) {
  1654. FreeAddr(pConnectAddr);
  1655. return status;
  1656. }
  1657. status = Q931CopyAliasNames(&pCallerAliasNames, pCall->pLocalAliasNames);
  1658. if (status != CS_OK) {
  1659. FreeAddr(pConnectAddr);
  1660. FreeAddr(pDestinationAddr);
  1661. return status;
  1662. }
  1663. status = CopyVendorInfo(&pVendorInfo, pConference->pVendorInfo);
  1664. if (status != CC_OK) {
  1665. FreeAddr(pConnectAddr);
  1666. FreeAddr(pDestinationAddr);
  1667. Q931FreeAliasNames(pCallerAliasNames);
  1668. return status;
  1669. }
  1670. status = CopyDisplay(&pszDisplay, pCall->pszLocalDisplay);
  1671. if (status != CC_OK) {
  1672. FreeAddr(pConnectAddr);
  1673. FreeAddr(pDestinationAddr);
  1674. Q931FreeAliasNames(pCallerAliasNames);
  1675. FreeVendorInfo(pVendorInfo);
  1676. return status;
  1677. }
  1678. status = Q931CopyAliasNames(&pCalleeAliasNames, pCall->pPeerAliasNames);
  1679. if (status != CS_OK) {
  1680. FreeAddr(pConnectAddr);
  1681. FreeAddr(pDestinationAddr);
  1682. Q931FreeAliasNames(pCallerAliasNames);
  1683. FreeVendorInfo(pVendorInfo);
  1684. FreeDisplay(pszDisplay);
  1685. return status;
  1686. }
  1687. status = Q931CopyAliasNames(&pCalleeExtraAliasNames,
  1688. pCall->pPeerExtraAliasNames);
  1689. if (status != CS_OK) {
  1690. FreeAddr(pConnectAddr);
  1691. FreeAddr(pDestinationAddr);
  1692. Q931FreeAliasNames(pCallerAliasNames);
  1693. FreeVendorInfo(pVendorInfo);
  1694. FreeDisplay(pszDisplay);
  1695. Q931FreeAliasNames(pCalleeAliasNames);
  1696. return status;
  1697. }
  1698. status = Q931CopyAliasItem(&pCalleeExtension,
  1699. pCall->pPeerExtension);
  1700. if (status != CS_OK) {
  1701. FreeAddr(pConnectAddr);
  1702. FreeAddr(pDestinationAddr);
  1703. Q931FreeAliasNames(pCallerAliasNames);
  1704. FreeVendorInfo(pVendorInfo);
  1705. FreeDisplay(pszDisplay);
  1706. Q931FreeAliasNames(pCalleeAliasNames);
  1707. Q931FreeAliasNames(pCalleeExtraAliasNames);
  1708. return status;
  1709. }
  1710. status = CopyNonStandardData(&pNonStandardData, pCall->pLocalNonStandardData);
  1711. if (status != CC_OK) {
  1712. FreeAddr(pConnectAddr);
  1713. FreeAddr(pDestinationAddr);
  1714. Q931FreeAliasNames(pCallerAliasNames);
  1715. FreeVendorInfo(pVendorInfo);
  1716. FreeDisplay(pszDisplay);
  1717. Q931FreeAliasNames(pCalleeAliasNames);
  1718. Q931FreeAliasNames(pCalleeExtraAliasNames);
  1719. Q931FreeAliasItem(pCalleeExtension);
  1720. return status;
  1721. }
  1722. bCallerIsMC = (pConference->tsMultipointController == TS_TRUE ? TRUE : FALSE);
  1723. // Note that if pConference->ConferenceMode == POINT_TO_POINT_MODE, this call attempt
  1724. // will result in a multipoint call if successful, so set the wCallType accordingly
  1725. wCallType = (WORD)((pConference->ConferenceMode == UNCONNECTED_MODE) ? CC_CALLTYPE_PT_PT : CC_CALLTYPE_N_N);
  1726. SourceEndpointType.pVendorInfo = pVendorInfo;
  1727. SourceEndpointType.bIsTerminal = TRUE;
  1728. SourceEndpointType.bIsGateway = FALSE;
  1729. // Cause our local Q.931 connect address to be placed in the
  1730. // Q.931 setup-UUIE sourceAddress field
  1731. SourceAddr.nAddrType = CC_IP_BINARY;
  1732. SourceAddr.bMulticast = FALSE;
  1733. SourceAddr.Addr.IP_Binary.dwAddr = 0;
  1734. SourceAddr.Addr.IP_Binary.wPort = 0;
  1735. status = Q931PlaceCall(&hQ931Call, // Q931 call handle
  1736. pszDisplay,
  1737. pCallerAliasNames,
  1738. pCalleeAliasNames,
  1739. pCalleeExtraAliasNames, // pCalleeExtraAliasNames
  1740. pCalleeExtension, // pCalleeExtension
  1741. pNonStandardData, // non-standard data
  1742. &SourceEndpointType,
  1743. NULL, // pszCalledPartyNumber
  1744. pConnectAddr,
  1745. pDestinationAddr,
  1746. &SourceAddr, // source address
  1747. bCallerIsMC,
  1748. &pCall->ConferenceID, // conference ID
  1749. wGoal,
  1750. wCallType,
  1751. hCall, // user token
  1752. (Q931_CALLBACK)Q931Callback, // callback
  1753. #ifdef GATEKEEPER
  1754. pCall->GkiCall.usCRV, // CRV
  1755. &pCall->CallIdentifier); // H.225 CallIdentifier
  1756. #else
  1757. 0, // CRV
  1758. &pCall->CallIdentifier); // H.225 CallIdentifier
  1759. #endif GATEKEEPER
  1760. FreeAddr(pConnectAddr);
  1761. FreeAddr(pDestinationAddr);
  1762. Q931FreeAliasNames(pCallerAliasNames);
  1763. FreeVendorInfo(pVendorInfo);
  1764. FreeDisplay(pszDisplay);
  1765. Q931FreeAliasNames(pCalleeAliasNames);
  1766. Q931FreeAliasNames(pCalleeExtraAliasNames);
  1767. Q931FreeAliasItem(pCalleeExtension);
  1768. FreeNonStandardData(pNonStandardData);
  1769. if (status != CS_OK)
  1770. return status;
  1771. pCall->hQ931Call = hQ931Call;
  1772. return CC_OK;
  1773. }
  1774. HRESULT SendTermCaps( PCALL pCall,
  1775. PCONFERENCE pConference)
  1776. {
  1777. HRESULT status;
  1778. WORD i;
  1779. H245_TOTCAPDESC_T *pTermCapDescriptor;
  1780. PCC_TERMCAP pH2250MuxCapability;
  1781. PCC_TERMCAPLIST pTermCapList;
  1782. PCC_TERMCAPDESCRIPTORS pTermCapDescriptors;
  1783. ASSERT(pCall != NULL);
  1784. ASSERT(pConference != NULL);
  1785. if ((pConference->ConferenceMode == MULTIPOINT_MODE) &&
  1786. (pConference->tsMultipointController == TS_TRUE)) {
  1787. pH2250MuxCapability = pConference->pConferenceH245H2250MuxCapability;
  1788. pTermCapList = pConference->pConferenceTermCapList;
  1789. pTermCapDescriptors = pConference->pConferenceTermCapDescriptors;
  1790. } else {
  1791. pH2250MuxCapability = pConference->pLocalH245H2250MuxCapability;
  1792. pTermCapList = pConference->pLocalH245TermCapList;
  1793. pTermCapDescriptors = pConference->pLocalH245TermCapDescriptors;
  1794. }
  1795. ASSERT(pH2250MuxCapability != NULL);
  1796. ASSERT(pTermCapList != NULL);
  1797. ASSERT(pTermCapDescriptors != NULL);
  1798. // First send out the H.225.0 capability
  1799. status = H245SetLocalCap(pCall->H245Instance,
  1800. pH2250MuxCapability,
  1801. &pH2250MuxCapability->CapId);
  1802. ASSERT(pH2250MuxCapability->CapId == 0);
  1803. if (status != H245_ERROR_OK)
  1804. return status;
  1805. // Now send out the terminal capabilities
  1806. for (i = 0; i < pTermCapList->wLength; i++) {
  1807. status = H245SetLocalCap(pCall->H245Instance,
  1808. pTermCapList->pTermCapArray[i],
  1809. &pTermCapList->pTermCapArray[i]->CapId);
  1810. if (status != H245_ERROR_OK)
  1811. return status;
  1812. }
  1813. // Finally send out the capability descriptors
  1814. for (i = 0; i < pTermCapDescriptors->wLength; i++) {
  1815. pTermCapDescriptor = pTermCapDescriptors->pTermCapDescriptorArray[i];
  1816. status = H245SetCapDescriptor(pCall->H245Instance,
  1817. &pTermCapDescriptor->CapDesc,
  1818. &pTermCapDescriptor->CapDescId);
  1819. if (status != H245_ERROR_OK)
  1820. return status;
  1821. }
  1822. status = H245SendTermCaps(pCall->H245Instance,
  1823. pCall->H245Instance); // returned as dwTransId in the callback
  1824. return status;
  1825. }
  1826. HRESULT SessionTableToH245CommunicationTable(
  1827. PCC_SESSIONTABLE pSessionTable,
  1828. H245_COMM_MODE_ENTRY_T *pH245CommunicationTable[],
  1829. BYTE *pbCommunicationTableCount)
  1830. {
  1831. WORD i, j;
  1832. WORD wStringLength;
  1833. ASSERT(pH245CommunicationTable != NULL);
  1834. ASSERT(pbCommunicationTableCount != NULL);
  1835. if ((pSessionTable == NULL) || (pSessionTable->wLength == 0)) {
  1836. *pH245CommunicationTable = NULL;
  1837. *pbCommunicationTableCount = 0;
  1838. return CC_OK;
  1839. }
  1840. if (pSessionTable->SessionInfoArray == NULL) {
  1841. *pH245CommunicationTable = NULL;
  1842. *pbCommunicationTableCount = 0;
  1843. return CC_BAD_PARAM;
  1844. }
  1845. *pH245CommunicationTable = (H245_COMM_MODE_ENTRY_T *)MemAlloc(sizeof(H245_COMM_MODE_ENTRY_T) * pSessionTable->wLength);
  1846. if (*pH245CommunicationTable == NULL) {
  1847. *pbCommunicationTableCount = 0;
  1848. return CC_NO_MEMORY;
  1849. }
  1850. *pbCommunicationTableCount = (BYTE)pSessionTable->wLength;
  1851. for (i = 0; i < pSessionTable->wLength; i++) {
  1852. (*pH245CommunicationTable)[i].pNonStandard = NULL;
  1853. (*pH245CommunicationTable)[i].sessionID = pSessionTable->SessionInfoArray[i].bSessionID;
  1854. if (pSessionTable->SessionInfoArray[i].bAssociatedSessionID == 0)
  1855. (*pH245CommunicationTable)[i].associatedSessionIDPresent = FALSE;
  1856. else {
  1857. (*pH245CommunicationTable)[i].associatedSessionIDPresent = TRUE;
  1858. (*pH245CommunicationTable)[i].associatedSessionID = pSessionTable->SessionInfoArray[i].bAssociatedSessionID;
  1859. }
  1860. (*pH245CommunicationTable)[i].terminalLabelPresent = FALSE;
  1861. wStringLength = pSessionTable->SessionInfoArray[i].SessionDescription.wOctetStringLength;
  1862. if (wStringLength > 0) {
  1863. (*pH245CommunicationTable)[i].pSessionDescription = (unsigned short *)MemAlloc(sizeof(unsigned short) * wStringLength);
  1864. if ((*pH245CommunicationTable)[i].pSessionDescription == NULL) {
  1865. for (j = 0; j < i; j++)
  1866. MemFree((*pH245CommunicationTable)[j].pSessionDescription);
  1867. MemFree(*pH245CommunicationTable);
  1868. *pbCommunicationTableCount = 0;
  1869. return CC_NO_MEMORY;
  1870. }
  1871. memcpy((*pH245CommunicationTable)[i].pSessionDescription,
  1872. pSessionTable->SessionInfoArray[i].SessionDescription.pOctetString,
  1873. wStringLength);
  1874. } else
  1875. (*pH245CommunicationTable)[i].pSessionDescription = NULL;
  1876. (*pH245CommunicationTable)[i].wSessionDescriptionLength = wStringLength;
  1877. (*pH245CommunicationTable)[i].dataType = *pSessionTable->SessionInfoArray[i].pTermCap;
  1878. if (pSessionTable->SessionInfoArray[i].pRTPAddr == NULL)
  1879. (*pH245CommunicationTable)[i].mediaChannelPresent = FALSE;
  1880. else {
  1881. if (pSessionTable->SessionInfoArray[i].pRTPAddr->nAddrType != CC_IP_BINARY) {
  1882. for (j = 0; j <= i; j++)
  1883. if ((*pH245CommunicationTable)[j].pSessionDescription != NULL)
  1884. MemFree((*pH245CommunicationTable)[j].pSessionDescription);
  1885. MemFree(*pH245CommunicationTable);
  1886. *pbCommunicationTableCount = 0;
  1887. return CC_BAD_PARAM;
  1888. }
  1889. if (pSessionTable->SessionInfoArray[i].pRTPAddr->bMulticast)
  1890. (*pH245CommunicationTable)[i].mediaChannel.type = H245_IP_MULTICAST;
  1891. else
  1892. (*pH245CommunicationTable)[i].mediaChannel.type = H245_IP_UNICAST;
  1893. (*pH245CommunicationTable)[i].mediaChannel.u.ip.tsapIdentifier =
  1894. pSessionTable->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.wPort;
  1895. HostToH245IPNetwork((*pH245CommunicationTable)[i].mediaChannel.u.ip.network,
  1896. pSessionTable->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.dwAddr);
  1897. (*pH245CommunicationTable)[i].mediaChannelPresent = TRUE;
  1898. }
  1899. if (pSessionTable->SessionInfoArray[i].pRTCPAddr == NULL)
  1900. (*pH245CommunicationTable)[i].mediaControlChannelPresent = FALSE;
  1901. else {
  1902. if (pSessionTable->SessionInfoArray[i].pRTCPAddr->nAddrType != CC_IP_BINARY) {
  1903. for (j = 0; j <= i; j++)
  1904. if ((*pH245CommunicationTable)[j].pSessionDescription != NULL)
  1905. MemFree((*pH245CommunicationTable)[j].pSessionDescription);
  1906. MemFree(*pH245CommunicationTable);
  1907. *pbCommunicationTableCount = 0;
  1908. return CC_BAD_PARAM;
  1909. }
  1910. if (pSessionTable->SessionInfoArray[i].pRTCPAddr->bMulticast)
  1911. (*pH245CommunicationTable)[i].mediaControlChannel.type = H245_IP_MULTICAST;
  1912. else
  1913. (*pH245CommunicationTable)[i].mediaControlChannel.type = H245_IP_UNICAST;
  1914. (*pH245CommunicationTable)[i].mediaControlChannel.u.ip.tsapIdentifier =
  1915. pSessionTable->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.wPort;
  1916. HostToH245IPNetwork((*pH245CommunicationTable)[i].mediaControlChannel.u.ip.network,
  1917. pSessionTable->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.dwAddr);
  1918. (*pH245CommunicationTable)[i].mediaControlChannelPresent = TRUE;
  1919. }
  1920. (*pH245CommunicationTable)[i].mediaGuaranteed = FALSE;
  1921. (*pH245CommunicationTable)[i].mediaGuaranteedPresent = TRUE;
  1922. (*pH245CommunicationTable)[i].mediaControlGuaranteed = FALSE;
  1923. (*pH245CommunicationTable)[i].mediaControlGuaranteedPresent = TRUE;
  1924. }
  1925. return CC_OK;
  1926. }
  1927. HRESULT H245CommunicationTableToSessionTable(
  1928. H245_COMM_MODE_ENTRY_T H245CommunicationTable[],
  1929. BYTE bCommunicationTableCount,
  1930. PCC_SESSIONTABLE *ppSessionTable)
  1931. {
  1932. WORD i, j;
  1933. HRESULT status;
  1934. ASSERT(ppSessionTable != NULL);
  1935. if (H245CommunicationTable == NULL)
  1936. if (bCommunicationTableCount == 0) {
  1937. *ppSessionTable = NULL;
  1938. return CC_OK;
  1939. } else
  1940. return CC_BAD_PARAM;
  1941. else
  1942. if (bCommunicationTableCount == 0)
  1943. return CC_BAD_PARAM;
  1944. *ppSessionTable = (PCC_SESSIONTABLE)MemAlloc(sizeof(CC_SESSIONTABLE));
  1945. if (*ppSessionTable == NULL)
  1946. return CC_NO_MEMORY;
  1947. (*ppSessionTable)->wLength = bCommunicationTableCount;
  1948. (*ppSessionTable)->SessionInfoArray = (PCC_SESSIONINFO)MemAlloc(sizeof(CC_SESSIONINFO) * bCommunicationTableCount);
  1949. if ((*ppSessionTable)->SessionInfoArray == NULL) {
  1950. MemFree(*ppSessionTable);
  1951. *ppSessionTable = NULL;
  1952. return CC_NO_MEMORY;
  1953. }
  1954. for (i = 0; i < bCommunicationTableCount; i++) {
  1955. (*ppSessionTable)->SessionInfoArray[i].bSessionID = H245CommunicationTable[i].sessionID;
  1956. if (H245CommunicationTable[i].associatedSessionIDPresent)
  1957. (*ppSessionTable)->SessionInfoArray[i].bAssociatedSessionID =
  1958. H245CommunicationTable[i].associatedSessionID;
  1959. else
  1960. (*ppSessionTable)->SessionInfoArray[i].bAssociatedSessionID = 0;
  1961. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.wOctetStringLength =
  1962. H245CommunicationTable[i].wSessionDescriptionLength;
  1963. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.wOctetStringLength == 0)
  1964. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString = NULL;
  1965. else {
  1966. (*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString =
  1967. (BYTE *)MemAlloc(H245CommunicationTable[i].wSessionDescriptionLength);
  1968. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString == NULL) {
  1969. for (j = 0; j < i; j++) {
  1970. H245FreeCap((*ppSessionTable)->SessionInfoArray[j].pTermCap);
  1971. if ((*ppSessionTable)->SessionInfoArray[j].pRTPAddr != NULL)
  1972. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTPAddr);
  1973. if ((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr != NULL)
  1974. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr);
  1975. }
  1976. MemFree((*ppSessionTable)->SessionInfoArray);
  1977. MemFree(*ppSessionTable);
  1978. return CC_NO_MEMORY;
  1979. }
  1980. memcpy((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString,
  1981. H245CommunicationTable[i].pSessionDescription,
  1982. H245CommunicationTable[i].wSessionDescriptionLength);
  1983. }
  1984. status = H245CopyCap(&(*ppSessionTable)->SessionInfoArray[i].pTermCap,
  1985. &H245CommunicationTable[i].dataType);
  1986. if (status != H245_ERROR_OK) {
  1987. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString != NULL)
  1988. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  1989. for (j = 0; j < i; j++) {
  1990. H245FreeCap((*ppSessionTable)->SessionInfoArray[j].pTermCap);
  1991. if ((*ppSessionTable)->SessionInfoArray[j].pRTPAddr != NULL)
  1992. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTPAddr);
  1993. if ((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr != NULL)
  1994. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr);
  1995. }
  1996. MemFree((*ppSessionTable)->SessionInfoArray);
  1997. MemFree(*ppSessionTable);
  1998. return status;
  1999. }
  2000. if ((H245CommunicationTable[i].mediaChannelPresent) &&
  2001. ((H245CommunicationTable[i].mediaChannel.type == H245_IP_MULTICAST) ||
  2002. (H245CommunicationTable[i].mediaChannel.type == H245_IP_UNICAST))) {
  2003. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr = (PCC_ADDR)MemAlloc(sizeof(CC_ADDR));
  2004. if ((*ppSessionTable)->SessionInfoArray[i].pRTPAddr == NULL) {
  2005. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString != NULL)
  2006. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  2007. H245FreeCap((*ppSessionTable)->SessionInfoArray[i].pTermCap);
  2008. for (j = 0; j < i; j++) {
  2009. H245FreeCap((*ppSessionTable)->SessionInfoArray[j].pTermCap);
  2010. if ((*ppSessionTable)->SessionInfoArray[j].pRTPAddr != NULL)
  2011. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTPAddr);
  2012. if ((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr != NULL)
  2013. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr);
  2014. }
  2015. MemFree((*ppSessionTable)->SessionInfoArray);
  2016. MemFree(*ppSessionTable);
  2017. return CC_NO_MEMORY;
  2018. }
  2019. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->nAddrType = CC_IP_BINARY;
  2020. if (H245CommunicationTable[i].mediaChannel.type == H245_IP_MULTICAST)
  2021. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->bMulticast = TRUE;
  2022. else
  2023. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->bMulticast = FALSE;
  2024. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.wPort =
  2025. H245CommunicationTable[i].mediaChannel.u.ip.tsapIdentifier;
  2026. H245IPNetworkToHost(&(*ppSessionTable)->SessionInfoArray[i].pRTPAddr->Addr.IP_Binary.dwAddr,
  2027. H245CommunicationTable[i].mediaChannel.u.ip.network);
  2028. } else
  2029. (*ppSessionTable)->SessionInfoArray[i].pRTPAddr = NULL;
  2030. if ((H245CommunicationTable[i].mediaControlChannelPresent) &&
  2031. ((H245CommunicationTable[i].mediaControlChannel.type == H245_IP_MULTICAST) ||
  2032. (H245CommunicationTable[i].mediaControlChannel.type == H245_IP_UNICAST))) {
  2033. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr = (PCC_ADDR)MemAlloc(sizeof(CC_ADDR));
  2034. if ((*ppSessionTable)->SessionInfoArray[i].pRTCPAddr == NULL) {
  2035. if ((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString != NULL)
  2036. MemFree((*ppSessionTable)->SessionInfoArray[i].SessionDescription.pOctetString);
  2037. H245FreeCap((*ppSessionTable)->SessionInfoArray[i].pTermCap);
  2038. if ((*ppSessionTable)->SessionInfoArray[i].pRTPAddr != NULL)
  2039. MemFree((*ppSessionTable)->SessionInfoArray[i].pRTPAddr);
  2040. for (j = 0; j < i; j++) {
  2041. H245FreeCap((*ppSessionTable)->SessionInfoArray[j].pTermCap);
  2042. if ((*ppSessionTable)->SessionInfoArray[j].pRTPAddr != NULL)
  2043. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTPAddr);
  2044. if ((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr != NULL)
  2045. MemFree((*ppSessionTable)->SessionInfoArray[j].pRTCPAddr);
  2046. }
  2047. MemFree((*ppSessionTable)->SessionInfoArray);
  2048. MemFree(*ppSessionTable);
  2049. return CC_NO_MEMORY;
  2050. }
  2051. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->nAddrType = CC_IP_BINARY;
  2052. if (H245CommunicationTable[i].mediaChannel.type == H245_IP_MULTICAST)
  2053. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->bMulticast = TRUE;
  2054. else
  2055. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->bMulticast = FALSE;
  2056. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.wPort =
  2057. H245CommunicationTable[i].mediaControlChannel.u.ip.tsapIdentifier;
  2058. H245IPNetworkToHost(&(*ppSessionTable)->SessionInfoArray[i].pRTCPAddr->Addr.IP_Binary.dwAddr,
  2059. H245CommunicationTable[i].mediaControlChannel.u.ip.network);
  2060. } else
  2061. (*ppSessionTable)->SessionInfoArray[i].pRTCPAddr = NULL;
  2062. }
  2063. return CC_OK;
  2064. }
  2065. HRESULT FreeH245CommunicationTable( H245_COMM_MODE_ENTRY_T H245CommunicationTable[],
  2066. BYTE bCommunicationTableCount)
  2067. {
  2068. WORD i;
  2069. if (H245CommunicationTable == NULL)
  2070. if (bCommunicationTableCount == 0)
  2071. return CC_OK;
  2072. else
  2073. return CC_BAD_PARAM;
  2074. else
  2075. if (bCommunicationTableCount == 0)
  2076. return CC_BAD_PARAM;
  2077. for (i = 0; i < bCommunicationTableCount; i++)
  2078. if (H245CommunicationTable[i].pSessionDescription != NULL)
  2079. MemFree(H245CommunicationTable[i].pSessionDescription);
  2080. MemFree(H245CommunicationTable);
  2081. return CC_OK;
  2082. }
  2083. HRESULT _PrepareTermCapLists( PCONFERENCE pConference,
  2084. WORD *pwListCount,
  2085. PCC_TERMCAPLIST **ppTermCapList,
  2086. PCC_TERMCAPDESCRIPTORS **ppTermCapDescriptorList,
  2087. PCALL *pCallList[])
  2088. {
  2089. WORD i;
  2090. WORD wNumCalls;
  2091. WORD wOffset;
  2092. PCC_HCALL CallList;
  2093. PCALL pCall;
  2094. ASSERT(pConference != NULL);
  2095. ASSERT(pwListCount != NULL);
  2096. ASSERT(ppTermCapList != NULL);
  2097. ASSERT(ppTermCapDescriptorList != NULL);
  2098. ASSERT(pCallList != NULL);
  2099. EnumerateCallsInConference(&wNumCalls, &CallList, pConference, ESTABLISHED_CALL);
  2100. if ((pConference->LocalEndpointAttached == DETACHED) && (wNumCalls > 0))
  2101. wOffset = 0;
  2102. else
  2103. // LocalEndpointAttached is either UNATTACHED or ATTACHED, or there are no calls
  2104. // in the conference; in the latter case, we need to have some term caps in
  2105. // order to form the conference term cap set (which cannot be empty)
  2106. wOffset = 1;
  2107. *pwListCount = (WORD)(wNumCalls + wOffset);
  2108. *ppTermCapList = (PCC_TERMCAPLIST *)MemAlloc(sizeof(PCC_TERMCAPLIST) * (*pwListCount));
  2109. if (*ppTermCapList == NULL) {
  2110. MemFree(CallList);
  2111. return CC_NO_MEMORY;
  2112. }
  2113. *ppTermCapDescriptorList = (PCC_TERMCAPDESCRIPTORS *)MemAlloc(sizeof(PCC_TERMCAPDESCRIPTORS) * (*pwListCount));
  2114. if (*ppTermCapDescriptorList == NULL) {
  2115. MemFree(CallList);
  2116. MemFree(*ppTermCapList);
  2117. return CC_NO_MEMORY;
  2118. }
  2119. *pCallList = (PCALL *)MemAlloc(sizeof(PCALL) * (*pwListCount));
  2120. if (*pCallList == NULL) {
  2121. MemFree(CallList);
  2122. MemFree(*ppTermCapList);
  2123. MemFree(*ppTermCapDescriptorList);
  2124. return CC_NO_MEMORY;
  2125. }
  2126. // Fill in pTermCapList and pTermCapDescriptorList
  2127. if (wOffset == 1) {
  2128. // The local endpoint is attached to the conference, so fill in the first
  2129. // slot in both lists with the local term cap and descriptor lists
  2130. (*ppTermCapList)[0] = pConference->pLocalH245TermCapList;
  2131. (*ppTermCapDescriptorList)[0] = pConference->pLocalH245TermCapDescriptors;
  2132. }
  2133. for (i = 0; i < wNumCalls; i++) {
  2134. if (LockCall(CallList[i], &pCall) == CC_OK) {
  2135. (*ppTermCapList)[i+wOffset] = pCall->pPeerH245TermCapList;
  2136. (*ppTermCapDescriptorList)[i+wOffset] = pCall->pPeerH245TermCapDescriptors;
  2137. (*pCallList)[i] = pCall;
  2138. } else {
  2139. (*ppTermCapList)[i+wOffset] = NULL;
  2140. (*ppTermCapDescriptorList)[i+wOffset] = NULL;
  2141. (*pCallList)[i] = NULL;
  2142. }
  2143. }
  2144. for (i = 0; i < wOffset; i++)
  2145. (*pCallList)[wNumCalls+i] = NULL;
  2146. MemFree(CallList);
  2147. return CC_OK;
  2148. }
  2149. HRESULT _FreeTermCapLists( WORD wListCount,
  2150. PCC_TERMCAPLIST *pTermCapList,
  2151. PCC_TERMCAPDESCRIPTORS *pTermCapDescriptorList,
  2152. PCALL pCallList[])
  2153. {
  2154. WORD i;
  2155. for (i = 0; i < wListCount; i++)
  2156. if (pCallList[i] != NULL)
  2157. UnlockCall(pCallList[i]);
  2158. if (pTermCapList != NULL)
  2159. MemFree(pTermCapList);
  2160. if (pTermCapDescriptorList != NULL)
  2161. MemFree(pTermCapDescriptorList);
  2162. MemFree(pCallList);
  2163. return CC_OK;
  2164. }
  2165. HRESULT CreateConferenceSessionTable(
  2166. PCONFERENCE pConference,
  2167. BOOL *pbSessionTableChanged)
  2168. {
  2169. HRESULT status;
  2170. PCALL *pCallList;
  2171. PCC_TERMCAPLIST *pTermCapList;
  2172. PCC_TERMCAPDESCRIPTORS *pTermCapDescriptorList;
  2173. WORD wListCount;
  2174. ASSERT(pConference != NULL);
  2175. if (pConference->bSessionTableInternallyConstructed == TRUE) {
  2176. status = FreeConferenceSessionTable(pConference);
  2177. if (status != CC_OK)
  2178. return status;
  2179. pConference->bSessionTableInternallyConstructed = FALSE;
  2180. }
  2181. status = _PrepareTermCapLists(pConference,
  2182. &wListCount,
  2183. &pTermCapList,
  2184. &pTermCapDescriptorList,
  2185. &pCallList);
  2186. if (status != CC_OK)
  2187. return status;
  2188. status = pConference->SessionTableConstructor(
  2189. pConference->hConference,
  2190. pConference->dwConferenceToken,
  2191. TRUE, // bCreate
  2192. pbSessionTableChanged,
  2193. wListCount,
  2194. pTermCapList,
  2195. pTermCapDescriptorList,
  2196. &pConference->pSessionTable);
  2197. _FreeTermCapLists(wListCount,
  2198. pTermCapList,
  2199. pTermCapDescriptorList,
  2200. pCallList);
  2201. return status;
  2202. }
  2203. HRESULT FreeConferenceSessionTable( PCONFERENCE pConference)
  2204. {
  2205. HRESULT status;
  2206. ASSERT(pConference != NULL);
  2207. if (pConference->bSessionTableInternallyConstructed)
  2208. status = DefaultSessionTableConstructor(
  2209. pConference->hConference,
  2210. pConference->dwConferenceToken,
  2211. FALSE, // bCreate
  2212. NULL, // pbSessionTableChanged
  2213. 0, // wListCount
  2214. NULL, // pTermCapList[]
  2215. NULL, // pTermCapDescriptors[]
  2216. &pConference->pSessionTable);
  2217. else
  2218. status = pConference->SessionTableConstructor(
  2219. pConference->hConference,
  2220. pConference->dwConferenceToken,
  2221. FALSE, // bCreate
  2222. NULL, // pbSessionTableChanged
  2223. 0, // wListCount
  2224. NULL, // pTermCapList[]
  2225. NULL, // pTermCapDescriptors[]
  2226. &pConference->pSessionTable);
  2227. pConference->pSessionTable = NULL;
  2228. return status;
  2229. }
  2230. HRESULT CreateConferenceTermCaps( PCONFERENCE pConference,
  2231. BOOL *pbTermCapsChanged)
  2232. {
  2233. HRESULT status;
  2234. WORD wListCount;
  2235. PCALL *pCallList;
  2236. PCC_TERMCAPLIST *pInTermCapList;
  2237. PCC_TERMCAPDESCRIPTORS *pInTermCapDescriptors;
  2238. ASSERT(pConference != NULL);
  2239. if (pConference->pConferenceH245H2250MuxCapability != NULL)
  2240. H245FreeCap(pConference->pConferenceH245H2250MuxCapability);
  2241. ASSERT(pConference->pLocalH245H2250MuxCapability != NULL);
  2242. status = H245CopyCap(&pConference->pConferenceH245H2250MuxCapability,
  2243. pConference->pLocalH245H2250MuxCapability);
  2244. if (status != H245_ERROR_OK)
  2245. return status;
  2246. status = _PrepareTermCapLists(pConference,
  2247. &wListCount,
  2248. &pInTermCapList,
  2249. &pInTermCapDescriptors,
  2250. &pCallList);
  2251. if (status != CC_OK)
  2252. return status;
  2253. status = UnregisterTermCapListFromH245(pConference,
  2254. pConference->pConferenceTermCapList);
  2255. if (status != CC_OK)
  2256. return status;
  2257. status = UnregisterTermCapDescriptorsFromH245(pConference,
  2258. pConference->pConferenceTermCapDescriptors);
  2259. if (status != CC_OK)
  2260. return status;
  2261. status = pConference->TermCapConstructor(
  2262. pConference->hConference,
  2263. pConference->dwConferenceToken,
  2264. TRUE, // bCreate
  2265. pbTermCapsChanged,
  2266. wListCount,
  2267. pInTermCapList,
  2268. pInTermCapDescriptors,
  2269. &pConference->pConferenceTermCapList,
  2270. &pConference->pConferenceTermCapDescriptors);
  2271. _FreeTermCapLists(wListCount,
  2272. pInTermCapList,
  2273. pInTermCapDescriptors,
  2274. pCallList);
  2275. return status;
  2276. }
  2277. HRESULT FreeConferenceTermCaps( PCONFERENCE pConference)
  2278. {
  2279. HRESULT status;
  2280. ASSERT(pConference != NULL);
  2281. status = pConference->TermCapConstructor(
  2282. pConference->hConference,
  2283. pConference->dwConferenceToken,
  2284. FALSE, // bCreate
  2285. NULL, // pbTermCapsChanged
  2286. 0, // wListCount
  2287. NULL, // pInTermCapList[]
  2288. NULL, // pInTermCapDescriptors[]
  2289. &pConference->pConferenceTermCapList,
  2290. &pConference->pConferenceTermCapDescriptors);
  2291. pConference->pConferenceTermCapList = NULL;
  2292. pConference->pConferenceTermCapDescriptors = NULL;
  2293. return status;
  2294. }
  2295. HRESULT FindEnqueuedRequest( PCALL_QUEUE pQueueHead,
  2296. CC_HCALL hEnqueuedCall)
  2297. {
  2298. PCALL_QUEUE pQueueItem;
  2299. ASSERT(hEnqueuedCall != CC_INVALID_HANDLE);
  2300. pQueueItem = pQueueHead;
  2301. while (pQueueItem != NULL) {
  2302. if (pQueueItem->hCall == hEnqueuedCall)
  2303. break;
  2304. pQueueItem = pQueueItem->pNext;
  2305. }
  2306. if (pQueueItem == NULL)
  2307. return CC_BAD_PARAM;
  2308. else
  2309. return CC_OK;
  2310. }
  2311. HRESULT EnqueueRequest( PCALL_QUEUE *ppQueueHead,
  2312. CC_HCALL hEnqueuedCall)
  2313. {
  2314. PCALL_QUEUE pQueueItem;
  2315. ASSERT(ppQueueHead != NULL);
  2316. ASSERT(hEnqueuedCall != CC_INVALID_HANDLE);
  2317. // Make sure we're not enqueuing a duplicate request
  2318. pQueueItem = *ppQueueHead;
  2319. while (pQueueItem != NULL) {
  2320. if (pQueueItem->hCall == hEnqueuedCall)
  2321. return CC_OK;
  2322. pQueueItem = pQueueItem->pNext;
  2323. }
  2324. pQueueItem = (PCALL_QUEUE)MemAlloc(sizeof(CALL_QUEUE));
  2325. if (pQueueItem == NULL)
  2326. return CC_NO_MEMORY;
  2327. pQueueItem->hCall = hEnqueuedCall;
  2328. pQueueItem->pPrev = NULL;
  2329. pQueueItem->pNext = *ppQueueHead;
  2330. if (*ppQueueHead != NULL)
  2331. (*ppQueueHead)->pPrev = pQueueItem;
  2332. *ppQueueHead = pQueueItem;
  2333. return CC_OK;
  2334. }
  2335. HRESULT DequeueRequest( PCALL_QUEUE *ppQueueHead,
  2336. PCC_HCALL phEnqueuedCall)
  2337. {
  2338. PCALL_QUEUE pQueueItem;
  2339. ASSERT(ppQueueHead != NULL);
  2340. if (phEnqueuedCall != NULL)
  2341. *phEnqueuedCall = CC_INVALID_HANDLE;
  2342. if (*ppQueueHead == NULL)
  2343. return CC_BAD_PARAM;
  2344. pQueueItem = *ppQueueHead;
  2345. *ppQueueHead = (*ppQueueHead)->pNext;
  2346. if (*ppQueueHead != NULL)
  2347. (*ppQueueHead)->pPrev = NULL;
  2348. if (phEnqueuedCall != NULL)
  2349. *phEnqueuedCall = pQueueItem->hCall;
  2350. MemFree(pQueueItem);
  2351. return CC_OK;
  2352. }
  2353. HRESULT DequeueSpecificRequest( PCALL_QUEUE *ppQueueHead,
  2354. CC_HCALL hEnqueuedCall)
  2355. {
  2356. PCALL_QUEUE pQueueItem;
  2357. ASSERT(ppQueueHead != NULL);
  2358. ASSERT(hEnqueuedCall != CC_INVALID_HANDLE);
  2359. pQueueItem = *ppQueueHead;
  2360. while (pQueueItem != NULL)
  2361. if (pQueueItem->hCall == hEnqueuedCall)
  2362. break;
  2363. else
  2364. pQueueItem = pQueueItem->pNext;
  2365. if (pQueueItem == NULL)
  2366. return CC_BAD_PARAM;
  2367. if (pQueueItem->pNext != NULL)
  2368. pQueueItem->pNext->pPrev = pQueueItem->pPrev;
  2369. if (pQueueItem->pPrev == NULL)
  2370. *ppQueueHead = pQueueItem->pNext;
  2371. else
  2372. pQueueItem->pPrev->pNext = pQueueItem->pNext;
  2373. MemFree(pQueueItem);
  2374. return CC_OK;
  2375. }
  2376.