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.

258 lines
6.8 KiB

  1. /******************************************************************************
  2. *
  3. * File: h245send.c
  4. *
  5. * INTEL Corporation Proprietary Information
  6. * Copyright (c) 1994, 1995, 1996 Intel Corporation.
  7. *
  8. * This listing is supplied under the terms of a license agreement
  9. * with INTEL Corporation and may not be used, copied, nor disclosed
  10. * except in accordance with the terms of that agreement.
  11. *
  12. *****************************************************************************/
  13. /******************************************************************************
  14. *
  15. * $Workfile: h245asn.c $
  16. * $Revision: 1.4 $
  17. * $Modtime: 17 Jan 1997 14:31:20 $
  18. * $Log: S:\sturgeon\src\h245\src\vcs\h245asn.c_v $
  19. *
  20. * Rev 1.2 28 May 1996 14:25:22 EHOWARDX
  21. * Tel Aviv update.
  22. *
  23. * Rev 1.1 21 May 1996 13:39:28 EHOWARDX
  24. * Added LOGGING switch to log PDUs to the file H245.OUT.
  25. * Add /D "LOGGING" to project options to enable this feature.
  26. *
  27. * Rev 1.0 09 May 1996 21:06:20 EHOWARDX
  28. * Initial revision.
  29. *
  30. * Rev 1.5.1.2 09 May 1996 19:34:44 EHOWARDX
  31. * Redesigned locking logic.
  32. * Simplified link API.
  33. *
  34. * Rev 1.5.1.0 23 Apr 1996 14:42:44 EHOWARDX
  35. * Added check for ASN.1 initialized.
  36. *
  37. * Rev 1.5 13 Mar 1996 11:33:06 DABROWN1
  38. * Enable logging for ring0
  39. *
  40. * Rev 1.4 07 Mar 1996 23:20:14 dabrown1
  41. *
  42. * Modifications required for ring0/ring3 compatiblity
  43. *
  44. * Rev 1.3 06 Mar 1996 13:13:52 DABROWN1
  45. *
  46. * added #define _DLL for SPOX build
  47. *
  48. * Rev 1.2 23 Feb 1996 13:54:42 DABROWN1
  49. *
  50. * added tracing functions
  51. *
  52. * Rev 1.1 21 Feb 1996 16:52:08 DABROWN1
  53. *
  54. * Removed call to h245_asn1free, now uses generic MemFree
  55. *
  56. * Rev 1.0 09 Feb 1996 17:35:20 cjutzi
  57. * Initial revision.
  58. *
  59. *****************************************************************************/
  60. #ifndef STRICT
  61. #define STRICT
  62. #endif
  63. /***********************/
  64. /* SYSTEM INCLUDES */
  65. /***********************/
  66. #include <stdlib.h>
  67. #include <stddef.h>
  68. #include <limits.h>
  69. #include "precomp.h"
  70. /***********************/
  71. /* H245 INCLUDES */
  72. /***********************/
  73. #ifdef _IA_SPOX_
  74. # define _DLL
  75. #endif //_IA_SPOX_
  76. #include "h245asn1.h"
  77. #include "h245sys.x"
  78. #include "sendrcv.x"
  79. #include "h245com.h"
  80. /***********************/
  81. /* ASN1 INCLUDES */
  82. /***********************/
  83. /***********************/
  84. /* S/R GLOBALS */
  85. /***********************/
  86. #ifdef _IA_SPOX_
  87. # define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
  88. # define HWND void*
  89. # undef _DLL
  90. #endif //_IA_SPOX
  91. #define ASN1_FLAGS 0
  92. int initializeASN1(ASN1_CODER_INFO *pWorld)
  93. {
  94. int nResult;
  95. nResult = H245_InitWorld(pWorld);
  96. return (MAKELONG(nResult, 0));
  97. }
  98. int terminateASN1(ASN1_CODER_INFO *pWorld)
  99. {
  100. H245_TermWorld(pWorld);
  101. H245TRACE(0, 10, "Unloading ASN.1 libraries", 0);
  102. return 0;
  103. }
  104. // THE FOLLOWING IS ADDED FOR TELES ASN.1 INTEGRATION
  105. int H245_InitModule(void)
  106. {
  107. H245ASN_Module_Startup();
  108. return (H245ASN_Module != NULL) ? ASN1_SUCCESS : ASN1_ERR_MEMORY;
  109. }
  110. int H245_TermModule(void)
  111. {
  112. H245ASN_Module_Cleanup();
  113. return ASN1_SUCCESS;
  114. }
  115. int H245_InitWorld(ASN1_CODER_INFO *pWorld)
  116. {
  117. int rc;
  118. ZeroMemory(pWorld, sizeof(*pWorld));
  119. if (H245ASN_Module == NULL)
  120. {
  121. return ASN1_ERR_BADARGS;
  122. }
  123. rc = ASN1_CreateEncoder(
  124. H245ASN_Module, // ptr to mdule
  125. &(pWorld->pEncInfo), // ptr to encoder info
  126. NULL, // buffer ptr
  127. 0, // buffer size
  128. NULL); // parent ptr
  129. if (rc == ASN1_SUCCESS)
  130. {
  131. ASSERT(pWorld->pEncInfo != NULL);
  132. rc = ASN1_CreateDecoder(
  133. H245ASN_Module, // ptr to mdule
  134. &(pWorld->pDecInfo), // ptr to decoder info
  135. NULL, // buffer ptr
  136. 0, // buffer size
  137. NULL); // parent ptr
  138. ASSERT(pWorld->pDecInfo != NULL);
  139. }
  140. if (rc != ASN1_SUCCESS)
  141. {
  142. H245_TermWorld(pWorld);
  143. }
  144. return rc;
  145. }
  146. int H245_TermWorld(ASN1_CODER_INFO *pWorld)
  147. {
  148. if (H245ASN_Module == NULL)
  149. {
  150. return ASN1_ERR_BADARGS;
  151. }
  152. ASN1_CloseEncoder(pWorld->pEncInfo);
  153. ASN1_CloseDecoder(pWorld->pDecInfo);
  154. ZeroMemory(pWorld, sizeof(*pWorld));
  155. return ASN1_SUCCESS;
  156. }
  157. int H245_Encode(ASN1_CODER_INFO *pWorld, void *pStruct, int nPDU, ASN1_BUF *pBuf)
  158. {
  159. int rc;
  160. ASN1encoding_t pEncInfo = pWorld->pEncInfo;
  161. BOOL fBufferSupplied = (pBuf->value != NULL) && (pBuf->length != 0);
  162. DWORD dwFlags = fBufferSupplied ? ASN1ENCODE_SETBUFFER : ASN1ENCODE_ALLOCATEBUFFER;
  163. // clean up out parameters
  164. if (! fBufferSupplied)
  165. {
  166. pBuf->length = 0;
  167. pBuf->value = NULL;
  168. }
  169. rc = ASN1_Encode(
  170. pEncInfo, // ptr to encoder info
  171. pStruct, // pdu data structure
  172. nPDU, // pdu id
  173. dwFlags, // flags
  174. pBuf->value, // buffer
  175. pBuf->length); // buffer size if provided
  176. if (ASN1_SUCCEEDED(rc))
  177. {
  178. if (fBufferSupplied)
  179. {
  180. ASSERT(pBuf->value == pEncInfo->buf);
  181. ASSERT(pBuf->length >= pEncInfo->len);
  182. }
  183. else
  184. {
  185. pBuf->value = pEncInfo->buf; // buffer to encode into
  186. }
  187. pBuf->length = pEncInfo->len; // len of encoded data in buffer
  188. }
  189. else
  190. {
  191. ASSERT(FALSE);
  192. }
  193. return rc;
  194. }
  195. int H245_Decode(ASN1_CODER_INFO *pWorld, void **ppStruct, int nPDU, ASN1_BUF *pBuf)
  196. {
  197. ASN1decoding_t pDecInfo = pWorld->pDecInfo;
  198. BYTE *pEncoded = pBuf->value;
  199. ULONG cbEncodedSize = pBuf->length;
  200. int rc = ASN1_Decode(
  201. pDecInfo, // ptr to encoder info
  202. ppStruct, // pdu data structure
  203. nPDU, // pdu id
  204. ASN1DECODE_SETBUFFER, // flags
  205. pEncoded, // do not provide buffer
  206. cbEncodedSize); // buffer size if provided
  207. if (ASN1_SUCCEEDED(rc))
  208. {
  209. ASSERT(pDecInfo->pos > pDecInfo->buf);
  210. pBuf->length -= (ULONG)(pDecInfo->pos - pDecInfo->buf);
  211. pBuf->value = pDecInfo->pos;
  212. }
  213. else
  214. {
  215. ASSERT(FALSE);
  216. *ppStruct = NULL;
  217. }
  218. return rc;
  219. }
  220.