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.

291 lines
8.6 KiB

  1. /*
  2. * packet.h
  3. *
  4. * Copyright (c) 1993 - 1995 by DataBeam Corporation, Lexington, KY
  5. * 1997 by Microsoft Corporation, Redmond, WA
  6. *
  7. * Abstract:
  8. * This is the interface file for the Packet class. Instances of this
  9. * class represent Protocol Data Units (PDUs) as they flow through the
  10. * system. These instances manage the memory required to hold both
  11. * encoded and decoded versions of the PDU, and make sure that no PDU
  12. * is ever encoded or decoded more than once. The use of lock counts
  13. * allow multiple objects in the system to reference and use the same
  14. * packet object at the same time. This class inherits from the SimplePacket
  15. * class (a pure virtual class).
  16. *
  17. * A packet object can be created in 2 different ways. It can be created
  18. * with either decoded data or encoded data. During instantiation, the
  19. * new packet object will calculate how much memory it will need to
  20. * hold both the encoded and decoded data, and attempts to allocate that
  21. * memory. If it cannot, then it will report an error, and the newly
  22. * created object should be immediately destroyed. If the allocations are
  23. * successful, then the packet will report success, but WILL NOT yet put
  24. * any data into those allocated buffers.
  25. *
  26. * When a Lock message is sent to the object, it will put encoded
  27. * data into the pre-allocated encode buffer. If the packet was created
  28. * with decoded data, then this will entail an encode operation. However,
  29. * if the packet was created with encoded data, then it is smart enough
  30. * to just COPY the encoded data into the internal buffer, thus avoiding
  31. * the overhead associated with the encode operation.
  32. *
  33. * When a Lock message is sent to the object, it will put decoded
  34. * data into the pre-allocated decode buffer. If the packet was created
  35. * with encoded data, then this will entail a decode operation. However,
  36. * if the packet was created with decoded data, then it is smart enough
  37. * to just COPY the decoded data into the internal buffer, thus avoiding
  38. * the overhead associated with the decode operation.
  39. *
  40. * When Unlock messages are received, the lock count is decremented. When
  41. * the lock count is 0, the packet deletes itself (it commits
  42. * suicide). Note that for this reason, no other object should explicitly
  43. * delete a packet object.
  44. *
  45. * Caveats:
  46. * None.
  47. *
  48. * Authors:
  49. * James J. Johnstone IV
  50. * Christos Tsollis
  51. */
  52. #ifndef _PACKET_
  53. #define _PACKET_
  54. #include "pktcoder.h"
  55. /*
  56. * Definition of class Packet.
  57. */
  58. class Packet;
  59. typedef Packet * PPacket;
  60. class Packet : public SimplePacket
  61. {
  62. public:
  63. // outgoing packets
  64. Packet(PPacketCoder pPacketCoder,
  65. UINT nEncodingRules,
  66. LPVOID pInputPduStructure,
  67. int nPduType,
  68. BOOL fPacketDirectionUp,
  69. PPacketError pePktErr,
  70. BOOL fLockEncodedData = FALSE);
  71. // incoming packets
  72. Packet(PPacketCoder pPacketCoder,
  73. UINT nEncodingRules,
  74. LPBYTE pEncodedData,
  75. UINT cbEncodedDataSize,
  76. int nPduType,
  77. BOOL fPacketDirectionUp,
  78. PPacketError pePktErr);
  79. virtual ~Packet(void);
  80. virtual BOOL IsDataPacket (void);
  81. virtual PVoid GetDecodedData(void);
  82. UINT GetDecodedDataLength(void) { return Decoded_Data_Length; };
  83. virtual int GetPDUType(void);
  84. protected:
  85. PPacketCoder Packet_Coder;
  86. LPVOID m_Decoded_Data;
  87. UINT Decoded_Data_Length;
  88. int PDU_Type;
  89. };
  90. /*
  91. * Packet (
  92. * PPacketCoder packet_coder,
  93. * UINT encoding_rules,
  94. * PVoid pInputPduStructure,
  95. * PMemory pInputPduStructure_Memory,
  96. * int pdu_type,
  97. * DBBoolean packet_direction_up,
  98. * PPacketError return_value )
  99. *
  100. * Functional Description:
  101. * This version of the constructor is used to create a Packet object
  102. * for outgoing PDUs when the packet is to be created from a structure
  103. * containing the PDU data to be encoded.
  104. *
  105. * Formal Parameters:
  106. * packet_coder (i)
  107. * Pointer to the packet coder object. This pointer will be used by
  108. * the packet object to encode and decode PDU structures. This pointer
  109. * must not become stale during the life of the packet object.
  110. * encoding_rules (i)
  111. * This value identifies which set of encoding rules should be used
  112. * on the current packet. This is simply through to the packet coder
  113. * during all encode and decode operations.
  114. * pInputPduStructure (i)
  115. * Pointer to the input PDU structure.
  116. * pInputPduStructure_Memory
  117. * Pointer to a Memory struct for the buffer containing the pdu structure.
  118. * Exactly one of the args pInputPduStructure_Memory and pInputPduStructure
  119. * should be non-NULL;
  120. * pdu_type (i)
  121. * The type of PDU contained in the packet. This is passed through
  122. * to the packet coder specified above.
  123. * packet_direction_up (i)
  124. * The packet_direction_up flag indicates the initial orientation of
  125. * the packet. Valid values are:
  126. * TRUE - The packet's direction is up.
  127. * FALSE - The packet's direction is down.
  128. * return_value (o)
  129. * When the constructor returns control to the calling function, this
  130. * variable will be set to one of the return values listed below.
  131. *
  132. * Return Value:
  133. * PACKET_NO_ERROR
  134. * The Packet object was constructed correctly.
  135. * PACKET_MALLOC_FAILURE
  136. * The constructor was unable to allocate the memory required to work
  137. * properly. The Packet object should be deleted.
  138. *
  139. * Side Effects:
  140. * None.
  141. *
  142. * Caveats:
  143. * None.
  144. */
  145. /*
  146. * Packet (
  147. * PPacketCoder packet_coder,
  148. * UINT encoding_rules,
  149. * PUChar encoded_data_ptr,
  150. * UShort encoded_data_length,
  151. * int pdu_type,
  152. * DBBoolean packet_direction_up,
  153. * PPacketError return_value )
  154. *
  155. * Functional Description:
  156. * This version of the constructor is used to create a Packet object
  157. * for incomming PDUs when the packet is to be created from an encoded
  158. * data stream containing the PDU data to be decoded.
  159. *
  160. * Formal Parameters:
  161. * packet_coder (i)
  162. * Pointer to the packet coder object. This pointer will be used by
  163. * the packet object to encode and decode PDU structures. This pointer
  164. * must not become stale during the life of the packet object.
  165. * encoding_rules (i)
  166. * This value identifies which set of encoding rules should be used
  167. * on the current packet. This is simply through to the packet coder
  168. * during all encode and decode operations.
  169. * encoded_data_ptr (i)
  170. * Pointer to the input encoded PDU.
  171. * encoded_data_length (i)
  172. * The length in bytes of the input encoded PDU.
  173. * pdu_type (i)
  174. * The type of PDU contained in the packet. This is passed through
  175. * to the packet coder specified above.
  176. * packet_direction_up (i)
  177. * The packet_direction_up flag indicates the initial orientation of
  178. * the packet. Valid values are:
  179. * TRUE - The packet's direction is up.
  180. * FALSE - The packet's direction is down.
  181. * return_value (o)
  182. * When the constructor returns control to the calling function, this
  183. * variable will be set to one of the return values listed below.
  184. *
  185. * Return Value:
  186. * PACKET_NO_ERROR
  187. * The Packet object was constructed correctly.
  188. * PACKET_MALLOC_FAILURE
  189. * The constructor was unable to allocate the memory required to work
  190. * properly. The Packet object should be deleted.
  191. *
  192. * Side Effects:
  193. * None.
  194. *
  195. * Caveats:
  196. * None.
  197. */
  198. /*
  199. * ~Packet ()
  200. *
  201. * Functional Description:
  202. * Destructor for the Packet class. The destructor ensures that all
  203. * resources that have been allocated are freed.
  204. *
  205. * Formal Parameters:
  206. * None.
  207. *
  208. * Return Value:
  209. * None.
  210. *
  211. * Side Effects:
  212. * None.
  213. *
  214. * Caveats:
  215. * None.
  216. */
  217. /*
  218. * GetDecodedData ()
  219. *
  220. * Functional Description:
  221. * The GetDecodedData method returns a pointer to the decoded data
  222. * buffer.
  223. *
  224. * Formal Parameters:
  225. * None.
  226. *
  227. * Return Value:
  228. * A pointer to the decoded data. If an decoding error occurs, this
  229. * method will return NULL.
  230. *
  231. * Side Effects:
  232. * None.
  233. *
  234. * Caveats:
  235. * None.
  236. */
  237. /*
  238. * GetDecodedDataLength ()
  239. *
  240. * Functional Description:
  241. * This method returns the decoded data's length.
  242. *
  243. * Formal Parameters:
  244. * None.
  245. *
  246. * Return Value:
  247. * The number of bytes in the decoded data.
  248. *
  249. * Side Effects:
  250. * None.
  251. *
  252. * Caveats:
  253. * None.
  254. */
  255. /*
  256. * GetPDUType ()
  257. *
  258. * Functional Description:
  259. * This method returns the PDU type.
  260. *
  261. * Formal Parameters:
  262. * None.
  263. *
  264. * Return Value:
  265. * Either DOMAIN_MCS_PDU or CONNECT_MCS_PDU dependant upon the PDU type.
  266. *
  267. * Side Effects:
  268. * None.
  269. *
  270. * Caveats:
  271. * None.
  272. */
  273. #endif