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.

929 lines
27 KiB

  1. /****************************************************************************
  2. *
  3. * $Archive: S:\sturgeon\src\q931\vcs\utils.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-1996 Intel Corporation.
  12. *
  13. * $Revision: 1.33 $
  14. * $Date: 23 Jan 1997 20:42:54 $
  15. * $Author: SBELL1 $
  16. *
  17. * Deliverable:
  18. *
  19. * Abstract:
  20. *
  21. *
  22. * Notes:
  23. *
  24. ***************************************************************************/
  25. #pragma warning ( disable : 4115 4201 4214 4514 )
  26. #include "precomp.h"
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include <string.h>
  31. #include "q931.h"
  32. #include "isrg.h"
  33. #include "utils.h"
  34. #include "linkapi.h"
  35. //====================================================================================
  36. //===============/=====================================================================
  37. void
  38. Q931MakePhysicalID(DWORD *pdwPhysicalID)
  39. {
  40. *pdwPhysicalID = INVALID_PHYS_ID;
  41. }
  42. //====================================================================================
  43. //====================================================================================
  44. WORD
  45. ADDRToInetPort(CC_ADDR *pAddr)
  46. {
  47. WORD HostPort = 0;
  48. switch (pAddr->nAddrType)
  49. {
  50. case CC_IP_DOMAIN_NAME:
  51. HostPort = pAddr->Addr.IP_DomainName.wPort;
  52. break;
  53. case CC_IP_DOT:
  54. HostPort = pAddr->Addr.IP_Dot.wPort;
  55. break;
  56. case CC_IP_BINARY:
  57. HostPort = pAddr->Addr.IP_Binary.wPort;
  58. break;
  59. }
  60. return htons(HostPort);
  61. }
  62. //====================================================================================
  63. //====================================================================================
  64. DWORD
  65. ADDRToInetAddr(CC_ADDR *pAddr)
  66. {
  67. struct hostent *pHostEnt;
  68. switch (pAddr->nAddrType)
  69. {
  70. case CC_IP_DOMAIN_NAME:
  71. {
  72. char buf[sizeof(pAddr->Addr.IP_DomainName.cAddr) / sizeof(WCHAR)];
  73. WideCharToMultiByte(CP_ACP, 0, pAddr->Addr.IP_DomainName.cAddr, -1, buf, sizeof(buf), NULL, NULL);
  74. pHostEnt = gethostbyname(buf);
  75. }
  76. if (pHostEnt == NULL || pHostEnt->h_addr_list == NULL)
  77. {
  78. return htonl(0L);
  79. }
  80. return *((DWORD *)pHostEnt->h_addr_list[0]);
  81. case CC_IP_DOT:
  82. {
  83. char buf[sizeof(pAddr->Addr.IP_Dot.cAddr) / sizeof(WCHAR)];
  84. WideCharToMultiByte(CP_ACP, 0, pAddr->Addr.IP_Dot.cAddr, -1, buf, sizeof(buf), NULL, NULL);
  85. return inet_addr(buf);
  86. }
  87. case CC_IP_BINARY:
  88. return htonl(pAddr->Addr.IP_Binary.dwAddr);
  89. }
  90. return 0L;
  91. }
  92. //====================================================================================
  93. // If Port 0 is passed in, use default listen port.
  94. //====================================================================================
  95. void
  96. SetDefaultPort(CC_ADDR *pAddr)
  97. {
  98. switch (pAddr->nAddrType)
  99. {
  100. case CC_IP_DOMAIN_NAME:
  101. if (pAddr->Addr.IP_DomainName.wPort == 0)
  102. {
  103. pAddr->Addr.IP_DomainName.wPort = CC_H323_HOST_CALL;
  104. }
  105. return;
  106. case CC_IP_DOT:
  107. if (pAddr->Addr.IP_Dot.wPort == 0)
  108. {
  109. pAddr->Addr.IP_Dot.wPort = CC_H323_HOST_CALL;
  110. }
  111. return;
  112. case CC_IP_BINARY:
  113. if (pAddr->Addr.IP_Binary.wPort == 0)
  114. {
  115. pAddr->Addr.IP_Binary.wPort = CC_H323_HOST_CALL;
  116. }
  117. return;
  118. }
  119. return;
  120. }
  121. //====================================================================================
  122. //====================================================================================
  123. BOOL
  124. MakeBinaryADDR(CC_ADDR *pInAddr, CC_ADDR *pOutAddr)
  125. {
  126. if (pOutAddr == NULL)
  127. {
  128. return FALSE;
  129. }
  130. memset(pOutAddr, 0, sizeof(CC_ADDR));
  131. if (pInAddr == NULL)
  132. {
  133. return FALSE;
  134. }
  135. pOutAddr->nAddrType = CC_IP_BINARY;
  136. pOutAddr->bMulticast = pInAddr->bMulticast;
  137. switch (pInAddr->nAddrType)
  138. {
  139. case CC_IP_DOMAIN_NAME:
  140. {
  141. struct hostent *pHostEnt;
  142. DWORD net_addr;
  143. {
  144. char buf[sizeof(pInAddr->Addr.IP_DomainName.cAddr) / sizeof(WCHAR)];
  145. WideCharToMultiByte(CP_ACP, 0, pInAddr->Addr.IP_DomainName.cAddr, -1, buf, sizeof(buf), NULL, NULL);
  146. if (buf[0] == '\0')
  147. {
  148. return FALSE;
  149. }
  150. pHostEnt = gethostbyname(buf);
  151. }
  152. if (pHostEnt == NULL || pHostEnt->h_addr_list == NULL)
  153. {
  154. return FALSE;
  155. }
  156. net_addr = *((DWORD *)pHostEnt->h_addr_list[0]);
  157. pOutAddr->Addr.IP_Binary.wPort = pInAddr->Addr.IP_DomainName.wPort;
  158. pOutAddr->Addr.IP_Binary.dwAddr = ntohl(net_addr);
  159. }
  160. break;
  161. case CC_IP_DOT:
  162. {
  163. char buf[sizeof(pInAddr->Addr.IP_Dot.cAddr) / sizeof(WCHAR)];
  164. WideCharToMultiByte(CP_ACP, 0, pInAddr->Addr.IP_Dot.cAddr, -1, buf, sizeof(buf), NULL, NULL);
  165. if (buf[0] == '\0')
  166. {
  167. return FALSE;
  168. }
  169. pOutAddr->Addr.IP_Binary.dwAddr = ntohl(inet_addr(buf));
  170. }
  171. pOutAddr->Addr.IP_Binary.wPort = pInAddr->Addr.IP_Dot.wPort;
  172. break;
  173. default:
  174. pOutAddr->Addr.IP_Binary.wPort = pInAddr->Addr.IP_Binary.wPort;
  175. pOutAddr->Addr.IP_Binary.dwAddr = pInAddr->Addr.IP_Binary.dwAddr;
  176. break;
  177. }
  178. return TRUE;
  179. }
  180. //====================================================================================
  181. //====================================================================================
  182. void
  183. GetDomainAddr(CC_ADDR *pAddr)
  184. {
  185. WORD wTemp;
  186. char szHostName[80];
  187. if (gethostname(szHostName, sizeof(szHostName)) != SOCKET_ERROR)
  188. {
  189. wTemp = pAddr->Addr.IP_Binary.wPort;
  190. pAddr->nAddrType = CC_IP_DOMAIN_NAME;
  191. MultiByteToWideChar(CP_ACP, 0, szHostName, -1,
  192. pAddr->Addr.IP_DomainName.cAddr,
  193. sizeof(pAddr->Addr.IP_DomainName.cAddr) /
  194. sizeof(pAddr->Addr.IP_DomainName.cAddr[0]));
  195. pAddr->Addr.IP_DomainName.wPort = wTemp;
  196. }
  197. }
  198. //====================================================================================
  199. //====================================================================================
  200. CS_STATUS
  201. Q931ValidateAddr(PCC_ADDR pAddr)
  202. {
  203. if (pAddr == NULL)
  204. {
  205. return CS_OK;
  206. }
  207. if ((pAddr->nAddrType != CC_IP_DOMAIN_NAME) &&
  208. (pAddr->nAddrType != CC_IP_DOT) &&
  209. (pAddr->nAddrType != CC_IP_BINARY))
  210. {
  211. return CS_BAD_PARAM;
  212. }
  213. if (pAddr->nAddrType == CC_IP_DOT)
  214. {
  215. WCHAR *p = pAddr->Addr.IP_Dot.cAddr;
  216. while (*p)
  217. {
  218. if (wcschr((const WCHAR *)CC_ODOTTO_CHARS, *p) == NULL)
  219. {
  220. return CS_BAD_PARAM;
  221. }
  222. p++;
  223. }
  224. }
  225. if (pAddr->bMulticast == TRUE)
  226. {
  227. return CS_BAD_PARAM;
  228. }
  229. return CS_OK;
  230. }
  231. //====================================================================================
  232. //====================================================================================
  233. CS_STATUS
  234. Q931ValidateAliasItem(PCC_ALIASITEM pSource)
  235. {
  236. register unsigned int y;
  237. if (pSource)
  238. {
  239. if ((pSource->pData == NULL) || (pSource->wDataLength == 0))
  240. {
  241. return CS_BAD_PARAM;
  242. }
  243. if (pSource->pPrefix != NULL)
  244. {
  245. if (pSource->wPrefixLength == 0)
  246. {
  247. return CS_BAD_PARAM;
  248. }
  249. }
  250. else if (pSource->wPrefixLength != 0)
  251. {
  252. return CS_BAD_PARAM;
  253. }
  254. switch (pSource->wType)
  255. {
  256. case CC_ALIAS_H323_ID:
  257. if ((pSource->wDataLength + pSource->wPrefixLength) > CC_ALIAS_MAX_H323_ID)
  258. {
  259. return CS_BAD_PARAM;
  260. }
  261. break;
  262. case CC_ALIAS_H323_PHONE:
  263. if ((pSource->wDataLength + pSource->wPrefixLength +1) > CC_ALIAS_MAX_H323_PHONE)
  264. {
  265. return CS_BAD_PARAM;
  266. }
  267. for (y = 0; y < pSource->wDataLength; ++y)
  268. {
  269. if (wcschr((const WCHAR *)CC_ALIAS_H323_PHONE_CHARS, pSource->pData[y]) == NULL)
  270. {
  271. return CS_BAD_PARAM;
  272. }
  273. }
  274. if (pSource->pPrefix != NULL)
  275. {
  276. for (y = 0; y < pSource->wPrefixLength; ++y)
  277. {
  278. if (wcschr((const WCHAR *)CC_ALIAS_H323_PHONE_CHARS, pSource->pPrefix[y]) == NULL)
  279. {
  280. return CS_BAD_PARAM;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. return CS_OK;
  287. }
  288. //====================================================================================
  289. //====================================================================================
  290. CS_STATUS
  291. Q931CopyAliasItem(PCC_ALIASITEM *ppTarget, PCC_ALIASITEM pSource)
  292. {
  293. PCC_ALIASITEM pNewItem = NULL;
  294. if (ppTarget == NULL)
  295. {
  296. return CS_BAD_PARAM;
  297. }
  298. *ppTarget = NULL;
  299. if (pSource == NULL)
  300. {
  301. return CS_OK;
  302. }
  303. pNewItem = (PCC_ALIASITEM)MemAlloc(sizeof(CC_ALIASITEM));
  304. if (pNewItem == NULL)
  305. {
  306. return CS_NO_MEMORY;
  307. }
  308. pNewItem->wType = pSource->wType;
  309. if ((pSource->wPrefixLength != 0) && (pSource->pPrefix != NULL))
  310. {
  311. pNewItem->wPrefixLength = pSource->wPrefixLength;
  312. pNewItem->pPrefix = (LPWSTR)MemAlloc(pSource->wPrefixLength * sizeof(pNewItem->pPrefix[0]));
  313. if (pNewItem->pPrefix == NULL)
  314. {
  315. MemFree(pNewItem);
  316. return CS_NO_MEMORY;
  317. }
  318. memcpy(pNewItem->pPrefix, pSource->pPrefix, pSource->wPrefixLength * sizeof(WCHAR));
  319. }
  320. else
  321. {
  322. pNewItem->wPrefixLength = 0;
  323. pNewItem->pPrefix = NULL;
  324. }
  325. if ((pSource->wDataLength != 0) && (pSource->pData != NULL))
  326. {
  327. pNewItem->wDataLength = pSource->wDataLength;
  328. pNewItem->pData = (LPWSTR)MemAlloc(pSource->wDataLength * sizeof(pNewItem->pData[0]));
  329. if (pNewItem->pData == NULL)
  330. {
  331. if (pNewItem->pPrefix)
  332. {
  333. MemFree(pNewItem->pPrefix);
  334. }
  335. MemFree(pNewItem);
  336. return CS_NO_MEMORY;
  337. }
  338. memcpy(pNewItem->pData, pSource->pData, pSource->wDataLength * sizeof(WCHAR));
  339. }
  340. else
  341. {
  342. pNewItem->wDataLength = 0;
  343. pNewItem->pData = NULL;
  344. }
  345. *ppTarget = pNewItem;
  346. return CS_OK;
  347. }
  348. //====================================================================================
  349. //====================================================================================
  350. CS_STATUS
  351. Q931FreeAliasItem(PCC_ALIASITEM pSource)
  352. {
  353. if (pSource)
  354. {
  355. if ((pSource->pPrefix) != NULL)
  356. {
  357. MemFree(pSource->pPrefix);
  358. }
  359. if ((pSource->pData) != NULL)
  360. {
  361. MemFree(pSource->pData);
  362. }
  363. MemFree(pSource);
  364. }
  365. return CS_OK;
  366. }
  367. //====================================================================================
  368. //====================================================================================
  369. CS_STATUS
  370. Q931ValidateAliasNames(PCC_ALIASNAMES pSource)
  371. {
  372. CS_STATUS TempResult = CS_OK;
  373. WORD x;
  374. if (pSource)
  375. {
  376. for (x = 0; x < pSource->wCount; x++)
  377. {
  378. TempResult = Q931ValidateAliasItem(&(pSource->pItems[x]));
  379. if (TempResult != CS_OK)
  380. {
  381. return TempResult;
  382. }
  383. }
  384. }
  385. return CS_OK;
  386. }
  387. //====================================================================================
  388. //====================================================================================
  389. CS_STATUS
  390. Q931CopyAliasNames(PCC_ALIASNAMES *ppTarget, PCC_ALIASNAMES pSource)
  391. {
  392. if (ppTarget == NULL)
  393. {
  394. return CS_BAD_PARAM;
  395. }
  396. *ppTarget = NULL;
  397. if (pSource == NULL)
  398. {
  399. return CS_OK;
  400. }
  401. if (pSource->wCount)
  402. {
  403. WORD x;
  404. *ppTarget = (PCC_ALIASNAMES)MemAlloc(sizeof(CC_ALIASNAMES));
  405. if (*ppTarget == NULL)
  406. {
  407. return CS_NO_MEMORY;
  408. }
  409. (*ppTarget)->pItems = (PCC_ALIASITEM)MemAlloc(pSource->wCount *
  410. sizeof(CC_ALIASITEM));
  411. if ((*ppTarget)->pItems == NULL)
  412. {
  413. MemFree(*ppTarget);
  414. *ppTarget = NULL;
  415. return CS_NO_MEMORY;
  416. }
  417. (*ppTarget)->wCount = pSource->wCount;
  418. {
  419. PCC_ALIASITEM p = (*ppTarget)->pItems;
  420. for (x = 0; x < pSource->wCount; x++)
  421. {
  422. p[x].wType = pSource->pItems[x].wType;
  423. if ((pSource->pItems[x].wPrefixLength != 0) &&
  424. (pSource->pItems[x].pPrefix != NULL))
  425. {
  426. p[x].wPrefixLength = pSource->pItems[x].wPrefixLength;
  427. p[x].pPrefix = (LPWSTR)MemAlloc(pSource->pItems[x].wPrefixLength * sizeof(p[x].pPrefix[0]));
  428. if (p[x].pPrefix == NULL)
  429. {
  430. // Free everything that has been allocated so far...
  431. int y;
  432. for (y = 0; y < x; y++)
  433. {
  434. if (p[y].pPrefix)
  435. {
  436. MemFree(p[y].pPrefix);
  437. }
  438. if (p[y].pData)
  439. {
  440. MemFree(p[y].pData);
  441. }
  442. }
  443. MemFree(p);
  444. MemFree(*ppTarget);
  445. *ppTarget = NULL;
  446. return CS_NO_MEMORY;
  447. }
  448. memcpy(p[x].pPrefix, pSource->pItems[x].pPrefix,
  449. pSource->pItems[x].wPrefixLength * sizeof(WCHAR));
  450. }
  451. else
  452. {
  453. p[x].wPrefixLength = 0;
  454. p[x].pPrefix = NULL;
  455. }
  456. if ((pSource->pItems[x].wDataLength != 0) &&
  457. (pSource->pItems[x].pData != NULL))
  458. {
  459. p[x].wDataLength = pSource->pItems[x].wDataLength;
  460. p[x].pData = (LPWSTR)MemAlloc(pSource->pItems[x].wDataLength * sizeof(p[x].pData[0]));
  461. if (p[x].pData == NULL)
  462. {
  463. // Free everything that has been allocated so far...
  464. int y;
  465. if (p[x].pPrefix)
  466. {
  467. MemFree(p[x].pPrefix);
  468. }
  469. for (y = 0; y < x; y++)
  470. {
  471. if (p[y].pPrefix)
  472. {
  473. MemFree(p[y].pPrefix);
  474. }
  475. if (p[y].pData)
  476. {
  477. MemFree(p[y].pData);
  478. }
  479. }
  480. MemFree(p);
  481. MemFree(*ppTarget);
  482. *ppTarget = NULL;
  483. return CS_NO_MEMORY;
  484. }
  485. memcpy(p[x].pData, pSource->pItems[x].pData,
  486. pSource->pItems[x].wDataLength * sizeof(WCHAR));
  487. }
  488. else
  489. {
  490. p[x].wDataLength = 0;
  491. p[x].pData = NULL;
  492. }
  493. }
  494. }
  495. }
  496. return CS_OK;
  497. }
  498. //====================================================================================
  499. //====================================================================================
  500. CS_STATUS
  501. Q931FreeAliasNames(PCC_ALIASNAMES pSource)
  502. {
  503. if (pSource && (pSource->wCount))
  504. {
  505. // Free everything that has been allocated so far...
  506. int x;
  507. for (x = 0; x < pSource->wCount; x++)
  508. {
  509. if ((pSource->pItems[x].pPrefix) != NULL)
  510. {
  511. MemFree(pSource->pItems[x].pPrefix);
  512. }
  513. if ((pSource->pItems[x].pData) != NULL)
  514. {
  515. MemFree(pSource->pItems[x].pData);
  516. }
  517. }
  518. if (pSource->pItems != NULL)
  519. {
  520. MemFree(pSource->pItems);
  521. }
  522. if (pSource != NULL)
  523. {
  524. MemFree(pSource);
  525. }
  526. }
  527. return CS_OK;
  528. }
  529. //====================================================================================
  530. //====================================================================================
  531. CS_STATUS
  532. Q931ValidateDisplay(LPWSTR pszDisplay)
  533. {
  534. if (pszDisplay == NULL)
  535. {
  536. return CS_OK;
  537. }
  538. if (wcslen(pszDisplay) > CC_MAX_DISPLAY_LENGTH)
  539. {
  540. return CS_BAD_PARAM;
  541. }
  542. #if 0 // turn this on to validate display field against IA5 characters...
  543. while (*pszDisplay)
  544. {
  545. if (wcschr(CC_UNICODE_IA5_CHARS, *pszDisplay) == NULL)
  546. {
  547. return CS_BAD_PARAM;
  548. }
  549. pszDisplay++;
  550. }
  551. #endif
  552. return CS_OK;
  553. }
  554. //====================================================================================
  555. //====================================================================================
  556. CS_STATUS
  557. Q931ValidatePartyNumber(LPWSTR pszPartyNumber)
  558. {
  559. if (pszPartyNumber == NULL)
  560. {
  561. return CS_OK;
  562. }
  563. if (wcslen(pszPartyNumber) > CC_MAX_PARTY_NUMBER_LEN)
  564. {
  565. return CS_BAD_PARAM;
  566. }
  567. #if 0 // turn this on to validate party number field against IA5 characters...
  568. while (*pszPartyNumber)
  569. {
  570. if (wcschr(CC_UNICODE_IA5_CHARS, *pszPartyNumber) == NULL)
  571. {
  572. return CS_BAD_PARAM;
  573. }
  574. pszPartyNumber++;
  575. }
  576. #endif
  577. return CS_OK;
  578. }
  579. //====================================================================================
  580. //====================================================================================
  581. CS_STATUS
  582. Q931CopyDisplay(LPWSTR *ppDest, LPWSTR pSource)
  583. {
  584. if (ppDest == NULL)
  585. {
  586. ASSERT(FALSE);
  587. return CS_BAD_PARAM;
  588. }
  589. if (pSource == NULL)
  590. {
  591. *ppDest = NULL;
  592. return CS_OK;
  593. }
  594. *ppDest = (LPWSTR)MemAlloc((wcslen(pSource) + 1) * sizeof(WCHAR));
  595. if (*ppDest == NULL)
  596. {
  597. return CS_NO_MEMORY;
  598. }
  599. wcscpy(*ppDest, pSource);
  600. return CS_OK;
  601. }
  602. //====================================================================================
  603. //====================================================================================
  604. CS_STATUS
  605. Q931FreeDisplay(LPWSTR pszDisplay)
  606. {
  607. if (pszDisplay == NULL)
  608. {
  609. return CS_OK;
  610. }
  611. MemFree(pszDisplay);
  612. return CS_OK;
  613. }
  614. //====================================================================================
  615. //====================================================================================
  616. CS_STATUS
  617. Q931ValidateVendorInfo(PCC_VENDORINFO pVendorInfo)
  618. {
  619. if (pVendorInfo == NULL)
  620. {
  621. return CS_OK;
  622. }
  623. if (pVendorInfo->pProductNumber)
  624. {
  625. if (pVendorInfo->pProductNumber->wOctetStringLength)
  626. {
  627. if (pVendorInfo->pProductNumber->wOctetStringLength > CC_MAX_PRODUCT_LENGTH)
  628. {
  629. return CS_BAD_PARAM;
  630. }
  631. if (pVendorInfo->pProductNumber->pOctetString == NULL)
  632. {
  633. return CS_BAD_PARAM;
  634. }
  635. }
  636. else if (pVendorInfo->pProductNumber->pOctetString)
  637. {
  638. return CS_BAD_PARAM;
  639. }
  640. }
  641. if (pVendorInfo->pVersionNumber)
  642. {
  643. if (pVendorInfo->pVersionNumber->wOctetStringLength)
  644. {
  645. if (pVendorInfo->pVersionNumber->wOctetStringLength > CC_MAX_VERSION_LENGTH)
  646. {
  647. return CS_BAD_PARAM;
  648. }
  649. if (pVendorInfo->pVersionNumber->pOctetString == NULL)
  650. {
  651. return CS_BAD_PARAM;
  652. }
  653. }
  654. else if (pVendorInfo->pVersionNumber->pOctetString)
  655. {
  656. return CS_BAD_PARAM;
  657. }
  658. }
  659. return CS_OK;
  660. }
  661. //====================================================================================
  662. //====================================================================================
  663. CS_STATUS
  664. Q931CopyVendorInfo(PCC_VENDORINFO *ppDest, PCC_VENDORINFO pSource)
  665. {
  666. if (ppDest == NULL)
  667. {
  668. ASSERT(FALSE);
  669. return CS_BAD_PARAM;
  670. }
  671. if (pSource == NULL)
  672. {
  673. *ppDest = NULL;
  674. return CS_OK;
  675. }
  676. *ppDest = (PCC_VENDORINFO)MemAlloc(sizeof(CC_VENDORINFO));
  677. if (*ppDest == NULL)
  678. {
  679. return CS_NO_MEMORY;
  680. }
  681. memset(*ppDest, 0, sizeof(CC_VENDORINFO));
  682. (*ppDest)->bCountryCode = pSource->bCountryCode;
  683. (*ppDest)->bExtension = pSource->bExtension;
  684. (*ppDest)->wManufacturerCode = pSource->wManufacturerCode;
  685. if ((pSource->pProductNumber == NULL) ||
  686. (pSource->pProductNumber->pOctetString == NULL) ||
  687. (pSource->pProductNumber->wOctetStringLength == 0))
  688. {
  689. (*ppDest)->pProductNumber = NULL;
  690. }
  691. else
  692. {
  693. (*ppDest)->pProductNumber = (PCC_OCTETSTRING)MemAlloc(sizeof(CC_OCTETSTRING));
  694. if ((*ppDest)->pProductNumber == NULL)
  695. {
  696. Q931FreeVendorInfo(*ppDest);
  697. *ppDest = NULL;
  698. return CS_NO_MEMORY;
  699. }
  700. memset((*ppDest)->pProductNumber, 0, sizeof(CC_OCTETSTRING));
  701. (*ppDest)->pProductNumber->pOctetString =
  702. (BYTE *)MemAlloc(pSource->pProductNumber->wOctetStringLength);
  703. if ((*ppDest)->pProductNumber->pOctetString == NULL)
  704. {
  705. Q931FreeVendorInfo(*ppDest);
  706. *ppDest = NULL;
  707. return CS_NO_MEMORY;
  708. }
  709. (*ppDest)->pProductNumber->wOctetStringLength =
  710. pSource->pProductNumber->wOctetStringLength;
  711. memcpy((*ppDest)->pProductNumber->pOctetString,
  712. pSource->pProductNumber->pOctetString,
  713. pSource->pProductNumber->wOctetStringLength);
  714. }
  715. if ((pSource->pVersionNumber == NULL) ||
  716. (pSource->pVersionNumber->pOctetString == NULL) ||
  717. (pSource->pVersionNumber->wOctetStringLength == 0))
  718. {
  719. (*ppDest)->pVersionNumber = NULL;
  720. }
  721. else
  722. {
  723. (*ppDest)->pVersionNumber = (PCC_OCTETSTRING)MemAlloc(sizeof(CC_OCTETSTRING));
  724. if ((*ppDest)->pVersionNumber == NULL)
  725. {
  726. Q931FreeVendorInfo(*ppDest);
  727. *ppDest = NULL;
  728. return CS_NO_MEMORY;
  729. }
  730. memset((*ppDest)->pVersionNumber, 0, sizeof(CC_OCTETSTRING));
  731. (*ppDest)->pVersionNumber->pOctetString =
  732. (BYTE *)MemAlloc(pSource->pVersionNumber->wOctetStringLength);
  733. if ((*ppDest)->pVersionNumber->pOctetString == NULL)
  734. {
  735. Q931FreeVendorInfo(*ppDest);
  736. *ppDest = NULL;
  737. return CS_NO_MEMORY;
  738. }
  739. (*ppDest)->pVersionNumber->wOctetStringLength =
  740. pSource->pVersionNumber->wOctetStringLength;
  741. memcpy((*ppDest)->pVersionNumber->pOctetString,
  742. pSource->pVersionNumber->pOctetString,
  743. pSource->pVersionNumber->wOctetStringLength);
  744. }
  745. return CS_OK;
  746. }
  747. //====================================================================================
  748. //====================================================================================
  749. CS_STATUS
  750. Q931FreeVendorInfo(PCC_VENDORINFO pVendorInfo)
  751. {
  752. if (pVendorInfo == NULL)
  753. {
  754. return CS_OK;
  755. }
  756. if (pVendorInfo->pProductNumber != NULL)
  757. {
  758. if (pVendorInfo->pProductNumber->pOctetString != NULL)
  759. {
  760. MemFree(pVendorInfo->pProductNumber->pOctetString);
  761. }
  762. MemFree(pVendorInfo->pProductNumber);
  763. }
  764. if (pVendorInfo->pVersionNumber != NULL)
  765. {
  766. if (pVendorInfo->pVersionNumber->pOctetString != NULL)
  767. {
  768. MemFree(pVendorInfo->pVersionNumber->pOctetString);
  769. }
  770. MemFree(pVendorInfo->pVersionNumber);
  771. }
  772. MemFree(pVendorInfo);
  773. return CS_OK;
  774. }
  775. //====================================================================================
  776. //====================================================================================
  777. CS_STATUS
  778. Q931ValidateNonStandardData(PCC_NONSTANDARDDATA pNonStandardData)
  779. {
  780. if (pNonStandardData)
  781. {
  782. if ((pNonStandardData->sData.pOctetString == NULL) ||
  783. (pNonStandardData->sData.wOctetStringLength == 0))
  784. {
  785. return CS_BAD_PARAM;
  786. }
  787. }
  788. return CS_OK;
  789. }
  790. //====================================================================================
  791. //====================================================================================
  792. CS_STATUS
  793. Q931CopyNonStandardData(PCC_NONSTANDARDDATA *ppDest, PCC_NONSTANDARDDATA pSource)
  794. {
  795. if (ppDest == NULL)
  796. {
  797. ASSERT(FALSE);
  798. return CS_BAD_PARAM;
  799. }
  800. if (pSource == NULL)
  801. {
  802. *ppDest = NULL;
  803. return CS_OK;
  804. }
  805. *ppDest = (PCC_NONSTANDARDDATA)MemAlloc(sizeof(CC_NONSTANDARDDATA));
  806. if (*ppDest == NULL)
  807. {
  808. return CS_NO_MEMORY;
  809. }
  810. (*ppDest)->bCountryCode = pSource->bCountryCode;
  811. (*ppDest)->bExtension = pSource->bExtension;
  812. (*ppDest)->wManufacturerCode = pSource->wManufacturerCode;
  813. (*ppDest)->sData.wOctetStringLength = pSource->sData.wOctetStringLength;
  814. if (pSource->sData.pOctetString == NULL)
  815. {
  816. (*ppDest)->sData.pOctetString = NULL;
  817. }
  818. else
  819. {
  820. (*ppDest)->sData.pOctetString = (void *)MemAlloc(pSource->sData.wOctetStringLength);
  821. if ((*ppDest)->sData.pOctetString == NULL)
  822. {
  823. MemFree(*ppDest);
  824. *ppDest = NULL;
  825. return CS_NO_MEMORY;
  826. }
  827. memcpy((*ppDest)->sData.pOctetString, pSource->sData.pOctetString,
  828. pSource->sData.wOctetStringLength);
  829. }
  830. return CS_OK;
  831. }
  832. //====================================================================================
  833. //====================================================================================
  834. CS_STATUS
  835. Q931FreeNonStandardData(PCC_NONSTANDARDDATA pNonStandardData)
  836. {
  837. if (pNonStandardData == NULL)
  838. {
  839. return CS_OK;
  840. }
  841. if (pNonStandardData->sData.pOctetString != NULL)
  842. {
  843. MemFree(pNonStandardData->sData.pOctetString);
  844. }
  845. MemFree(pNonStandardData);
  846. return CS_OK;
  847. }
  848. #ifdef __cplusplus
  849. }
  850. #endif