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.

2514 lines
69 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. q931pdu.cpp
  5. Abstract:
  6. Encode/decode/transport routines for Q931/H450 messages.
  7. Author:
  8. Nikhil Bobde (NikhilB)
  9. Revision History:
  10. --*/
  11. #include "globals.h"
  12. #include "q931obj.h"
  13. #include "line.h"
  14. #include "q931pdu.h"
  15. #include "ras.h"
  16. //PARSE ROUTINES
  17. //------------------------------------------------------------------------------
  18. // Parse and return a single octet encoded value, See Q931 section 4.5.1.
  19. //
  20. // Parameters:
  21. // pbBuffer Pointer to a descriptor of the buffer
  22. // containing the length and a pointer
  23. // to the raw bytes of the input stream.
  24. // bIdent Pointer to space for field identifier
  25. // Value Pointer to space for field value
  26. //------------------------------------------------------------------------------
  27. HRESULT
  28. ParseSingleOctetType1(
  29. PBUFFERDESCR pBuf,
  30. BYTE * bIdent,
  31. BYTE * Value
  32. )
  33. {
  34. // There has to be at least 1 byte in the stream to be
  35. // able to parse the single octet value
  36. if (((LONG)(pBuf->dwLength)) < 1)
  37. {
  38. return E_INVALIDARG;
  39. }
  40. // low bits (0, 1, 2, 3) of the byte are the value
  41. *Value = (BYTE)(*pBuf->pbBuffer & TYPE1VALUEMASK);
  42. // higher bits (4, 5, 6) are the identifier. bit 7 is always 1,
  43. // and is not returned as part of the id.
  44. *bIdent = (BYTE)((*pBuf->pbBuffer & 0x70) >> 4);
  45. pBuf->pbBuffer++;
  46. pBuf->dwLength--;
  47. return S_OK;
  48. }
  49. //------------------------------------------------------------------------------
  50. // Parse and return a single octet encoded value, See Q931 section 4.5.1.
  51. // This octet has no value, only an identifier.
  52. //
  53. // Parameters:
  54. // pbBuffer Pointer to a descriptor of the buffer containing the
  55. // length and a pointer to the raw bytes of the input stream.
  56. // bIdent Pointer to space for field identifier
  57. //------------------------------------------------------------------------------
  58. HRESULT
  59. ParseSingleOctetType2(
  60. PBUFFERDESCR pBuf,
  61. BYTE * bIdent
  62. )
  63. {
  64. // There has to be at least 1 byte in the stream to be
  65. // able to parse the single octet value
  66. if (((LONG)(pBuf->dwLength)) < 1)
  67. {
  68. return E_INVALIDARG;
  69. }
  70. // low 7 bits of the byte are the identifier
  71. *bIdent = (BYTE)(*pBuf->pbBuffer & 0x7f);
  72. pBuf->pbBuffer++;
  73. pBuf->dwLength--;
  74. return S_OK;
  75. }
  76. //------------------------------------------------------------------------------
  77. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  78. //
  79. // Parameters :
  80. // pbBuffer Pointer to a descriptor of the buffer
  81. // containing the length and a pointer
  82. // to the raw bytes of the input stream.
  83. // bIdent Pointer to space for field identifier
  84. // dwLength Pointer to space for the length
  85. // pbContents Pointer to space for the bytes of the field
  86. //------------------------------------------------------------------------------
  87. HRESULT
  88. ParseVariableOctet(
  89. PBUFFERDESCR pBuf,
  90. BYTE * dwLength,
  91. BYTE * pbContents
  92. )
  93. {
  94. // There has to be at least 2 bytes in order just to get
  95. // the length and the identifier
  96. // able to parse the single octet value
  97. if (((LONG)(pBuf->dwLength)) < 2)
  98. {
  99. return E_INVALIDARG;
  100. }
  101. //Increment the ident byte
  102. pBuf->pbBuffer++;
  103. pBuf->dwLength--;
  104. // The next byte is the length
  105. *dwLength = *pBuf->pbBuffer;
  106. pBuf->pbBuffer++;
  107. pBuf->dwLength--;
  108. if (((LONG)(pBuf->dwLength)) < *dwLength)
  109. {
  110. return E_INVALIDARG;
  111. }
  112. if (*dwLength >= MAXVARFIELDLEN)
  113. {
  114. return E_INVALIDARG;
  115. }
  116. CopyMemory( pbContents, pBuf->pbBuffer, *dwLength );
  117. pBuf->pbBuffer += *dwLength;
  118. pBuf->dwLength -= *dwLength;
  119. return S_OK;
  120. }
  121. //------------------------------------------------------------------------------
  122. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  123. //------------------------------------------------------------------------------
  124. HRESULT
  125. ParseVariableASN(
  126. PBUFFERDESCR pBuf,
  127. BYTE *bIdent,
  128. BYTE *ProtocolDiscriminator,
  129. PUSERUSERIE pUserUserIE
  130. )
  131. {
  132. pUserUserIE -> wUserInfoLen = 0;
  133. // There has to be at least 4 bytes for the IE identifier,
  134. // the contents length, and the protocol discriminator (1 + 2 + 1).
  135. if (((LONG)(pBuf->dwLength)) < 4)
  136. {
  137. return E_INVALIDARG;
  138. }
  139. // low 7 bits of the first byte are the identifier
  140. *bIdent= (BYTE)(*pBuf->pbBuffer & 0x7f);
  141. pBuf->pbBuffer++;
  142. pBuf->dwLength--;
  143. // The next 2 bytes are the length
  144. pUserUserIE -> wUserInfoLen = *(pBuf->pbBuffer);
  145. pBuf->pbBuffer++;
  146. pUserUserIE -> wUserInfoLen =
  147. (WORD)(((pUserUserIE -> wUserInfoLen) << 8) + *pBuf->pbBuffer);
  148. pBuf->pbBuffer++;
  149. pBuf->dwLength -= 2;
  150. // The next byte is the protocol discriminator.
  151. *ProtocolDiscriminator = *pBuf->pbBuffer;
  152. pBuf->pbBuffer++;
  153. pBuf->dwLength--;
  154. if( pUserUserIE -> wUserInfoLen > 0 )
  155. {
  156. pUserUserIE -> wUserInfoLen--;
  157. }
  158. if (((LONG)(pBuf->dwLength)) < pUserUserIE -> wUserInfoLen )
  159. {
  160. return E_INVALIDARG;
  161. }
  162. if (pUserUserIE->wUserInfoLen >= MAX_USER_TO_USER_INFO_LEN)
  163. {
  164. return E_INVALIDARG;
  165. }
  166. CopyMemory( pUserUserIE -> pbUserInfo,
  167. pBuf->pbBuffer,
  168. pUserUserIE -> wUserInfoLen );
  169. pBuf->pbBuffer += pUserUserIE -> wUserInfoLen;
  170. pBuf->dwLength -= pUserUserIE -> wUserInfoLen;
  171. return S_OK;
  172. }
  173. //------------------------------------------------------------------------------
  174. // Get the identifier of the next field from the buffer and
  175. // return it. The buffer pointer is not incremented, To
  176. // parse the field and extract its values, the above functions
  177. // should be used. See Q931 table 4-3 for the encodings of the
  178. // identifiers.
  179. //
  180. // Parameters:
  181. // pbBuffer Pointer to the buffer space
  182. //------------------------------------------------------------------------------
  183. BYTE
  184. GetNextIdent(
  185. void *pbBuffer
  186. )
  187. {
  188. FIELDIDENTTYPE bIdent;
  189. // Extract the first byte from the buffer
  190. bIdent= (*(FIELDIDENTTYPE *)pbBuffer);
  191. // This value can be returned as the identifier as long
  192. // as it is not a single Octet - Type 1 element.
  193. // Those items must have the value removed from them
  194. // before they can be returned.
  195. if ((bIdent & 0x80) && ((bIdent & TYPE1IDENTMASK) != 0xA0))
  196. {
  197. return (BYTE)(bIdent & TYPE1IDENTMASK);
  198. }
  199. return bIdent;
  200. }
  201. //------------------------------------------------------------------------------
  202. // Parse and return a protocol discriminator. See Q931 section 4.2.
  203. // The octet pointed to by **pbBuffer is the protocol Discriminator.
  204. //
  205. // Parameters:
  206. // pbBuffer Pointer to a descriptor of the buffer
  207. // containing the length and a pointer
  208. // to the raw bytes of the input stream.
  209. // Discrim Pointer to space for discriminator
  210. //------------------------------------------------------------------------------
  211. HRESULT
  212. ParseProtocolDiscriminator(
  213. PBUFFERDESCR pBuf,
  214. PDTYPE *Discrim)
  215. {
  216. // There has to be at least enough bytes left in the
  217. // string for the operation
  218. if (((LONG)(pBuf->dwLength)) < sizeof(PDTYPE))
  219. {
  220. return E_INVALIDARG;
  221. }
  222. *Discrim = *(PDTYPE *)pBuf->pbBuffer;
  223. if (*Discrim != Q931PDVALUE)
  224. {
  225. return E_INVALIDARG;
  226. }
  227. pBuf->pbBuffer += sizeof(PDTYPE);
  228. pBuf->dwLength -= sizeof(PDTYPE);
  229. return S_OK;
  230. }
  231. //------------------------------------------------------------------------------
  232. // Parse and return a variable length Q931 call reference see
  233. // Q931 section 4.3.
  234. //
  235. // Parameters:
  236. // pbBuffer Pointer to a descriptor of the buffer
  237. // containing the length and a pointer
  238. // to the raw bytes of the input stream.
  239. // dwLength Pointer to space for the length
  240. // pbContents Pointer to space for the bytes of the field
  241. //------------------------------------------------------------------------------
  242. HRESULT
  243. ParseCallReference(
  244. PBUFFERDESCR pBuf,
  245. CRTYPE * wCallRef
  246. )
  247. {
  248. register int indexI;
  249. BYTE dwLength;
  250. // There has to be at least enough bytes left in the
  251. // string for the length byte
  252. if( ((LONG)(pBuf->dwLength)) < 1 )
  253. {
  254. return E_INVALIDARG;
  255. }
  256. // low 4 bits of the first byte are the length.
  257. // the rest of the bits are zeroes.
  258. dwLength = (BYTE)(*pBuf->pbBuffer & 0x0f);
  259. if( dwLength != sizeof(WORD) )
  260. {
  261. return E_INVALIDARG;
  262. }
  263. pBuf->pbBuffer++;
  264. pBuf->dwLength--;
  265. // There has to be at least enough bytes left in the
  266. // string for the operation
  267. if (((LONG)(pBuf->dwLength)) < dwLength)
  268. {
  269. return E_INVALIDARG;
  270. }
  271. *wCallRef = 0; // length can be 0, so initialize here first...
  272. for (indexI = 0; indexI < dwLength; indexI++)
  273. {
  274. if (indexI < sizeof(CRTYPE))
  275. {
  276. // Copy the bytes out of the rest of the buffer
  277. *wCallRef = (WORD)((*wCallRef << 8) +
  278. *pBuf->pbBuffer);
  279. }
  280. pBuf->pbBuffer++;
  281. pBuf->dwLength--;
  282. }
  283. // note: the high order bit of the value represents callee relationship.
  284. return S_OK;
  285. }
  286. //------------------------------------------------------------------------------
  287. // Parse and return a message type. See Q931 section 4.4.
  288. // The octet pointed to by **pbBuffer is the message type.
  289. //
  290. // Parameters:
  291. // pbBuffer Pointer to a descriptor of the buffer
  292. // containing the length and a pointer
  293. // to the raw bytes of the input stream.
  294. // MessageType Pointer to space for message type
  295. //------------------------------------------------------------------------------
  296. HRESULT
  297. ParseMessageType(
  298. PBUFFERDESCR pBuf,
  299. MESSAGEIDTYPE * MessageType
  300. )
  301. {
  302. // There has to be at least enough bytes left in the
  303. // string for the operation
  304. if (((LONG)(pBuf->dwLength)) < sizeof(MESSAGEIDTYPE))
  305. {
  306. return E_INVALIDARG;
  307. }
  308. *MessageType = (BYTE)(*((MESSAGEIDTYPE *)pBuf->pbBuffer) & MESSAGETYPEMASK);
  309. if( ISVALIDQ931MESSAGE(*MessageType) == FALSE )
  310. {
  311. return E_INVALIDARG;
  312. }
  313. pBuf->pbBuffer += sizeof(MESSAGEIDTYPE);
  314. pBuf->dwLength -= sizeof(MESSAGEIDTYPE);
  315. return S_OK;
  316. }
  317. //------------------------------------------------------------------------------
  318. // Parse an optional facility ie field
  319. //
  320. // Parameters:
  321. // pbBuffer Pointer to a descriptor of the buffer
  322. // containing the length and a pointer
  323. // to the raw bytes of the input stream.
  324. // pFieldStruct Pointer to space for parsed facility
  325. // information.
  326. //------------------------------------------------------------------------------
  327. HRESULT
  328. ParseFacility(
  329. PBUFFERDESCR pBuf,
  330. PFACILITYIE pFieldStruct
  331. )
  332. {
  333. HRESULT hr;
  334. memset( (PVOID)pFieldStruct, 0, sizeof(FACILITYIE));
  335. pFieldStruct->fPresent = FALSE;
  336. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  337. &pFieldStruct->pbContents[0]);
  338. if( FAILED(hr) )
  339. {
  340. return hr;
  341. }
  342. if (pFieldStruct->dwLength > 0)
  343. {
  344. pFieldStruct->fPresent = TRUE;
  345. }
  346. return S_OK;
  347. }
  348. //------------------------------------------------------------------------------
  349. // Parse an optional bearer capability field
  350. //
  351. // Parameters:
  352. // pbBuffer Pointer to a descriptor of the buffer
  353. // containing the length and a pointer
  354. // to the raw bytes of the input stream.
  355. // pFieldStruct Pointer to space for parsed bearer capability
  356. // information.
  357. //------------------------------------------------------------------------------
  358. HRESULT
  359. ParseBearerCapability(
  360. PBUFFERDESCR pBuf,
  361. PBEARERCAPIE pFieldStruct)
  362. {
  363. HRESULT hr;
  364. memset( (PVOID)pFieldStruct, 0, sizeof(BEARERCAPIE));
  365. pFieldStruct->fPresent = FALSE;
  366. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  367. &pFieldStruct->pbContents[0]);
  368. if( FAILED(hr) )
  369. {
  370. return hr;
  371. }
  372. if (pFieldStruct->dwLength > 0)
  373. {
  374. pFieldStruct->fPresent = TRUE;
  375. }
  376. return S_OK;
  377. }
  378. //------------------------------------------------------------------------------
  379. // Parse an optional cause field
  380. //
  381. // Parameters:
  382. // pbBuffer Pointer to a descriptor of the buffer
  383. // containing the length and a pointer
  384. // to the raw bytes of the input stream.
  385. // pFieldStruct Pointer to space for parsed cause
  386. // information.
  387. //------------------------------------------------------------------------------
  388. HRESULT
  389. ParseCause(
  390. PBUFFERDESCR pBuf,
  391. PCAUSEIE pFieldStruct)
  392. {
  393. HRESULT hr;
  394. memset( (PVOID)pFieldStruct, 0, sizeof(CAUSEIE));
  395. pFieldStruct->fPresent = FALSE;
  396. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  397. &pFieldStruct->pbContents[0]);
  398. if( FAILED(hr) )
  399. {
  400. return hr;
  401. }
  402. if (pFieldStruct->dwLength > 0)
  403. {
  404. pFieldStruct->fPresent = TRUE;
  405. }
  406. return S_OK;
  407. }
  408. //------------------------------------------------------------------------------
  409. // Parse an optional call state field
  410. //
  411. // Parameters:
  412. // pbBuffer Pointer to a descriptor of the buffer
  413. // containing the length and a pointer
  414. // to the raw bytes of the input stream.
  415. // pFieldStruct Pointer to space for parsed call state
  416. // information.
  417. //------------------------------------------------------------------------------
  418. HRESULT
  419. ParseCallState(
  420. PBUFFERDESCR pBuf,
  421. PCALLSTATEIE pFieldStruct)
  422. {
  423. memset( (PVOID)pFieldStruct, 0, sizeof(CALLSTATEIE));
  424. pFieldStruct->fPresent = FALSE;
  425. HRESULT hr;
  426. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  427. &pFieldStruct->pbContents[0]);
  428. if( FAILED(hr) )
  429. {
  430. return hr;
  431. }
  432. if (pFieldStruct->dwLength > 0)
  433. {
  434. pFieldStruct->fPresent = TRUE;
  435. }
  436. return S_OK;
  437. }
  438. //------------------------------------------------------------------------------
  439. // Parse an optional channel identification field
  440. //
  441. // Parameters:
  442. // pbBuffer Pointer to a descriptor of the buffer
  443. // containing the length and a pointer
  444. // to the raw bytes of the input stream.
  445. // pFieldStruct Pointer to space for parsed channel identity
  446. // information.
  447. //------------------------------------------------------------------------------
  448. HRESULT
  449. ParseChannelIdentification(
  450. PBUFFERDESCR pBuf,
  451. PCHANIDENTIE pFieldStruct)
  452. {
  453. memset( (PVOID)pFieldStruct, 0, sizeof(CHANIDENTIE));
  454. pFieldStruct->fPresent = FALSE;
  455. HRESULT hr;
  456. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  457. &pFieldStruct->pbContents[0]);
  458. if( FAILED(hr) )
  459. {
  460. return hr;
  461. }
  462. if (pFieldStruct->dwLength > 0)
  463. {
  464. pFieldStruct->fPresent = TRUE;
  465. }
  466. return S_OK;
  467. }
  468. //------------------------------------------------------------------------------
  469. // Parse an optional progress indication field
  470. //
  471. // Parameters:
  472. // pbBuffer Pointer to a descriptor of the buffer
  473. // containing the length and a pointer
  474. // to the raw bytes of the input stream.
  475. // pFieldStruct Pointer to space for parsed progress
  476. // information.
  477. //------------------------------------------------------------------------------
  478. HRESULT
  479. ParseProgress(
  480. PBUFFERDESCR pBuf,
  481. PPROGRESSIE pFieldStruct)
  482. {
  483. memset( (PVOID)pFieldStruct, 0, sizeof(PROGRESSIE));
  484. pFieldStruct->fPresent = FALSE;
  485. HRESULT hr;
  486. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  487. &pFieldStruct->pbContents[0]);
  488. if( FAILED(hr) )
  489. {
  490. return hr;
  491. }
  492. if (pFieldStruct->dwLength > 0)
  493. {
  494. pFieldStruct->fPresent = TRUE;
  495. }
  496. return S_OK;
  497. }
  498. //------------------------------------------------------------------------------
  499. // Parse an optional network specific facilities field
  500. //
  501. // Parameters:
  502. // pbBuffer Pointer to a descriptor of the buffer
  503. // containing the length and a pointer
  504. // to the raw bytes of the input stream.
  505. // pFieldStruct Pointer to space for parsed network facitlities
  506. // information.
  507. //------------------------------------------------------------------------------
  508. HRESULT
  509. ParseNetworkSpec(
  510. PBUFFERDESCR pBuf,
  511. PNETWORKIE pFieldStruct)
  512. {
  513. memset( (PVOID)pFieldStruct, 0, sizeof(NETWORKIE));
  514. pFieldStruct->fPresent = FALSE;
  515. HRESULT hr;
  516. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  517. &pFieldStruct->pbContents[0]);
  518. if( FAILED(hr) )
  519. {
  520. return hr;
  521. }
  522. if (pFieldStruct->dwLength > 0)
  523. {
  524. pFieldStruct->fPresent = TRUE;
  525. }
  526. return S_OK;
  527. }
  528. //------------------------------------------------------------------------------
  529. // Parse an optional notification indicator field
  530. //
  531. // Parameters:
  532. // pbBuffer Pointer to a descriptor of the buffer
  533. // containing the length and a pointer
  534. // to the raw bytes of the input stream.
  535. // pFieldStruct Pointer to space for parse notification indicator
  536. // information.
  537. //------------------------------------------------------------------------------
  538. HRESULT
  539. ParseNotificationIndicator(
  540. PBUFFERDESCR pBuf,
  541. PNOTIFICATIONINDIE pFieldStruct)
  542. {
  543. memset( (PVOID)pFieldStruct, 0, sizeof(NOTIFICATIONINDIE));
  544. pFieldStruct->fPresent = FALSE;
  545. if (GetNextIdent(pBuf->pbBuffer) == IDENT_NOTIFICATION)
  546. {
  547. HRESULT hr;
  548. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  549. &pFieldStruct->pbContents[0]);
  550. if( FAILED(hr) )
  551. {
  552. return hr;
  553. }
  554. if (pFieldStruct->dwLength > 0)
  555. {
  556. pFieldStruct->fPresent = TRUE;
  557. }
  558. }
  559. return S_OK;
  560. }
  561. //------------------------------------------------------------------------------
  562. // Parse an optional display field
  563. //
  564. // Parameters:
  565. // pbBuffer Pointer to a descriptor of the buffer
  566. // containing the length and a pointer
  567. // to the raw bytes of the input stream.
  568. // pFieldStruct Pointer to space for parsed display
  569. // information.
  570. //------------------------------------------------------------------------------
  571. HRESULT
  572. ParseDisplay(
  573. PBUFFERDESCR pBuf,
  574. PDISPLAYIE pFieldStruct)
  575. {
  576. HRESULT hr;
  577. memset( (PVOID)pFieldStruct, 0, sizeof(DISPLAYIE));
  578. pFieldStruct->fPresent = FALSE;
  579. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  580. &pFieldStruct->pbContents[0]);
  581. if( FAILED(hr) )
  582. {
  583. return hr;
  584. }
  585. if (pFieldStruct->dwLength > 0)
  586. {
  587. pFieldStruct->fPresent = TRUE;
  588. }
  589. return S_OK;
  590. }
  591. HRESULT
  592. ParseDate(
  593. PBUFFERDESCR pBuf,
  594. PDATEIE pFieldStruct)
  595. {
  596. HRESULT hr;
  597. memset( (PVOID)pFieldStruct, 0, sizeof(DATEIE));
  598. pFieldStruct->fPresent = FALSE;
  599. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  600. &pFieldStruct->pbContents[0]);
  601. if( FAILED(hr) )
  602. {
  603. return hr;
  604. }
  605. if (pFieldStruct->dwLength > 0)
  606. {
  607. pFieldStruct->fPresent = TRUE;
  608. }
  609. return S_OK;
  610. }
  611. //------------------------------------------------------------------------------
  612. // Parse an optional keypad field
  613. //
  614. // Parameters:
  615. // pbBuffer Pointer to a descriptor of the buffer
  616. // containing the length and a pointer
  617. // to the raw bytes of the input stream.
  618. // pFieldStruct Pointer to space for parsed keypad
  619. // information.
  620. //------------------------------------------------------------------------------
  621. HRESULT
  622. ParseKeypad(
  623. PBUFFERDESCR pBuf,
  624. PKEYPADIE pFieldStruct)
  625. {
  626. HRESULT hr;
  627. memset( (PVOID)pFieldStruct, 0, sizeof(KEYPADIE));
  628. pFieldStruct->fPresent = FALSE;
  629. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  630. &pFieldStruct->pbContents[0]);
  631. if( FAILED(hr) )
  632. {
  633. return hr;
  634. }
  635. if (pFieldStruct->dwLength > 0)
  636. {
  637. pFieldStruct->fPresent = TRUE;
  638. }
  639. return S_OK;
  640. }
  641. //------------------------------------------------------------------------------
  642. // Parse an optional signal field
  643. //
  644. // Parameters:
  645. // pbBuffer Pointer to a descriptor of the buffer
  646. // containing the length and a pointer
  647. // to the raw bytes of the input stream.
  648. // pFieldStruct Pointer to space for parsed signal
  649. // information.
  650. //------------------------------------------------------------------------------
  651. HRESULT
  652. ParseSignal(
  653. PBUFFERDESCR pBuf,
  654. PSIGNALIE pFieldStruct)
  655. {
  656. HRESULT hr;
  657. memset( (PVOID)pFieldStruct, 0, sizeof(SIGNALIE));
  658. pFieldStruct->fPresent = FALSE;
  659. hr = ParseVariableOctet(pBuf,
  660. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  661. if( FAILED(hr) )
  662. {
  663. return hr;
  664. }
  665. if (pFieldStruct->dwLength > 0)
  666. {
  667. pFieldStruct->fPresent = TRUE;
  668. }
  669. return S_OK;
  670. }
  671. //------------------------------------------------------------------------------
  672. // Parse an optional information rate field
  673. //
  674. // Parameters:
  675. // pbBuffer Pointer to a descriptor of the buffer
  676. // containing the length and a pointer
  677. // to the raw bytes of the input stream.
  678. // pFieldStruct Pointer to space for parsed information rate
  679. // information.
  680. //------------------------------------------------------------------------------
  681. HRESULT
  682. ParseInformationRate(
  683. PBUFFERDESCR pBuf,
  684. PINFORATEIE pFieldStruct)
  685. {
  686. HRESULT hr;
  687. memset( (PVOID)pFieldStruct, 0, sizeof(INFORATEIE));
  688. pFieldStruct->fPresent = FALSE;
  689. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  690. &pFieldStruct->pbContents[0]);
  691. if( FAILED(hr) )
  692. {
  693. return hr;
  694. }
  695. if (pFieldStruct->dwLength > 0)
  696. {
  697. pFieldStruct->fPresent = TRUE;
  698. }
  699. return S_OK;
  700. }
  701. //------------------------------------------------------------------------------
  702. // Parse an optional calling party number field
  703. //
  704. // Parameters:
  705. // pbBuffer Pointer to a descriptor of the buffer
  706. // containing the length and a pointer
  707. // to the raw bytes of the input stream.
  708. // pFieldStruct Pointer to space for parsed
  709. // information.
  710. //------------------------------------------------------------------------------
  711. HRESULT
  712. ParseCallingPartyNumber(
  713. PBUFFERDESCR pBuf,
  714. PCALLINGNUMBERIE pFieldStruct)
  715. {
  716. HRESULT hr;
  717. memset( (PVOID)pFieldStruct, 0, sizeof(CALLINGNUMBERIE));
  718. pFieldStruct->fPresent = FALSE;
  719. hr = ParseVariableOctet(pBuf,
  720. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  721. if( FAILED(hr) )
  722. {
  723. return hr;
  724. }
  725. if (pFieldStruct->dwLength > 0)
  726. {
  727. pFieldStruct->fPresent = TRUE;
  728. }
  729. return S_OK;
  730. }
  731. //------------------------------------------------------------------------------
  732. // Parse an optional calling party subaddress field
  733. //
  734. // Parameters:
  735. // pbBuffer Pointer to a descriptor of the buffer
  736. // containing the length and a pointer
  737. // to the raw bytes of the input stream.
  738. // pFieldStruct Pointer to space for parsed
  739. // information.
  740. //------------------------------------------------------------------------------
  741. HRESULT
  742. ParseCallingPartySubaddress(
  743. PBUFFERDESCR pBuf,
  744. PCALLINGSUBADDRIE pFieldStruct)
  745. {
  746. HRESULT hr;
  747. memset( (PVOID)pFieldStruct, 0, sizeof(CALLINGSUBADDRIE));
  748. pFieldStruct->fPresent = FALSE;
  749. hr = ParseVariableOctet(pBuf,
  750. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  751. if( FAILED(hr) )
  752. {
  753. return hr;
  754. }
  755. if (pFieldStruct->dwLength > 0)
  756. {
  757. pFieldStruct->fPresent = TRUE;
  758. }
  759. return S_OK;
  760. }
  761. //------------------------------------------------------------------------------
  762. // Parse an optional called party number field
  763. //
  764. // Parameters:
  765. // pbBuffer Pointer to a descriptor of the buffer
  766. // containing the length and a pointer
  767. // to the raw bytes of the input stream.
  768. // pFieldStruct Pointer to space for parsed
  769. // information.
  770. //------------------------------------------------------------------------------
  771. HRESULT
  772. ParseCalledPartyNumber(
  773. PBUFFERDESCR pBuf,
  774. PCALLEDNUMBERIE pFieldStruct
  775. )
  776. {
  777. memset( (PVOID)pFieldStruct, 0, sizeof(PCALLEDNUMBERIE));
  778. pFieldStruct->fPresent = FALSE;
  779. if (GetNextIdent(pBuf->pbBuffer) == IDENT_CALLEDNUMBER)
  780. {
  781. BYTE RemainingLength = 0;
  782. // Need 3 bytes for the ident (1), length (1),
  783. // and type + plan (1) fields.
  784. if (((LONG)(pBuf->dwLength)) < 3)
  785. {
  786. return E_INVALIDARG;
  787. }
  788. // skip the ie identifier...
  789. pBuf->pbBuffer++;
  790. pBuf->dwLength--;
  791. // Get the length of the contents following the length field.
  792. RemainingLength = *pBuf->pbBuffer;
  793. pBuf->pbBuffer++;
  794. pBuf->dwLength--;
  795. // Get the type + plan fields.
  796. if (*(pBuf->pbBuffer) & 0x80)
  797. {
  798. pFieldStruct->NumberType =
  799. (BYTE)(*pBuf->pbBuffer & 0xf0);
  800. pFieldStruct->NumberingPlan =
  801. (BYTE)(*pBuf->pbBuffer & 0x0f);
  802. pBuf->pbBuffer++;
  803. pBuf->dwLength--;
  804. RemainingLength--;
  805. }
  806. // make sure we have at least that much length left...
  807. if (((LONG)(pBuf->dwLength)) < RemainingLength)
  808. {
  809. return E_INVALIDARG;
  810. }
  811. if ( RemainingLength >= MAXVARFIELDLEN)
  812. {
  813. return E_INVALIDARG;
  814. }
  815. pFieldStruct->PartyNumberLength = RemainingLength;
  816. pFieldStruct->fPresent = TRUE;
  817. CopyMemory( pFieldStruct->PartyNumbers, pBuf->pbBuffer, RemainingLength );
  818. pBuf->pbBuffer += RemainingLength;
  819. pBuf->dwLength -= RemainingLength;
  820. }
  821. return S_OK;
  822. }
  823. //------------------------------------------------------------------------------
  824. // Parse an optional called party subaddress field
  825. //
  826. // Parameters:
  827. // pbBuffer Pointer to a descriptor of the buffer
  828. // containing the length and a pointer
  829. // to the raw bytes of the input stream.
  830. // pFieldStruct Pointer to space for parsed
  831. // information.
  832. //------------------------------------------------------------------------------
  833. HRESULT
  834. ParseCalledPartySubaddress(
  835. PBUFFERDESCR pBuf,
  836. PCALLEDSUBADDRIE pFieldStruct
  837. )
  838. {
  839. HRESULT hr;
  840. memset( (PVOID)pFieldStruct, 0, sizeof(CALLEDSUBADDRIE));
  841. pFieldStruct->fPresent = FALSE;
  842. hr = ParseVariableOctet(pBuf,
  843. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  844. if( FAILED(hr) )
  845. {
  846. return hr;
  847. }
  848. if (pFieldStruct->dwLength > 0)
  849. {
  850. pFieldStruct->fPresent = TRUE;
  851. }
  852. return S_OK;
  853. }
  854. //------------------------------------------------------------------------------
  855. // Parse an optional redirecting number field
  856. //
  857. // Parameters:
  858. // pbBuffer Pointer to a descriptor of the buffer
  859. // containing the length and a pointer
  860. // to the raw bytes of the input stream.
  861. // pFieldStruct Pointer to space for parsed
  862. // information.
  863. //------------------------------------------------------------------------------
  864. HRESULT
  865. ParseRedirectingNumber(
  866. PBUFFERDESCR pBuf,
  867. PREDIRECTINGIE pFieldStruct
  868. )
  869. {
  870. HRESULT hr;
  871. memset( (PVOID)pFieldStruct, 0, sizeof(REDIRECTINGIE));
  872. pFieldStruct->fPresent = FALSE;
  873. hr = ParseVariableOctet(pBuf,
  874. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  875. if( FAILED(hr) )
  876. {
  877. return hr;
  878. }
  879. if (pFieldStruct->dwLength > 0)
  880. {
  881. pFieldStruct->fPresent = TRUE;
  882. }
  883. return S_OK;
  884. }
  885. //------------------------------------------------------------------------------
  886. // Parse an optional lower layer compatibility field
  887. //
  888. // Parameters:
  889. // pbBuffer Pointer to a descriptor of the buffer
  890. // containing the length and a pointer
  891. // to the raw bytes of the input stream.
  892. // pFieldStruct Pointer to space for parsed
  893. // information.
  894. //------------------------------------------------------------------------------
  895. HRESULT
  896. ParseLowLayerCompatibility(
  897. PBUFFERDESCR pBuf,
  898. PLLCOMPATIBILITYIE pFieldStruct
  899. )
  900. {
  901. HRESULT hr;
  902. memset( (PVOID)pFieldStruct, 0, sizeof(LLCOMPATIBILITYIE));
  903. pFieldStruct->fPresent = FALSE;
  904. hr = ParseVariableOctet(pBuf,
  905. &pFieldStruct->dwLength, &pFieldStruct->pbContents[0]);
  906. if( FAILED(hr) )
  907. {
  908. return hr;
  909. }
  910. if (pFieldStruct->dwLength > 0)
  911. {
  912. pFieldStruct->fPresent = TRUE;
  913. }
  914. return S_OK;
  915. }
  916. //------------------------------------------------------------------------------
  917. // Parse an optional higher layer compatibility field
  918. //
  919. // Parameters:
  920. // pbBuffer Pointer to a descriptor of the buffer
  921. // containing the length and a pointer
  922. // to the raw bytes of the input stream.
  923. // pFieldStruct Pointer to space for parsed
  924. // information.
  925. //------------------------------------------------------------------------------
  926. HRESULT
  927. ParseHighLayerCompatibility(
  928. PBUFFERDESCR pBuf,
  929. PHLCOMPATIBILITYIE pFieldStruct
  930. )
  931. {
  932. HRESULT hr;
  933. memset( (PVOID)pFieldStruct, 0, sizeof(HLCOMPATIBILITYIE));
  934. pFieldStruct->fPresent = FALSE;
  935. hr = ParseVariableOctet(pBuf, &pFieldStruct->dwLength,
  936. &pFieldStruct->pbContents[0]);
  937. if( FAILED(hr) )
  938. {
  939. return hr;
  940. }
  941. if (pFieldStruct->dwLength > 0)
  942. {
  943. pFieldStruct->fPresent = TRUE;
  944. }
  945. return S_OK;
  946. }
  947. HRESULT
  948. ParseUserToUser(
  949. PBUFFERDESCR pBuf,
  950. PUSERUSERIE pFieldStruct
  951. )
  952. {
  953. BYTE bIdent;
  954. HRESULT hr;
  955. ZeroMemory( (PVOID)pFieldStruct, sizeof(USERUSERIE));
  956. pFieldStruct->fPresent = FALSE;
  957. hr = ParseVariableASN( pBuf,
  958. &bIdent,
  959. &(pFieldStruct->ProtocolDiscriminator),
  960. pFieldStruct
  961. );
  962. if( FAILED(hr) )
  963. {
  964. return hr;
  965. }
  966. if (pFieldStruct->wUserInfoLen > 0)
  967. {
  968. pFieldStruct->fPresent = TRUE;
  969. }
  970. return S_OK;
  971. }
  972. HRESULT
  973. ParseQ931Field(
  974. PBUFFERDESCR pBuf,
  975. PQ931MESSAGE pMessage
  976. )
  977. {
  978. FIELDIDENTTYPE bIdent;
  979. bIdent = GetNextIdent(pBuf->pbBuffer);
  980. switch (bIdent)
  981. {
  982. /*case IDENT_REVCHARGE:
  983. case IDENT_TRANSITNET:
  984. case IDENT_RESTART:
  985. case IDENT_MORE:
  986. case IDENT_REPEAT:
  987. case IDENT_SEGMENTED:
  988. case IDENT_SHIFT:
  989. case IDENT_CALLIDENT:
  990. case IDENT_CLOSEDUG:
  991. case IDENT_SENDINGCOMPLETE:
  992. case IDENT_PACKETSIZE:
  993. case IDENT_CONGESTION:
  994. case IDENT_NETWORKSPEC:
  995. case IDENT_PLWINDOWSIZE:
  996. case IDENT_TRANSITDELAY:
  997. case IDENT_PLBINARYPARAMS:
  998. case IDENT_ENDTOENDDELAY:
  999. return E_INVALIDARG;*/
  1000. case IDENT_FACILITY:
  1001. return ParseFacility( pBuf, &pMessage->Facility );
  1002. case IDENT_BEARERCAP:
  1003. return ParseBearerCapability( pBuf, &pMessage->BearerCapability );
  1004. case IDENT_CAUSE:
  1005. return ParseCause(pBuf, &pMessage->Cause);
  1006. case IDENT_CALLSTATE:
  1007. return ParseCallState(pBuf, &pMessage->CallState);
  1008. case IDENT_CHANNELIDENT:
  1009. return ParseChannelIdentification( pBuf,
  1010. &pMessage->ChannelIdentification );
  1011. case IDENT_PROGRESS:
  1012. return ParseProgress( pBuf, &pMessage->ProgressIndicator );
  1013. case IDENT_NOTIFICATION:
  1014. return ParseNotificationIndicator( pBuf,
  1015. &pMessage->NotificationIndicator );
  1016. case IDENT_DISPLAY:
  1017. return ParseDisplay( pBuf, &pMessage->Display );
  1018. case IDENT_DATE:
  1019. return ParseDate( pBuf, &pMessage->Date );
  1020. case IDENT_KEYPAD:
  1021. return ParseKeypad( pBuf, &pMessage->Keypad );
  1022. case IDENT_SIGNAL:
  1023. return ParseSignal(pBuf, &pMessage->Signal);
  1024. case IDENT_INFORMATIONRATE:
  1025. return ParseInformationRate( pBuf, &pMessage->InformationRate );
  1026. case IDENT_CALLINGNUMBER:
  1027. return ParseCallingPartyNumber( pBuf, &pMessage->CallingPartyNumber );
  1028. case IDENT_CALLINGSUBADDR:
  1029. return ParseCallingPartySubaddress(pBuf,
  1030. &pMessage->CallingPartySubaddress);
  1031. case IDENT_CALLEDNUMBER:
  1032. return ParseCalledPartyNumber(pBuf, &pMessage->CalledPartyNumber);
  1033. case IDENT_CALLEDSUBADDR:
  1034. return ParseCalledPartySubaddress( pBuf,
  1035. &pMessage->CalledPartySubaddress );
  1036. case IDENT_REDIRECTING:
  1037. return ParseRedirectingNumber( pBuf, &pMessage->RedirectingNumber );
  1038. case IDENT_LLCOMPATIBILITY:
  1039. return ParseLowLayerCompatibility( pBuf,
  1040. &pMessage->LowLayerCompatibility );
  1041. case IDENT_HLCOMPATIBILITY:
  1042. return ParseHighLayerCompatibility( pBuf,
  1043. &pMessage->HighLayerCompatibility );
  1044. case IDENT_USERUSER:
  1045. return ParseUserToUser(pBuf, &pMessage->UserToUser);
  1046. default:
  1047. //Increment the ident byte
  1048. pBuf->pbBuffer++;
  1049. pBuf->dwLength--;
  1050. return S_OK;
  1051. }
  1052. }
  1053. //------------------------------------------------------------------------------
  1054. // Write a Q931 message type. See Q931 section 4.4.
  1055. //------------------------------------------------------------------------------
  1056. void
  1057. WriteMessageType(
  1058. PBUFFERDESCR pBuf,
  1059. MESSAGEIDTYPE * MessageType,
  1060. DWORD* pdwPDULen
  1061. )
  1062. {
  1063. (*pdwPDULen) += sizeof(MESSAGEIDTYPE);
  1064. _ASSERTE( pBuf->dwLength > *pdwPDULen );
  1065. *(MESSAGEIDTYPE *)(pBuf->pbBuffer) =
  1066. (BYTE)(*MessageType & MESSAGETYPEMASK);
  1067. pBuf->pbBuffer += sizeof(MESSAGEIDTYPE);
  1068. }
  1069. void
  1070. WriteVariableOctet(
  1071. PBUFFERDESCR pBuf,
  1072. BYTE bIdent,
  1073. BYTE dwLength,
  1074. BYTE *pbContents,
  1075. DWORD* pdwPDULen
  1076. )
  1077. {
  1078. if( pbContents == NULL )
  1079. {
  1080. dwLength = 0;
  1081. }
  1082. // space for the length and the identifier bytes and octet array
  1083. (*pdwPDULen) += (2 + dwLength);
  1084. _ASSERTE( pBuf->dwLength > *pdwPDULen );
  1085. // the id byte, then the length byte
  1086. // low 7 bits of the first byte are the identifier
  1087. *pBuf->pbBuffer = (BYTE)(bIdent & 0x7f);
  1088. pBuf->pbBuffer++;
  1089. *pBuf->pbBuffer = dwLength;
  1090. pBuf->pbBuffer++;
  1091. CopyMemory( (PVOID)pBuf->pbBuffer, (PVOID)pbContents, dwLength );
  1092. pBuf->pbBuffer += dwLength;
  1093. }
  1094. void
  1095. WriteUserInformation(
  1096. PBUFFERDESCR pBuf,
  1097. BYTE bIdent,
  1098. WORD wUserInfoLen,
  1099. BYTE * pbUserInfo,
  1100. DWORD * pdwPDULen
  1101. )
  1102. {
  1103. WORD ContentsLength = (WORD)(wUserInfoLen + 1);
  1104. // There has to be at least 4 bytes for the IE identifier,
  1105. // the contents length, and the protocol discriminator (1 + 2 + 1).
  1106. (*pdwPDULen) += (4 + wUserInfoLen);
  1107. _ASSERTE( pBuf->dwLength > *pdwPDULen );
  1108. // low 7 bits of the first byte are the identifier
  1109. *pBuf->pbBuffer = (BYTE)(bIdent & 0x7f);
  1110. pBuf->pbBuffer++;
  1111. // write the contents length bytes.
  1112. *pBuf->pbBuffer = (BYTE)(ContentsLength >> 8);
  1113. pBuf->pbBuffer++;
  1114. *pBuf->pbBuffer = (BYTE)ContentsLength;
  1115. pBuf->pbBuffer++;
  1116. // write the protocol discriminator byte.
  1117. *(pBuf->pbBuffer) = Q931_PROTOCOL_X209;
  1118. pBuf->pbBuffer++;
  1119. CopyMemory( (PVOID)pBuf->pbBuffer,
  1120. (PVOID)pbUserInfo,
  1121. wUserInfoLen);
  1122. pBuf->pbBuffer += wUserInfoLen;
  1123. }
  1124. HRESULT
  1125. WritePartyNumber(
  1126. PBUFFERDESCR pBuf,
  1127. BYTE bIdent,
  1128. BYTE NumberType,
  1129. BYTE NumberingPlan,
  1130. BYTE bPartyNumberLength,
  1131. BYTE *pbPartyNumbers,
  1132. DWORD * pdwPDULen )
  1133. {
  1134. if (pbPartyNumbers == NULL)
  1135. {
  1136. bPartyNumberLength = 1;
  1137. }
  1138. // space for the ident (1), length (1), and type + plan (1) fields.
  1139. (*pdwPDULen) += (2 + bPartyNumberLength);
  1140. _ASSERTE( pBuf->dwLength > *pdwPDULen );
  1141. // low 7 bits of byte 1 are the ie identifier
  1142. *pBuf->pbBuffer = (BYTE)(bIdent & 0x7f);
  1143. pBuf->pbBuffer++;
  1144. // byte 2 is the ie contents length following the length field.
  1145. *pBuf->pbBuffer = (BYTE)(bPartyNumberLength);
  1146. pBuf->pbBuffer++;
  1147. // byte 3 is the type and plan field.
  1148. *pBuf->pbBuffer = (BYTE)(NumberType | NumberingPlan);
  1149. pBuf->pbBuffer++;
  1150. if( pbPartyNumbers != NULL )
  1151. {
  1152. CopyMemory( (PVOID)pBuf->pbBuffer,
  1153. (PVOID)pbPartyNumbers,
  1154. bPartyNumberLength-1 );
  1155. }
  1156. pBuf->pbBuffer += (bPartyNumberLength-1);
  1157. return S_OK;
  1158. }
  1159. //
  1160. //ASN Parsing functions
  1161. //
  1162. BOOL
  1163. ParseVendorInfo(
  1164. OUT PH323_VENDORINFO pDestVendorInfo,
  1165. IN VendorIdentifier* pVendor
  1166. )
  1167. {
  1168. memset( (PVOID)pDestVendorInfo, 0, sizeof(H323_VENDORINFO) );
  1169. pDestVendorInfo ->bCountryCode = (BYTE)pVendor->vendor.t35CountryCode;
  1170. pDestVendorInfo ->bExtension = (BYTE)pVendor->vendor.t35Extension;
  1171. pDestVendorInfo ->wManufacturerCode = pVendor->vendor.manufacturerCode;
  1172. if( pVendor->bit_mask & (productId_present) )
  1173. {
  1174. pDestVendorInfo ->pProductNumber = new H323_OCTETSTRING;
  1175. if( pDestVendorInfo ->pProductNumber == NULL )
  1176. {
  1177. goto cleanup;
  1178. }
  1179. pDestVendorInfo ->pProductNumber->wOctetStringLength =
  1180. (WORD)min(pVendor->productId.length, H323_MAX_PRODUCT_LENGTH - 1);
  1181. pDestVendorInfo ->pProductNumber->pOctetString = (BYTE*)
  1182. new char[pDestVendorInfo ->pProductNumber->wOctetStringLength + 1];
  1183. if( pDestVendorInfo ->pProductNumber->pOctetString == NULL )
  1184. {
  1185. goto cleanup;
  1186. }
  1187. CopyMemory( (PVOID)pDestVendorInfo ->pProductNumber->pOctetString,
  1188. (PVOID)pVendor->productId.value,
  1189. pDestVendorInfo -> pProductNumber->wOctetStringLength );
  1190. pDestVendorInfo ->pProductNumber->pOctetString[
  1191. pDestVendorInfo ->pProductNumber->wOctetStringLength] = '\0';
  1192. }
  1193. if( pVendor->bit_mask & versionId_present )
  1194. {
  1195. pDestVendorInfo ->pVersionNumber = new H323_OCTETSTRING;
  1196. if( pDestVendorInfo ->pVersionNumber == NULL )
  1197. {
  1198. goto cleanup;
  1199. }
  1200. pDestVendorInfo ->pVersionNumber->wOctetStringLength =
  1201. (WORD)min(pVendor->versionId.length, H323_MAX_VERSION_LENGTH - 1);
  1202. pDestVendorInfo ->pVersionNumber->pOctetString = (BYTE*)
  1203. new char[pDestVendorInfo ->pVersionNumber->wOctetStringLength+1];
  1204. if( pDestVendorInfo ->pVersionNumber->pOctetString == NULL )
  1205. {
  1206. goto cleanup;
  1207. }
  1208. CopyMemory( (PVOID)pDestVendorInfo ->pVersionNumber->pOctetString,
  1209. (PVOID)pVendor->versionId.value,
  1210. pDestVendorInfo ->pVersionNumber->wOctetStringLength);
  1211. pDestVendorInfo ->pVersionNumber->pOctetString[
  1212. pDestVendorInfo ->pVersionNumber->wOctetStringLength] = '\0';
  1213. }
  1214. return TRUE;
  1215. cleanup:
  1216. FreeVendorInfo( pDestVendorInfo );
  1217. return FALSE;
  1218. }
  1219. BOOL
  1220. ParseNonStandardData(
  1221. OUT H323NonStandardData * dstNonStdData,
  1222. IN H225NonStandardParameter * srcNonStdData
  1223. )
  1224. {
  1225. H221NonStandard & h221NonStdData =
  1226. srcNonStdData ->nonStandardIdentifier.u.h221NonStandard;
  1227. if( srcNonStdData ->nonStandardIdentifier.choice ==
  1228. H225NonStandardIdentifier_h221NonStandard_chosen )
  1229. {
  1230. dstNonStdData ->bCountryCode = (BYTE)(h221NonStdData.t35CountryCode);
  1231. dstNonStdData ->bExtension = (BYTE)(h221NonStdData.t35Extension);
  1232. dstNonStdData ->wManufacturerCode = h221NonStdData.manufacturerCode;
  1233. }
  1234. dstNonStdData->sData.wOctetStringLength = (WORD)srcNonStdData->data.length;
  1235. dstNonStdData ->sData.pOctetString =
  1236. (BYTE *)new char[dstNonStdData ->sData.wOctetStringLength];
  1237. if( dstNonStdData -> sData.pOctetString == NULL )
  1238. {
  1239. return FALSE;
  1240. }
  1241. CopyMemory( (PVOID)dstNonStdData ->sData.pOctetString,
  1242. (PVOID)srcNonStdData ->data.value,
  1243. dstNonStdData ->sData.wOctetStringLength );
  1244. return TRUE;
  1245. }
  1246. BOOL
  1247. AliasAddrToAliasNames(
  1248. OUT PH323_ALIASNAMES *ppTarget,
  1249. IN Setup_UUIE_sourceAddress *pSource
  1250. )
  1251. {
  1252. Setup_UUIE_sourceAddress *CurrentNode = NULL;
  1253. WORD wCount = 0;
  1254. int indexI = 0;
  1255. HRESULT hr;
  1256. *ppTarget = NULL;
  1257. for( CurrentNode = pSource; CurrentNode; CurrentNode = CurrentNode->next )
  1258. {
  1259. wCount++;
  1260. }
  1261. if( wCount == 0 )
  1262. {
  1263. return TRUE;
  1264. }
  1265. *ppTarget = new H323_ALIASNAMES;
  1266. if (*ppTarget == NULL)
  1267. {
  1268. return FALSE;
  1269. }
  1270. ZeroMemory( *ppTarget, sizeof(H323_ALIASNAMES) );
  1271. (*ppTarget)->pItems = new H323_ALIASITEM[wCount];
  1272. if( (*ppTarget)->pItems == NULL )
  1273. {
  1274. goto cleanup;
  1275. }
  1276. for( CurrentNode = pSource; CurrentNode; CurrentNode = CurrentNode->next )
  1277. {
  1278. hr = AliasAddrToAliasItem( &((*ppTarget)->pItems[indexI]),
  1279. &(CurrentNode->value));
  1280. if( hr == E_OUTOFMEMORY )
  1281. {
  1282. WORD indexJ;
  1283. //Free everything that has been allocated so far...
  1284. for (indexJ = 0; indexJ < indexI; indexJ++)
  1285. {
  1286. delete (*ppTarget)->pItems[indexJ].pData;
  1287. }
  1288. goto cleanup;
  1289. }
  1290. else if( SUCCEEDED(hr) )
  1291. {
  1292. indexI++;
  1293. }
  1294. }
  1295. // any aliases?
  1296. if (indexI > 0)
  1297. {
  1298. // save number of aliases
  1299. (*ppTarget)->wCount = (WORD)indexI;
  1300. }
  1301. else
  1302. {
  1303. //free everything
  1304. delete (*ppTarget)->pItems;
  1305. delete (*ppTarget);
  1306. *ppTarget = NULL;
  1307. return FALSE;
  1308. }
  1309. return TRUE;
  1310. cleanup:
  1311. if( *ppTarget )
  1312. {
  1313. if( (*ppTarget)->pItems )
  1314. {
  1315. delete (*ppTarget)->pItems;
  1316. }
  1317. delete( *ppTarget );
  1318. *ppTarget = NULL;
  1319. }
  1320. return FALSE;
  1321. }
  1322. HRESULT
  1323. AliasAddrToAliasItem(
  1324. OUT PH323_ALIASITEM pAliasItem,
  1325. IN AliasAddress * pAliasAddr
  1326. )
  1327. {
  1328. WORD indexI;
  1329. if( pAliasItem == NULL )
  1330. {
  1331. return E_FAIL;
  1332. }
  1333. memset( (PVOID)pAliasItem, 0, sizeof(H323_ALIASITEM) );
  1334. switch( pAliasAddr->choice )
  1335. {
  1336. case h323_ID_chosen:
  1337. pAliasItem->wType = h323_ID_chosen;
  1338. if ((pAliasAddr->u.h323_ID.length != 0) &&
  1339. (pAliasAddr->u.h323_ID.value != NULL))
  1340. {
  1341. pAliasItem->wDataLength = (WORD)pAliasAddr->u.h323_ID.length;
  1342. pAliasItem->pData =
  1343. (LPWSTR)new char[(pAliasItem->wDataLength+1) * sizeof(WCHAR)];
  1344. if (pAliasItem->pData == NULL)
  1345. {
  1346. return E_OUTOFMEMORY;
  1347. }
  1348. CopyMemory( (PVOID)pAliasItem->pData,
  1349. (PVOID)pAliasAddr->u.h323_ID.value,
  1350. pAliasItem->wDataLength * sizeof(WCHAR) );
  1351. pAliasItem->pData[pAliasItem->wDataLength] = L'\0';
  1352. }
  1353. break;
  1354. case e164_chosen:
  1355. pAliasItem->wType = e164_chosen;
  1356. pAliasItem->wDataLength = (WORD)strlen(pAliasAddr->u.e164);
  1357. pAliasItem->pData =
  1358. (LPWSTR)new char[(pAliasItem->wDataLength + 1) * sizeof(WCHAR)];
  1359. if( pAliasItem->pData == NULL )
  1360. {
  1361. return E_OUTOFMEMORY;
  1362. }
  1363. //converting from byte to UNICODE
  1364. for (indexI = 0; indexI < pAliasItem->wDataLength; indexI++)
  1365. {
  1366. pAliasItem->pData[indexI] = (WCHAR)pAliasAddr->u.e164[indexI];
  1367. }
  1368. pAliasItem->pData[pAliasItem->wDataLength] = '\0';
  1369. break;
  1370. default:
  1371. return E_INVALIDARG;
  1372. } // switch
  1373. return S_OK;
  1374. }
  1375. void FreeFacilityASN(
  1376. IN Q931_FACILITY_ASN* pFacilityASN
  1377. )
  1378. {
  1379. //free non standard data
  1380. if( pFacilityASN->fNonStandardDataPresent != NULL )
  1381. {
  1382. delete pFacilityASN->nonStandardData.sData.pOctetString;
  1383. pFacilityASN->nonStandardData.sData.pOctetString =NULL;
  1384. }
  1385. if( pFacilityASN->pAlternativeAliasList != NULL )
  1386. {
  1387. FreeAliasNames(pFacilityASN->pAlternativeAliasList );
  1388. pFacilityASN->pAlternativeAliasList = NULL;
  1389. }
  1390. }
  1391. void FreeAlertingASN(
  1392. IN Q931_ALERTING_ASN* pAlertingASN
  1393. )
  1394. {
  1395. FreeProceedingASN( (Q931_CALL_PROCEEDING_ASN*)pAlertingASN );
  1396. }
  1397. void FreeProceedingASN(
  1398. IN Q931_CALL_PROCEEDING_ASN* pProceedingASN
  1399. )
  1400. {
  1401. //free non standard data
  1402. if( pProceedingASN->fNonStandardDataPresent == TRUE )
  1403. {
  1404. delete pProceedingASN->nonStandardData.sData.pOctetString;
  1405. pProceedingASN->nonStandardData.sData.pOctetString = NULL;
  1406. }
  1407. if( pProceedingASN->fFastStartPresent &&pProceedingASN->pFastStart )
  1408. {
  1409. FreeFastStart( pProceedingASN->pFastStart );
  1410. }
  1411. }
  1412. void FreeSetupASN(
  1413. IN Q931_SETUP_ASN* pSetupASN
  1414. )
  1415. {
  1416. if( pSetupASN == NULL )
  1417. {
  1418. return;
  1419. }
  1420. if( pSetupASN->pExtensionAliasItem != NULL )
  1421. {
  1422. if( pSetupASN->pExtensionAliasItem -> pData != NULL )
  1423. {
  1424. delete pSetupASN->pExtensionAliasItem -> pData;
  1425. }
  1426. delete pSetupASN->pExtensionAliasItem;
  1427. }
  1428. if( pSetupASN->pExtraAliasList != NULL )
  1429. {
  1430. FreeAliasNames(pSetupASN->pExtraAliasList);
  1431. pSetupASN->pExtraAliasList = NULL;
  1432. }
  1433. if( pSetupASN->pCalleeAliasList != NULL )
  1434. {
  1435. FreeAliasNames(pSetupASN->pCalleeAliasList);
  1436. pSetupASN->pCalleeAliasList = NULL;
  1437. }
  1438. if( pSetupASN->pCallerAliasList != NULL )
  1439. {
  1440. FreeAliasNames(pSetupASN->pCallerAliasList);
  1441. pSetupASN->pCallerAliasList = NULL;
  1442. }
  1443. if( pSetupASN->fNonStandardDataPresent == TRUE )
  1444. {
  1445. delete pSetupASN->nonStandardData.sData.pOctetString;
  1446. }
  1447. if( pSetupASN->EndpointType.pVendorInfo != NULL )
  1448. {
  1449. FreeVendorInfo( pSetupASN->EndpointType.pVendorInfo );
  1450. }
  1451. if( pSetupASN->fFastStartPresent == TRUE )
  1452. {
  1453. if( pSetupASN->pFastStart != NULL )
  1454. {
  1455. FreeFastStart( pSetupASN->pFastStart );
  1456. }
  1457. }
  1458. }
  1459. void FreeConnectASN(
  1460. IN Q931_CONNECT_ASN *pConnectASN
  1461. )
  1462. {
  1463. if( pConnectASN != NULL )
  1464. {
  1465. // Cleanup any dynamically allocated fields within SetupASN
  1466. if (pConnectASN->nonStandardData.sData.pOctetString)
  1467. {
  1468. delete pConnectASN->nonStandardData.sData.pOctetString;
  1469. pConnectASN->nonStandardData.sData.pOctetString = NULL;
  1470. }
  1471. if( pConnectASN->EndpointType.pVendorInfo != NULL )
  1472. {
  1473. FreeVendorInfo( pConnectASN->EndpointType.pVendorInfo );
  1474. }
  1475. if( pConnectASN->fFastStartPresent == TRUE )
  1476. {
  1477. if( pConnectASN->pFastStart != NULL )
  1478. {
  1479. FreeFastStart( pConnectASN->pFastStart );
  1480. }
  1481. }
  1482. }
  1483. }
  1484. void
  1485. FreeFastStart(
  1486. IN PH323_FASTSTART pFastStart
  1487. )
  1488. {
  1489. PH323_FASTSTART pTempFastStart;
  1490. while( pFastStart )
  1491. {
  1492. pTempFastStart = pFastStart -> next;
  1493. if(pFastStart -> value)
  1494. {
  1495. delete pFastStart -> value;
  1496. }
  1497. delete pFastStart;
  1498. pFastStart = pTempFastStart;
  1499. }
  1500. }
  1501. //FastStart is a plain linked list because it is exactly the same struct
  1502. //as defined by ASN.1. This allows to pass on the m_pFastStart member to
  1503. //the ASN encoder directly without any conversons
  1504. PH323_FASTSTART
  1505. CopyFastStart(
  1506. IN PSetup_UUIE_fastStart pSrcFastStart
  1507. )
  1508. {
  1509. PH323_FASTSTART pCurr, pHead = NULL, pTail = NULL;
  1510. H323DBG(( DEBUG_LEVEL_TRACE, "CopyFastStart entered." ));
  1511. while( pSrcFastStart )
  1512. {
  1513. pCurr = new H323_FASTSTART;
  1514. if( pCurr == NULL )
  1515. {
  1516. FreeFastStart( pHead );
  1517. return NULL;
  1518. }
  1519. pCurr -> next = NULL;
  1520. if( pHead == NULL )
  1521. {
  1522. pHead = pCurr;
  1523. }
  1524. else
  1525. {
  1526. pTail -> next = pCurr;
  1527. }
  1528. pTail = pCurr;
  1529. pCurr -> length = pSrcFastStart -> value.length;
  1530. pCurr -> value = (BYTE*)new char[pCurr -> length];
  1531. if( pCurr -> value == NULL )
  1532. {
  1533. FreeFastStart( pHead );
  1534. return NULL;
  1535. }
  1536. CopyMemory( (PVOID)pCurr -> value,
  1537. (PVOID)pSrcFastStart -> value.value,
  1538. pCurr -> length );
  1539. pSrcFastStart = pSrcFastStart->next;
  1540. }
  1541. H323DBG(( DEBUG_LEVEL_TRACE, "CopyFastStart exited." ));
  1542. return pHead;
  1543. }
  1544. void
  1545. FreeVendorInfo(
  1546. IN PH323_VENDORINFO pVendorInfo
  1547. )
  1548. {
  1549. H323DBG(( DEBUG_LEVEL_TRACE, "FreeVendorInfo entered." ));
  1550. if( pVendorInfo != NULL )
  1551. {
  1552. if( pVendorInfo ->pProductNumber != NULL )
  1553. {
  1554. if( pVendorInfo ->pProductNumber->pOctetString != NULL )
  1555. {
  1556. delete pVendorInfo ->pProductNumber->pOctetString;
  1557. }
  1558. delete pVendorInfo ->pProductNumber;
  1559. }
  1560. if( pVendorInfo ->pVersionNumber != NULL )
  1561. {
  1562. if( pVendorInfo ->pVersionNumber->pOctetString != NULL )
  1563. {
  1564. delete pVendorInfo ->pVersionNumber->pOctetString;
  1565. }
  1566. delete pVendorInfo ->pVersionNumber;
  1567. }
  1568. memset( (PVOID) pVendorInfo, 0, sizeof(H323_VENDORINFO) );
  1569. }
  1570. H323DBG(( DEBUG_LEVEL_TRACE, "FreeVendorInfo exited." ));
  1571. }
  1572. void
  1573. FreeAliasNames(
  1574. IN PH323_ALIASNAMES pSource
  1575. )
  1576. {
  1577. H323DBG(( DEBUG_LEVEL_TRACE, "FreeAliasNames entered." ));
  1578. if( pSource != NULL )
  1579. {
  1580. if( pSource->wCount != 0 )
  1581. {
  1582. // Free everything that has been allocated so far...
  1583. int indexI;
  1584. for( indexI = 0; indexI < pSource->wCount; indexI++ )
  1585. {
  1586. if( pSource->pItems[indexI].pPrefix != NULL )
  1587. {
  1588. H323DBG(( DEBUG_LEVEL_TRACE, "delete prefix:%d.", indexI ));
  1589. delete pSource->pItems[indexI].pPrefix;
  1590. }
  1591. if( pSource->pItems[indexI].pData != NULL )
  1592. {
  1593. H323DBG(( DEBUG_LEVEL_TRACE, "delete pdata:%d.", indexI ));
  1594. delete pSource->pItems[indexI].pData;
  1595. }
  1596. }
  1597. if( pSource->pItems != NULL )
  1598. {
  1599. H323DBG(( DEBUG_LEVEL_TRACE, "delete pitems." ));
  1600. delete pSource->pItems;
  1601. }
  1602. }
  1603. H323DBG(( DEBUG_LEVEL_TRACE, "outta loop." ));
  1604. delete pSource;
  1605. }
  1606. H323DBG(( DEBUG_LEVEL_TRACE, "FreeAliasNames exited." ));
  1607. }
  1608. void
  1609. FreeAliasItems(
  1610. IN PH323_ALIASNAMES pSource
  1611. )
  1612. {
  1613. H323DBG(( DEBUG_LEVEL_TRACE, "FreeAliasItems entered." ));
  1614. if( pSource != NULL )
  1615. {
  1616. if( pSource->wCount != 0 )
  1617. {
  1618. // Free everything that has been allocated so far...
  1619. int indexI;
  1620. for( indexI = 0; indexI < pSource->wCount; indexI++ )
  1621. {
  1622. if( pSource->pItems[indexI].pPrefix )
  1623. {
  1624. delete pSource->pItems[indexI].pPrefix;
  1625. }
  1626. if( pSource->pItems[indexI].pData )
  1627. {
  1628. delete pSource->pItems[indexI].pData;
  1629. }
  1630. }
  1631. if( pSource->pItems != NULL )
  1632. {
  1633. delete pSource->pItems;
  1634. pSource->pItems = NULL;
  1635. }
  1636. pSource->wCount = 0;
  1637. }
  1638. }
  1639. H323DBG(( DEBUG_LEVEL_TRACE, "FreeAliasItems exited." ));
  1640. }
  1641. void
  1642. SetupTPKTHeader(
  1643. OUT BYTE * pbTpktHeader,
  1644. IN DWORD dwLength
  1645. )
  1646. {
  1647. dwLength += TPKT_HEADER_SIZE;
  1648. // TPKT requires that the packet size fit in two bytes.
  1649. _ASSERTE( dwLength < (1L << 16));
  1650. pbTpktHeader[0] = TPKT_VERSION;
  1651. pbTpktHeader[1] = 0;
  1652. pbTpktHeader[2] = (BYTE)(dwLength >> 8);
  1653. pbTpktHeader[3] = (BYTE)dwLength;
  1654. }
  1655. int
  1656. GetTpktLength(
  1657. IN char * pTpktHeader
  1658. )
  1659. {
  1660. BYTE * pbTempPtr = (BYTE*)pTpktHeader;
  1661. return (pbTempPtr[2] << 8) + pbTempPtr[3];
  1662. }
  1663. BOOL
  1664. AddAliasItem(
  1665. IN OUT PH323_ALIASNAMES pAliasNames,
  1666. IN BYTE* pbAliasName,
  1667. IN DWORD dwAliasSize,
  1668. IN WORD wType
  1669. )
  1670. {
  1671. H323DBG(( DEBUG_LEVEL_TRACE, "AddAliasItem entered." ));
  1672. PH323_ALIASITEM pAliasItem;
  1673. PH323_ALIASITEM tempPtr;
  1674. tempPtr = (PH323_ALIASITEM)realloc( pAliasNames -> pItems,
  1675. sizeof(H323_ALIASITEM) * (pAliasNames->wCount+1) );
  1676. if( tempPtr == NULL )
  1677. {
  1678. //restore the old pointer in case enough memory was not available to
  1679. //expand the memory block
  1680. return FALSE;
  1681. }
  1682. pAliasNames -> pItems = tempPtr;
  1683. pAliasItem = &(pAliasNames -> pItems[pAliasNames->wCount]);
  1684. pAliasItem->pData = (WCHAR*)new char[dwAliasSize];
  1685. if( pAliasItem ->pData == NULL )
  1686. {
  1687. return FALSE;
  1688. }
  1689. pAliasNames->wCount++;
  1690. // transfer memory
  1691. CopyMemory((PVOID)pAliasItem ->pData,
  1692. pbAliasName,
  1693. dwAliasSize );
  1694. // complete alias
  1695. pAliasItem ->wType = wType;
  1696. pAliasItem ->wPrefixLength = 0;
  1697. pAliasItem ->pPrefix = NULL;
  1698. pAliasItem ->wDataLength = (WORD)wcslen(pAliasItem -> pData);
  1699. _ASSERTE( ((pAliasItem->wDataLength+1)*2) == (WORD)dwAliasSize );
  1700. H323DBG(( DEBUG_LEVEL_TRACE, "AddAliasItem exited." ));
  1701. return TRUE;
  1702. }
  1703. void
  1704. FreeAddressAliases(
  1705. IN PSetup_UUIE_destinationAddress pAddr
  1706. )
  1707. {
  1708. PSetup_UUIE_destinationAddress pTempAddr;
  1709. while( pAddr )
  1710. {
  1711. pTempAddr = pAddr -> next;
  1712. if( pAddr ->value.choice == h323_ID_chosen )
  1713. {
  1714. if( pAddr -> value.u.h323_ID.value )
  1715. {
  1716. delete pAddr -> value.u.h323_ID.value;
  1717. }
  1718. }
  1719. delete pAddr;
  1720. pAddr = pTempAddr;
  1721. }
  1722. }
  1723. void CopyTransportAddress(
  1724. OUT TransportAddress& transportAddress,
  1725. IN PH323_ADDR pCalleeAddr
  1726. )
  1727. {
  1728. DWORD dwAddr = pCalleeAddr->Addr.IP_Binary.dwAddr;
  1729. transportAddress.choice = ipAddress_chosen;
  1730. transportAddress.u.ipAddress.ip.length = 4;
  1731. transportAddress.u.ipAddress.port
  1732. = pCalleeAddr->Addr.IP_Binary.wPort;
  1733. *(DWORD*)transportAddress.u.ipAddress.ip.value =
  1734. htonl( pCalleeAddr->Addr.IP_Binary.dwAddr );
  1735. //ReverseAddressAndCopy( transportAddress.u.ipAddress.ip.value, dwAddr);
  1736. }
  1737. void
  1738. AddressReverseAndCopy(
  1739. OUT DWORD * pdwAddr,
  1740. IN BYTE * addrValue
  1741. )
  1742. {
  1743. BYTE *addr = (BYTE *)(pdwAddr);
  1744. addr[3] = addrValue[0];
  1745. addr[2] = addrValue[1];
  1746. addr[1] = addrValue[2];
  1747. addr[0] = addrValue[3];
  1748. }
  1749. Setup_UUIE_sourceAddress *
  1750. SetMsgAddressAlias(
  1751. IN PH323_ALIASNAMES pAliasNames
  1752. )
  1753. {
  1754. PH323_ALIASITEM pAliasItem;
  1755. Setup_UUIE_sourceAddress *addressAlias, *currHead = NULL;
  1756. WORD wCount;
  1757. int indexI;
  1758. for( wCount=0; wCount < pAliasNames->wCount; wCount++ )
  1759. {
  1760. addressAlias = new Setup_UUIE_sourceAddress;
  1761. if( addressAlias == NULL )
  1762. {
  1763. goto cleanup;
  1764. }
  1765. ZeroMemory( (PVOID)addressAlias, sizeof(Setup_UUIE_sourceAddress) );
  1766. addressAlias -> next = currHead;
  1767. currHead = addressAlias;
  1768. pAliasItem = &(pAliasNames->pItems[wCount]);
  1769. // then do the required memory copying.
  1770. if( pAliasItem -> wType == h323_ID_chosen )
  1771. {
  1772. addressAlias ->value.choice = h323_ID_chosen;
  1773. addressAlias ->value.u.h323_ID.length = pAliasItem -> wDataLength;
  1774. _ASSERTE( pAliasItem -> wDataLength );
  1775. addressAlias->value.u.h323_ID.value =
  1776. new WCHAR[pAliasItem -> wDataLength];
  1777. if( addressAlias->value.u.h323_ID.value == NULL )
  1778. {
  1779. goto cleanup;
  1780. }
  1781. CopyMemory((PVOID)addressAlias->value.u.h323_ID.value,
  1782. (PVOID)pAliasItem->pData,
  1783. pAliasItem -> wDataLength * sizeof(WCHAR) );
  1784. }
  1785. else if( pAliasItem -> wType == e164_chosen )
  1786. {
  1787. addressAlias ->value.choice = e164_chosen;
  1788. for( indexI =0; indexI < pAliasItem->wDataLength; indexI++ )
  1789. {
  1790. addressAlias->value.u.e164[indexI] = (BYTE)pAliasItem->pData[indexI];
  1791. }
  1792. addressAlias->value.u.e164[ pAliasItem->wDataLength ] = '\0';
  1793. }
  1794. else
  1795. {
  1796. continue;
  1797. }
  1798. }
  1799. return currHead;
  1800. cleanup:
  1801. FreeAddressAliases( (PSetup_UUIE_destinationAddress)currHead );
  1802. return NULL;
  1803. }
  1804. /*BOOL
  1805. SetSetupMsgAddressAliasWithPrefix(
  1806. PH323_ALIASITEM pCallerAlias,
  1807. Setup_UUIE_sourceAddress *addressAlias
  1808. )
  1809. {
  1810. UINT indexI;
  1811. addressAlias -> next = NULL;
  1812. UINT uPrefixLength = pCallerAlias -> wPrefixLength;
  1813. UINT uDataLength = pCallerAlias -> wDataLength;
  1814. if(pCallerAlias->wType == h323_ID_chosen)
  1815. {
  1816. addressAlias->value.choice = h323_ID_chosen;
  1817. addressAlias->value.u.h323_ID.length =
  1818. (WORD)(uPrefixLength + uDataLength);
  1819. if(!addressAlias->value.u.h323_ID.length)
  1820. {
  1821. addressAlias->value.u.h323_ID.value = NULL;
  1822. //no data to copy
  1823. return TRUE;
  1824. }
  1825. addressAlias->value.u.h323_ID.value =
  1826. (WCHAR*)new char[(uPrefixLength + uDataLength) * sizeof(WCHAR)];
  1827. if( addressAlias->value.u.h323_ID.value == NULL )
  1828. {
  1829. return FALSE;
  1830. }
  1831. addressAlias->value.u.h323_ID.length = (WORD)(uDataLength+uPrefixLength);
  1832. if( uPrefixLength != 0 )
  1833. {
  1834. CopyMemory((PVOID)addressAlias->value.u.h323_ID.value,
  1835. (PVOID)pCallerAlias->pPrefix,
  1836. uPrefixLength * sizeof(WCHAR) );
  1837. }
  1838. if( uDataLength != 0 )
  1839. {
  1840. CopyMemory((PVOID)&addressAlias->value.u.h323_ID.value[uPrefixLength],
  1841. (PVOID)pCallerAlias->pData,
  1842. uDataLength * sizeof(WCHAR) );
  1843. }
  1844. }
  1845. else if(pCallerAlias->wType == e164_chosen )
  1846. {
  1847. addressAlias->value.choice = e164_chosen;
  1848. for (indexI = 0; indexI < uPrefixLength; ++indexI)
  1849. {
  1850. addressAlias->value.u.e164[indexI] = (BYTE)(pCallerAlias->pPrefix[indexI]);
  1851. }
  1852. for (indexI = 0; indexI < uDataLength; ++indexI)
  1853. {
  1854. addressAlias->value.u.e164[uPrefixLength + indexI] = (BYTE)(pCallerAlias->pData[indexI]);
  1855. }
  1856. for (indexI = uDataLength + uPrefixLength; indexI < sizeof(addressAlias->value.u.e164); ++indexI)
  1857. {
  1858. addressAlias->value.u.e164[indexI] = 0;
  1859. }
  1860. }
  1861. else
  1862. {
  1863. //un identified alias type
  1864. return FALSE;
  1865. }
  1866. return TRUE;
  1867. }*/
  1868. void
  1869. CopyVendorInfo(
  1870. OUT VendorIdentifier* vendor
  1871. )
  1872. {
  1873. H323_VENDORINFO* pVendorInfo = g_pH323Line -> GetVendorInfo();
  1874. vendor->bit_mask = 0;
  1875. vendor->vendor.t35CountryCode = pVendorInfo ->bCountryCode;
  1876. vendor->vendor.t35Extension = pVendorInfo ->bExtension;
  1877. vendor->vendor.manufacturerCode = pVendorInfo ->wManufacturerCode;
  1878. if (pVendorInfo ->pProductNumber && pVendorInfo ->pProductNumber->pOctetString &&
  1879. pVendorInfo ->pProductNumber->wOctetStringLength)
  1880. {
  1881. vendor->bit_mask |= productId_present;
  1882. vendor->productId.length =
  1883. pVendorInfo ->pProductNumber->wOctetStringLength;
  1884. CopyMemory( (PVOID)&vendor->productId.value,
  1885. (PVOID)pVendorInfo ->pProductNumber->pOctetString,
  1886. pVendorInfo ->pProductNumber->wOctetStringLength);
  1887. }
  1888. if (pVendorInfo ->pVersionNumber && pVendorInfo ->pVersionNumber->pOctetString &&
  1889. pVendorInfo ->pVersionNumber->wOctetStringLength)
  1890. {
  1891. vendor->bit_mask |= versionId_present;
  1892. vendor->versionId.length =
  1893. pVendorInfo ->pVersionNumber->wOctetStringLength;
  1894. CopyMemory( (PVOID)&vendor->versionId.value,
  1895. (PVOID)pVendorInfo ->pVersionNumber->pOctetString,
  1896. pVendorInfo ->pVersionNumber->wOctetStringLength);
  1897. }
  1898. }
  1899. // check to see if entry is in list
  1900. BOOL
  1901. IsInList(
  1902. IN LIST_ENTRY * List,
  1903. IN LIST_ENTRY * Entry
  1904. )
  1905. {
  1906. LIST_ENTRY * Pos;
  1907. for( Pos = List -> Flink; Pos != List; Pos = Pos -> Flink )
  1908. {
  1909. if( Pos == Entry )
  1910. {
  1911. return TRUE;
  1912. }
  1913. }
  1914. return FALSE;
  1915. }
  1916. void WriteProtocolDiscriminator(
  1917. PBUFFERDESCR pBuf,
  1918. DWORD * dwPDULen
  1919. )
  1920. {
  1921. // space for the length byte
  1922. (*dwPDULen)++;
  1923. _ASSERTE( pBuf->dwLength > *dwPDULen );
  1924. *(PDTYPE *)pBuf->pbBuffer = Q931PDVALUE;
  1925. pBuf->pbBuffer += sizeof(PDTYPE);
  1926. }
  1927. //------------------------------------------------------------------------------
  1928. // Write a variable length Q931 call reference. See Q931 section 4.3.
  1929. //------------------------------------------------------------------------------
  1930. void
  1931. WriteCallReference(
  1932. PBUFFERDESCR pBuf,
  1933. WORD * pwCallReference,
  1934. DWORD * pdwPDULen
  1935. )
  1936. {
  1937. int indexI;
  1938. // space for the length byte
  1939. (*pdwPDULen) += 1+ sizeof(WORD);
  1940. _ASSERTE( pBuf->dwLength > *pdwPDULen );
  1941. // the length byte
  1942. *pBuf->pbBuffer = (BYTE)sizeof(WORD);
  1943. pBuf->pbBuffer++;
  1944. for (indexI = 0; indexI < sizeof(WORD); indexI++)
  1945. {
  1946. // Copy the value bytes to the buffer
  1947. *pBuf->pbBuffer =
  1948. (BYTE)(((*pwCallReference) >> ((sizeof(WORD) - 1 -indexI) * 8)) & 0xff);
  1949. pBuf->pbBuffer++;
  1950. }
  1951. }
  1952. void
  1953. FreeCallForwardParams(
  1954. IN PCALLFORWARDPARAMS pCallForwardParams
  1955. )
  1956. {
  1957. LPFORWARDADDRESS pForwardedAddress, pTemp;
  1958. if( pCallForwardParams != NULL )
  1959. {
  1960. if( pCallForwardParams->divertedToAlias.pData != NULL )
  1961. {
  1962. delete pCallForwardParams->divertedToAlias.pData;
  1963. }
  1964. pForwardedAddress = pCallForwardParams->pForwardedAddresses;
  1965. while( pForwardedAddress )
  1966. {
  1967. pTemp = pForwardedAddress->next;
  1968. FreeForwardAddress( pForwardedAddress );
  1969. pForwardedAddress = pTemp;
  1970. }
  1971. delete pCallForwardParams;
  1972. }
  1973. }
  1974. void
  1975. FreeForwardAddress(
  1976. IN LPFORWARDADDRESS pForwardAddress
  1977. )
  1978. {
  1979. if( pForwardAddress != NULL )
  1980. {
  1981. if( pForwardAddress->callerAlias.pData != NULL )
  1982. {
  1983. delete pForwardAddress->callerAlias.pData;
  1984. }
  1985. if( pForwardAddress->divertedToAlias.pData != NULL )
  1986. {
  1987. delete pForwardAddress->divertedToAlias.pData;
  1988. }
  1989. delete pForwardAddress;
  1990. }
  1991. }
  1992. //Replaces first alias item in the alias list with the alias address passed.
  1993. BOOL
  1994. MapAliasItem(
  1995. IN PH323_ALIASNAMES pCalleeAliasNames,
  1996. IN AliasAddress* pAliasAddress )
  1997. {
  1998. int iIndex;
  1999. _ASSERTE( pCalleeAliasNames && pCalleeAliasNames->pItems );
  2000. if( pCalleeAliasNames != NULL )
  2001. {
  2002. switch( pAliasAddress->choice )
  2003. {
  2004. case e164_chosen:
  2005. pCalleeAliasNames->pItems[0].wType = pAliasAddress->choice;
  2006. if( pCalleeAliasNames->pItems[0].pData != NULL )
  2007. {
  2008. delete pCalleeAliasNames->pItems[0].pData;
  2009. }
  2010. pCalleeAliasNames->pItems[0].wDataLength =
  2011. (WORD)strlen( pAliasAddress->u.e164 );
  2012. pCalleeAliasNames->pItems[0].pData =
  2013. new WCHAR[pCalleeAliasNames->pItems[0].wDataLength];
  2014. if( pCalleeAliasNames->pItems[0].pData == NULL )
  2015. {
  2016. return FALSE;
  2017. }
  2018. for( iIndex=0; iIndex < pCalleeAliasNames->pItems[0].wDataLength;
  2019. iIndex++ )
  2020. {
  2021. pCalleeAliasNames->pItems[0].pData[iIndex] =
  2022. pAliasAddress->u.e164[iIndex];
  2023. }
  2024. break;
  2025. case h323_ID_chosen:
  2026. pCalleeAliasNames->pItems[0].wType = pAliasAddress->choice;
  2027. if( pCalleeAliasNames->pItems[0].pData != NULL )
  2028. {
  2029. delete pCalleeAliasNames->pItems[0].pData;
  2030. }
  2031. pCalleeAliasNames->pItems[0].wDataLength =
  2032. (WORD)pAliasAddress->u.h323_ID.length;
  2033. pCalleeAliasNames->pItems[0].pData =
  2034. new WCHAR[pCalleeAliasNames->pItems[0].wDataLength];
  2035. if( pCalleeAliasNames->pItems[0].pData == NULL )
  2036. {
  2037. return FALSE;
  2038. }
  2039. CopyMemory( (PVOID)pCalleeAliasNames->pItems[0].pData,
  2040. (PVOID)pAliasAddress->u.h323_ID.value,
  2041. pCalleeAliasNames->pItems[0].wDataLength );
  2042. break;
  2043. }
  2044. }
  2045. return TRUE;
  2046. }
  2047. //
  2048. //creates a new alias list and copies the first alias item from the given list.
  2049. //
  2050. PH323_ALIASNAMES
  2051. DuplicateAliasName(
  2052. PH323_ALIASNAMES pSrcAliasNames
  2053. )
  2054. {
  2055. PH323_ALIASNAMES pDestAliasNames = new H323_ALIASNAMES;
  2056. if( pDestAliasNames == NULL )
  2057. {
  2058. return NULL;
  2059. }
  2060. ZeroMemory( pDestAliasNames, sizeof(H323_ALIASNAMES) );
  2061. if( !AddAliasItem(
  2062. pDestAliasNames,
  2063. pSrcAliasNames->pItems[0].pData,
  2064. pSrcAliasNames->pItems[0].wType ) )
  2065. {
  2066. delete pDestAliasNames;
  2067. return NULL;
  2068. }
  2069. return pDestAliasNames;
  2070. }