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.

228 lines
6.2 KiB

  1. #ifndef __iptel_q931msg_h
  2. #define __iptel_q931msg_h
  3. // To use the Q931_MESSAGE class:
  4. //
  5. // To decode Q.931 PDUs:
  6. //
  7. // Create an instance of the Q931_MESSAGE class.
  8. // Call the AssignDecodePdu method, supplying the buffer and length of the PDU data.
  9. // If the AssignDecodePdu succeeds, then the buffer is now "bound" to the
  10. // Q931_MESSAGE instance. You may then examine the elements of Q931_MESSAGE:
  11. //
  12. // MessageType - The type of Q.931 PDU received (Setup, etc.)
  13. // CallReferenceValue
  14. // InfoElementArray - An ordered array of IEs that were in the PDU
  15. // UserInformation - If an ASN.1 UUIE was present, this field will be non-NULL
  16. //
  17. // You may also use the FindInfoElement method to locate a specific IE (cause code, etc.)
  18. //
  19. // When you are done using the contents of the Q931_MESSAGE instance, you must call the
  20. // FreeAll method. This destroys the association between the buffer and the Q931_MESSAGE class.
  21. // This step MUST be performed before destroying the instance of the Q931_MESSAGE class.
  22. //
  23. //
  24. // To encode Q.931 PDUs:
  25. //
  26. // Create an instance of the Q931_MESSAGE class.
  27. // Set the MessageType and CallReferenceValue fields.
  28. // For each IE that should be encoded, call AppendInfoElement.
  29. // (This includes the UUIE.)
  30. // Call EncodePdu. The buffer on return contains the fully encoded PDU.
  31. //
  32. // If the buffer supplied to EncodePdu is not long enough, then the ReturnLength
  33. // parameter will contain the required length, and the method will return
  34. // HRESULT_FROM_WIN32 (ERROR_MORE_DATA).
  35. //
  36. // When calling InsertInfoElement, you must insure that the buffer supplied in the
  37. // Q931_IE structure is still valid when the EncodePdu call is made. All IE buffers
  38. // should remain valid until the Q931_MESSAGE::FreeAll method is called.
  39. #include "q931defs.h"
  40. #include "dynarray.h"
  41. struct H323_UserInformation;
  42. struct Q931_ENCODE_CONTEXT;
  43. struct Q931_BEARER_CAPABILITY
  44. {
  45. };
  46. // Q931_IE_DATA contains the decoded contents of those information elements whose
  47. // interpretation is known and implemented in this module.
  48. // Not all IEs are supported.
  49. union Q931_IE_DATA
  50. {
  51. // Q931_IE_USER_TO_USER
  52. struct {
  53. Q931_UUIE_TYPE Type;
  54. H323_UserInformation * PduStructure;
  55. BOOL IsOwner; // if true, delete PduStructure on deletion
  56. } UserToUser;
  57. // Q931_IE_CAUSE
  58. DWORD CauseCode;
  59. // Q931_BEARER_CAPABILITY
  60. Q931_BEARER_CAPABILITY BearerCapability;
  61. // Q931_DISPLAY
  62. struct {
  63. LPSTR String;
  64. } Display;
  65. // IEs that are not implemented here, and are of variable length
  66. struct {
  67. LPBYTE Data;
  68. DWORD Length;
  69. } UnknownVariable;
  70. // IEs that are not implemented here, and are of fixed length
  71. struct {
  72. BYTE Value;
  73. } UnknownFixed;
  74. };
  75. struct Q931_IE
  76. {
  77. Q931_IE_IDENTIFIER Identifier;
  78. Q931_IE_DATA Data;
  79. };
  80. // it is the responsibility of the user of this object to synchronize access
  81. // and object lifetime.
  82. //
  83. // The Decode method builds the InfoElementArray. Elements in this array
  84. // may refer to the original buffer passed to Encode. Therefore, users of
  85. // Q931_MESSAGE::Decode must insure that the original buffer remains accessible
  86. // and does not change, until the user no longer requires the use of this Q931_MESSAGE
  87. // object, or calls Q931_MESSAGE::FreeAll.
  88. struct Q931_MESSAGE
  89. {
  90. public:
  91. Q931_MESSAGE_TYPE MessageType;
  92. WORD CallReferenceValue;
  93. DYNAMIC_ARRAY <Q931_IE> InfoElementArray;
  94. LPBYTE Buffer;
  95. DWORD BufferLength;
  96. BOOL BufferIsOwner;
  97. private:
  98. HRESULT DecodeInfoElement (
  99. IN OUT LPBYTE * Pos,
  100. IN LPBYTE End,
  101. OUT Q931_IE * ReturnInfoElement);
  102. void FreeInfoElementArray (void);
  103. // ParseInfoElement examines the contents of an IE that has already been decoded
  104. // (type and length determined), and for known IE types, decodes their contents
  105. // and assigns to data structures
  106. HRESULT ParseIE (
  107. IN Q931_IE * InfoElement);
  108. HRESULT ParseIE_UUIE (
  109. IN Q931_IE * InfoElement);
  110. HRESULT EncodeIE_UUIE (
  111. IN Q931_ENCODE_CONTEXT * Context,
  112. IN Q931_IE * InfoElement);
  113. // for those IEs that have attached allocated data, free it
  114. void FreeInfoElement (
  115. IN Q931_IE * InfoElement);
  116. HRESULT EncodeHeader (
  117. IN Q931_ENCODE_CONTEXT * Context);
  118. HRESULT EncodeInfoElement (
  119. IN Q931_ENCODE_CONTEXT * Context,
  120. IN Q931_IE * InfoElement);
  121. static INT __cdecl CompareInfoElement (const Q931_IE *, const Q931_IE *);
  122. static INT InfoElementSearchFunc (
  123. IN const Q931_IE_IDENTIFIER * SearchKey,
  124. IN const Q931_IE * Comparand);
  125. public:
  126. // initializes array and UserInformation
  127. Q931_MESSAGE (void);
  128. // will free the UserInformation field if present
  129. ~Q931_MESSAGE (void);
  130. HRESULT EncodePdu (
  131. IN OUT LPBYTE Data,
  132. IN OUT LPDWORD Length);
  133. HRESULT AttachDecodePdu (
  134. IN LPBYTE Data,
  135. IN DWORD Length,
  136. IN BOOL IsDataOwner); // if TRUE, Q931_MESSAGE will free on dtor
  137. void FreeAll (void);
  138. // if Q931_MESSAGE currently has a Buffer, and it owns the Buffer,
  139. // then it will free it here, using GkHeapFree
  140. void Detach (void);
  141. // if Q931_MESSAGE currently has a Buffer, regardless of whether it owns the buffer,
  142. // then it will be returned here
  143. // returns S_OK if a buffer was returned
  144. // returns S_FALSE if no buffer was returned, and ReturnBuffer set to null
  145. HRESULT Detach (
  146. OUT LPBYTE * ReturnBuffer,
  147. OUT DWORD * ReturnBufferLength);
  148. void SetUserInformation (
  149. IN H323_UserInformation *,
  150. IN BOOL FreeOnDelete);
  151. // information element manipulation
  152. HRESULT AppendInfoElement (
  153. IN Q931_IE * InfoElement);
  154. HRESULT DeleteInfoElement (
  155. IN Q931_IE_IDENTIFIER Identifier);
  156. HRESULT FindInfoElement (
  157. IN Q931_IE_IDENTIFIER Identifier,
  158. OUT Q931_IE ** ReturnInfoElement);
  159. void SortInfoElementArray (void);
  160. };
  161. DECLARE_SEARCH_FUNC_CAST(Q931_IE_IDENTIFIER, Q931_IE);
  162. #if DBG
  163. // in debug builds, this function will take a Q.931 PDU buffer,
  164. // decode it, re-encode it, verify that the contents match,
  165. // and attempt to decode the re-encoded PDU.
  166. // this is good for verifying the integrity of the Q931_MESSAGE class.
  167. void Q931TestDecoder (
  168. IN LPBYTE PduData,
  169. IN DWORD PduLength);
  170. #else
  171. #define Q931TestDecoder(x,y) 0
  172. #endif
  173. #endif // __iptel_q931msg_h